How can I use levenberg-marquardt algorithm with two variables
5 views (last 30 days)
Show older comments
Taeksang Yoon
on 29 Mar 2021
Commented: Star Strider
on 31 Mar 2021
Hello, everyone.
I started to use lsqcurvefit function in matlab for estimating the parameters in reaction kinetics.
My reaction kinetics are like this => r = k1[a][b] / (1+k2[a]+k3[b])^2
When I tried to use lsqcurvefit function, it demands only one variable x, however in my kinetics there are two variables a and b for output(reaction rate r).
Is there any way that can estimate reaction constant parameters k1,k2,k3 with two reaction variables a and b in kinetics?
I searched in matlab to solve this problem, but I couldn't find it.
I hope I could get good reply at here.
Thanks!
4 Comments
J. Alex Lee
on 29 Mar 2021
As @Star Strider's answer shows, I guess no, it is not important for you to know what the "residual function" is, because lsqcurvefit will automagically define it for you based on the model function that you give it. But it is definitely necessary for estimation since it is what defines "how far is your model from your data at this current set of estimates".
As for estimation and validation samples, I don't know if that's a typical thing for these types of goals, but if you're not going to use all available data I suppose I'd throw another caution out there to make sure you sample well...depending on how noisy your data is, 8 data points for 3 parameters doesn't seem like a lot, but i guess also depends on how "rigid" the model is...
Accepted Answer
Star Strider
on 29 Mar 2021
It will be necessary to parameterize the ‘k’ constants (that you want to estimate) as:
k1 = p(1)
k2 = p(2)
k3 = p(3)
If the independent variable data are ‘a’ and ‘b’ and the dependent variable is ‘r’, then the data will be:
x = [a(:) b(:)];
y = r(:);
the objective function will be:
kinfcn = @(b,x) p(1).*x(:,1}.*x(:,2) ./ (1 + p(2).*x(:,1) + p(3).*x(:,2)).^2;
and the lsqcurvefit call would then be:
B = lsqcurvefit(kinfcn, rand(3,1), x, y, zeros(1,3))
The ‘zeros(1,3)’ prevents the kinetic constants (the ‘k’ parameters from being negative, since if I remember correctly, they should always be greater than 0.
5 Comments
Star Strider
on 31 Mar 2021
As always, my pleasure!
I do not have the Curve Fitting Toolbox, since I can do everything I need to do with the Statistics and Machine Learning Toolbox and the Optimization Toolbox and Global Optimization Toolbox.
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!