custom equation fit in curveFitter is not working

16 次查看(过去 30 天)
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 个评论
Fernanda Vargas
Fernanda Vargas 2023-1-30
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 2023-1-30
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.

请先登录,再进行评论。

采纳的回答

Torsten
Torsten 2023-1-30
编辑:Torsten 2023-1-30
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by