How to fit my data to interpolated functions
1 view (last 30 days)
Show older comments
Hi all,
I need to do a complex fit of a power-law plus a few Gaussians (and no problem until here) but I have to add a different function coming from an array of x-y points downloaded from people who made numerical simulations. These five functions are given by the following five x-y couples x1,y1 etc...
This is how my model look like, but I get errors as it seems it can't read the variables x1,y1,x2,y2 etc
It says "??? Unrecognized function or variable 'x1' "
Anyone please know how I can do this?
Thanks in advance
mod=fittype(['F0*x^alpha' ... %powerlaw
'+A1b*exp(-((x-c1b)^2)/(2*s1b^2))' ... %gauss1b
'+A1n*exp(-((x-c1n)^2)/(2*s1n^2))' ... %gauss1n
'+A2n*exp(-((x-c2n)^2)/(2*s2n^2))' ... %gauss2n
'+A2o*exp(-((x-c2o)^2)/(2*s2o^2))' ... %gauss2out
'+A3n*exp(-((x-c3n)^2)/(2*s3n^2))' ... %gauss3n
'+A3o*exp(-((x-(c3n-(c2n-c2o)))^2)/(2*s3o^2))'... %gauss3out
'+k1*interp1(x1,y1,x)' ... %interpolated func 1
'+k2*interp1(x2,y2,x)' ... %interpolated func 2
'+k3*interp1(x3,y3,x)' ... %interpolated func 3
'+k4*interp1(x4,y4,x)' ... %interpolated func 4
'+k5*interp1(x5,y5,x)' ... %interpolated func 5
],...
'independent','x', ...
'coefficients',{'F0','alpha', ...
'A1b','c1b','s1b',...
'A1n','c1n','s1n',...
'A2n','c2n','s2n',...
'A2o','c2o','s2o',...
'A3n','c3n','s3n',...
'A3o','s3o',...
'k1','k2','k3','k4','k5',...
});
0 Comments
Answers (1)
Steven Lord
on 8 Oct 2024
Rather than defining your function as a large piece of text, I would define it as a function as per the "Fit a Curve Defined by a File" example on the fittype documentation page. I'd also either define your x1, x2, etc. variables inside that function or (if you want to be able to change them without having to modify the code) define them as problem parameters and specify their values in your call to the fit function.
See Also
Categories
Find more on Linear and Nonlinear Regression 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!