Fit data with dependent parameters
2 views (last 30 days)
Show older comments
Hi,
There are two rows of data, x and y. I would like to fit y = f(x), where
f(x) = a*x^3 + b*x^2 + (2a+3b)*x,
i.e. parameters are not independent.
I tried to use the function "fittype", but it does not work (Licensing error: -101,147).
I would like to know if there is any other way to solve it.
Thank you!
0 Comments
Accepted Answer
Star Strider
on 13 Jul 2018
Yours is a linear problem, however the easiest way to estimate the parameters is likely an unconstrained nonlinear solver, such as fminsearch:
x = ...;
y = ...;
objfcn = @(b,x) b(1).*x.^3 + b(2).*x.^2 + (2*b(1) + 3*b(2)).*x;
[B,resnorm] = fminsearch(@(b) norm(y - objfcn(b,x)), [1;1]);
xv = linspace(min(x), max(x));
figure
plot(x, y, 'pb')
hold on
plot(xv, objfcn(B,xv), '-r')
hold off
grid
6 Comments
See Also
Categories
Find more on Linear Least Squares 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!