Non-linear data fit with multiple constants
Show older comments
I have a non-linear equation with 3 variables I wish to be constants and only 1 variable to be fitted to x,y data.
Using fittype, I have entered the equation and tried to specify b, c & d as constants. However, the options 'problem' only seems to allow single variables to be specified as constants
ft = fittype(@(a, b, c, d,x) a*c*x./(1+c*x) + b*d*x./(1+d*x),'problem','b,c,d');
Error using fittype>iAssertValidVariableNames
The name '[b,c,d]' is not a valid MATLAB variable name.
In the next part I use "fit" to fit the data, and specify the value of the 3 constants and starting point of the fit:
f = fit(p(1:index),q(1:index),ft,'problem',[Qm2 b1 b2],'StartPoint',Qm1);
Is there another way to specify constants in the fittype?
4 Comments
Torsten
1 minute ago
If b,c and d are known constants, why don't you simply specify them with their numerical values in the fittype function ?
Lawrence
about 5 hours ago
Or like this:
xfit = (0:0.1:1).';
yfit = 3*xfit + 0.01*(2*rand(11,1)-1);
b = 4;
fun = @(a,b,x) a/b*x;
ft = fittype( @(a,x) fun(a,b,x));
f = fit(xfit,yfit,ft)
Lawrence
about 3 hours ago
Answers (1)
Though your post's title says the fitting problem is nonlinear, it is actually linear when b and d are known, and so has a simple analytical solution. When c is also known the solution is even simpler:
x=x(:);
p=c*x./(1+c*x);
q=(b*d)*x./(1+d*x);
a=p\(y(:)-q); %fit result
Categories
Find more on Interpolation 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!