您可以执行以下代码。该向量fitParams
将具有 a、b、e 和 x 的值。
function [fitParams, fval] = callMinEx()
Bm = 1:100;
% fake data. Use your actual data for pfei
x0 = [2,3,4,5];
pfei = coreLoss(Bm, x0) + 5e10*rand(1,length(Bm));
% call fminsearch with some initial parameters
startParams = [3,3,3,3];
[fitParams,fval] = fminsearch(@func2Minimize, startParams);
% plot data and fit
plot(Bm,pfei,'r*');
hold on
plot(Bm, coreLoss(Bm, x0));
legend('data','fit')
% The equation to be minimized by fminsearch
function epsValue = func2Minimize(params)
pfeStar = coreLoss(Bm,params);
epsValue = sum(((pfei - pfeStar) ./ pfei).^ 2);
end
% core loss function
function pfei = coreLoss(Bm, x0)
a = x0(1);
b = x0(2);
e = x0(3);
x = x0(4);
f = 100;
pfei = a * f * Bm .^ x + b * (f * Bm).^2 + e * (f * Bm).^1.5;
end
end