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 CenterFile Exchange에서 Get 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