How to fit a nonlinear function with parameter-dependent constraint?
2 views (last 30 days)
Show older comments
Hello,
I want to fit the nonlinear function
y(x)=a(1)*(C1/x)^a(2)
to experimental data. Here, a(1) and a(2) are the parameters to be optimized. C1 is a known constant.
In order to avoid singularity at x=0, I'd like to manipulate the fitting function and want to set
y(x=0)=a(1)*(a(2)+1)*(C1/C2)^a(2)
where C2 ist another known constant. Since y(x=0) depends on a(1) and a(2), I don't see any way to implement this.
Do you have any suggestions?
Thanks in advance!
0 Comments
Accepted Answer
Alan Weiss
on 18 Mar 2013
Edited: Alan Weiss
on 18 Mar 2013
Why not take a logarithm?
log y(x) = log(a(1)) + a(2)*log(C1/x)
Have log(a(1)) and a(2) be the variables to find, you now have a linear regression. Solve it using LinearModel.fit or just plain \ (mldivide).
In detail, your data points are:
Independent variable: measurements of log(C1/x)
Response variable: measurements of log(y)
Make a matrix XX with two columns, the independent variable in column 2, and ones in column 1. Make a matrix YY with the response variable.
Your model is XX*a = YY.
Least squares solution: ahat = XX \ YY.
Alan Weiss
MATLAB mathematical toolbox documentation
3 Comments
Alan Weiss
on 19 Mar 2013
Do you have data with x = 0? If so, is y = Inf there? If x = 0 and y is not = Inf, then your model is no good, and you need to come up with a better model. If you have data with x = 0 and y = Inf, then simply throw those points away, they add nothing to the fitting of the parameters.
If you have no data with x = 0, then don't worry about it.
Alan Weiss
MATLAB mathematical toolbox documentation
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!