custom equation fit in curveFitter is not working
15 views (last 30 days)
Show older comments
Fernanda Vargas
on 30 Jan 2023
Commented: Fernanda Vargas
on 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 Comments
Torsten
on 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.
Accepted Answer
Torsten
on 30 Jan 2023
Edited: Torsten
on 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)
x = linspace(min(lam_2),max(lam_2),100);
plot(x,fun(x,sol(1),sol(2)))
hold off
grid on
More Answers (0)
See Also
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!