How do you go about guessing for fitting parameter initializations?

The code is meant to fit this data to the equation σy = σ0 + k*d^(−1/2). So sigma_0 and k are the unknown parameters. This is all based on a fitting practice problem I found online related to yield stress of metals. How am I supposed to go about guessing the parameter initializations for p0. I found on previous examples I was just getting lucky.
Data:
Data = [0.006 334
0.011 276
0.017 249
0.025 235
0.039 216
0.060 216
0.081 194
0.105 182];
%Data = load('stress.txt');
d = Data(:,1);
sigma = Data(:,2);
figure
plot(d,sigma, 'go')
hold on
fun = @(p, d) p(1) + p(2).*d.^(-1/2);
p0 = [1 1];
params = lsqcurvefit(fun,p0,d,sigma);
Local minimum found. Optimization completed because the size of the gradient is less than the value of the optimality tolerance.
stress_fit = fun(params,d);
plot(d,stress_fit, 'b');
hold off

 Akzeptierte Antwort

Torsten
Torsten am 22 Jun. 2023
Bearbeitet: Torsten am 22 Jun. 2023
This is a linear fitting problem for which you don't need initial guesses for the parameters:
Data = [0.006 334
0.011 276
0.017 249
0.025 235
0.039 216
0.060 216
0.081 194
0.105 182];
d = Data(:,1);
sigma = Data(:,2);
figure
plot(d,sigma, 'go')
hold on
params = [ones(size(Data,1),1), d.^(-1/2)]\sigma;
plot(d,params(1) + params(2).*d.^(-1/2),'b')
hold off
grid on

4 Kommentare

Ok thank you. Could you theoretically use lsqcurvefit anyways. A bit confused because the equation is not linear.
Torsten
Torsten am 22 Jun. 2023
Bearbeitet: Torsten am 22 Jun. 2023
The equation is linear in p(1) and p(2). It's not linear in d, but this is not important here.
You can use nonlinear solvers also for linear problems, but why if there are easier numerical methods ?
Theoretically, "lsqcurvefit" should solve the problem in one iteration independent of p0.
Ok I understand. Taking on a different scenario, if you have some linear parameters, and some nonlinear parameters, is it best to use lsqcurvefit?
For example an equation like this: v(t) = a1 + a2*e (−3t/T) ; parameters being a1, a2, T
If you have a problem with some linear parameters and some nonlinear aprameters, then you have no choice but to use a tool that can handle nonlinear problems. Lsqcurvefit is not the only possible tool of couse. There are many of them to be found, so lsqnonlin, nlinfit, fit, etc. Or you can use any general nonlinear optimizer. Or you can use the fminspleas tool I posted on the file exchange.
lsqcurvefit is not always the best choice.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

John D'Errico
John D'Errico am 22 Jun. 2023

0 Stimmen

There is no magic way to guess parameter estimates for any nonlinear problem. Sorry, but true. And of course, if there was, then the fitting codes would use it. Oh well.
It helps if you understand what the parameters tell you about the shape of the curve. This helps by a MASSIVE amount, since then you can provide intelligent choices.
Lacking comprehension about the parameters, then you essentially are forced to rely on magic. And magic is never a good thing to rely on, unless your name is Harry, and you have your own magic wand.
In the example case you have posed, the model is LINEAR in the parameters. As such, you can use basic fitting tools that do not need starting values. This is a nice thing, but it relies on you understanding what makes a model linear in the parameters.
SOMETIMES, you can use a transformation of the problem. That is, in some problems, by taking the log of the model, the parameters will now enter linearly. Then you can use a solver able to handle such a fit. Again, no starting values will be needed, HOWEVER, the transformation will also do strange things to the noise structure in the probem.
IN desperate times, you can use tools like GA to try to minimze the errors. Since GA is a tool that tries to do a quasi-global search, it does not need starting values. But GA (and other solvers like it) comes with its own issues that you really need to understand to use it optimally.
I'm sorry. There is no magic solution that always works. Well, not unless you have a magic wand. Mine broke the other day, and the lead times on parts are quite lengthy. Lacking that, you need to understand the tools you are using, how the solvers work, and the differences between them. A good understanding of what those parameters do to your model is also important.

Kategorien

Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 22 Jun. 2023

Kommentiert:

am 22 Jun. 2023

Community Treasure Hunt

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

Start Hunting!

Translated by