fminsearch gives weird zick zack solution

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 Comments

Could you include your fitting function in a mathematical notation ?
Those 2 equations are implemented, but without the in eq. 1.11:
And you think you can just take the value of the integrand
pv = @(x) k1(x) .* abs(gradient(B, t(2)-t(1))).^x(2) .* B_pp.^(x(3)-x(2));
instead of the time-averaged integrand as done in (1.11) ?
Honestly, I am pretty sure this should work. The code above is from the "improved generalised steinmetz equation"-model, as the name says it is an improvement to the "generalised steinmetz equation", which has the following equations:
I implemented 1.8 and 1.9 and the fitting algorithm works perfectly fine. The main difference to the problematic equations is, that in eq. (1.11) the peak-to-peak value is used, instead of the absolute value in eq. (1.8). (1.10) is again the mean value, like in (1.11).
My guess is that you are overfitting with the model you use.
k1(x)*B_pp^(x(3)-x(2)) is (almost) independ of your measurement data. Thus you can use only one constant to reflect this expression.
A second constant (in your code: x(2)) can be used for the exponent in the expression abs(gradient(B, t(2)-t(1))).^x(2).
But you use three free constants instead of two in your model.
I suggest you make a test with a model of the form
pv = @(x) x(1) * abs(gradient(B, t(2)-t(1))).^x(2)
and see if it works better.
Funny enough, it gives exactly the same curve:
Could you plot abs(gradient(B,t(2)-t(1))) over t ?
Sure. It is more or less exactly the fitted function without a weight (same zick-zack, different amplitudes).
Torsten
Torsten on 11 Jun 2023
Edited: Torsten on 11 Jun 2023
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.

Sign in to comment.

Answers (1)

Matt J
Matt J on 10 Jun 2023
Edited: Matt J on 10 Jun 2023
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 Comments

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.
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.

Sign in to comment.

Categories

Find more on Curve Fitting Toolbox in Help Center and File Exchange

Products

Release

R2019a

Asked:

sbr
on 10 Jun 2023

Edited:

on 11 Jun 2023

Community Treasure Hunt

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

Start Hunting!