Non-linear data fit with multiple constants
Mostrar comentarios más antiguos
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 comentarios
Torsten
el 14 de Mayo de 2026 a las 13:38
If b,c and d are known constants, why don't you simply specify them with their numerical values in the fittype function ?
Lawrence
hace alrededor de 7 horas
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
hace 36 minutos
Respuestas (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=p(:); y=q(:);
x=x(1:index); y=y(1:index);
P=c*x./(1+c*x);
Q=(b*d)*x./(1+d*x);
ft = fittype(@(a, b, c, d,x) a*c*x./(1+c*x) + b*d*x./(1+d*x),'problem',{'b','c','d'});
f=cfit(ft, P\(y(:)-Q)) ; %fit result
Categorías
Más información sobre Interpolation en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!