fminsearch gives weird zick zack solution

2 ビュー (過去 30 日間)
sbr
sbr 2023 年 6 月 10 日
編集済み: Torsten 2023 年 6 月 11 日
So, I wanna implement a parameter fit to fit meassurement data to an equation (specifically, I wanna fit data to the "improved generalised steinmetz equation", which you can see here. The average over time period T from eq 1.11 is ignored, since I want the current value).
For a reason I don't understand, the solution fminsearch (and also lsqcurvefit) delivers is just completely off and goes zick-zack through my meassured data. Can someone of you maybe spot the flaw? In my mind it has to be somewhere in the implementation of the 2 equations, which are linked above too, since lsqcurvefit and fminsearch both deliver the same bs.
EDIT: Here is a screenshot of the plot:
Here is my code: At the beginning, I import data (B, P) from a file (which is not included below):
B_pp = max(B) - min(B); % peak-to-peak flux density
T = 1./f;
dt = T ./ 1000;
t = 0:dt:T;
k1 = @(x) x(1)./( (2*pi).^(x(2)-1) .* ...
integral(@(theta) abs(cos(theta)).^x(2) .* 2.^(x(3)-x(2)), 0, 2*pi) );
pv = @(x) k1(x) .* abs(gradient(B, t(2)-t(1))).^x(2) .* B_pp.^(x(3)-x(2));
x = fminsearch(@(x) vecnorm(pv(x) - P), [1,1,1]);
%[x, resnorm, residual] = lsqcurvefit(pv, [0,0,0], B, P, [-Inf, -Inf, -Inf],[Inf, Inf, Inf],opts);
figure; grid on;
plot(B, P, 'bo', B, pv(x), 'r-');
xlabel('Magnetic field B [T]'); ylabel('Power loss p [W/m^3]');
legend('Experimental data', 'Fitted function'); title('Experimental vs. fitted');
  9 件のコメント
sbr
sbr 2023 年 6 月 11 日
Sure. It is more or less exactly the fitted function without a weight (same zick-zack, different amplitudes).
Torsten
Torsten 2023 年 6 月 11 日
編集済み: Torsten 2023 年 6 月 11 日
And by multiplication by a constant and an exponentiation you expect a smooth curve like the blue one ? No chance. I think you have to reconsider if delta B in your integral really means max(B) - min(B). I doubt it. If it wouldn't depend on t as your setting implies , it could have been taken out of the integral.

サインインしてコメントする。

回答 (1 件)

Matt J
Matt J 2023 年 6 月 10 日
編集済み: Matt J 2023 年 6 月 10 日
It seems unlikely to me that x0=[1,1,1] would be an accurate initial guess. Surely, you chose that arbitrarily. Since you only have 3 unknown parameters, it shouldn't be too computationally expensive to do a discrete grid search for a better initial point.
  2 件のコメント
sbr
sbr 2023 年 6 月 11 日
Normal values for or in this case x(1), x(2), x(3) are [10, 1.5, 3], but setting the initial guess to that doesn't improve the result sadly.
Matt J
Matt J 2023 年 6 月 11 日
Then your model (as coded currently) may be inconsistent with your data. But that is an additional reason a grid search could help you. If you get poor agreement even after a grid search, you know you have bug in your model function code.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by