custom equation fit in curveFitter is not working

16 Ansichten (letzte 30 Tage)
Fernanda Vargas
Fernanda Vargas am 30 Jan. 2023
Kommentiert: Fernanda Vargas am 30 Jan. 2023
I'm looking to do a "custom equation" fit using the curveFitter in matlab with this data:
pc2 =
0
0.0001
0.0011
0.0216
0.2847
0.8708
1.0000
lam_2 =
0
30
55
110
200
320
460
After opening curveFitter, I load lam_2 as my X and pc2 as my Y.
My custom equation is: 0.5*(1+erf(b*(x-a)))
One time I got a good fit by choosing a good initial value, MATLAB calculated a to be a = 240.4
Now I wanted to recreate this fit and I'm choosing 240.4 or even numbers around that value as my starting point for "a" and the fit doesnt work anymore.
  3 Kommentare
Fernanda Vargas
Fernanda Vargas am 30 Jan. 2023
I didnt give it an initial value
but i also didnt give it the first time and it found a good fit just by me choosing a good value for a
Torsten
Torsten am 30 Jan. 2023
I didn't know you can give an initial value to only one of the parameters to be fitted. And in my opinion - if MATLAB chooses the second one arbitrarily - it also doesn't make much sense. Better you plot the curve for your guessed parameters first before using the fitting tool.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Torsten
Torsten am 30 Jan. 2023
Bearbeitet: Torsten am 30 Jan. 2023
pc2 = [ 0
0.0001
0.0011
0.0216
0.2847
0.8708
1.0000];
lam_2 = [ 0
30
55
110
200
320
460];
hold on
plot(lam_2,pc2,'o')
fun = @(x,a,b)0.5*(1+erf(b*(x-a)));
a = 1000;
b = 1/2000;
sol = lsqcurvefit(@(x,xdata)fun(xdata,x(1),x(2)),[a b],lam_2,pc2)
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
sol = 1×2
240.3831 0.0101
x = linspace(min(lam_2),max(lam_2),100);
plot(x,fun(x,sol(1),sol(2)))
hold off
grid on

Weitere Antworten (0)

Kategorien

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

Community Treasure Hunt

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

Start Hunting!

Translated by