MATLAB: Fsolve interchangeable with nlinfit, but how

fsolveMATLABnlinfit

Okay, so I know how to use nlinfit, but supposedly fsolve is also interchangeable with nlinfit, and I was wondering what I would need to do to do that.
If I was given x data and y data and the model the function fits and needed to find parameters such as A, B, and C etc how would I go about solving for A, B, and C using fsolve instead of nlinfit?

Best Answer

It’s not exactly interchangable, however it’s possible to use it to estimate the parameters.
Example —
x = linspace(0, 10, 10);
y = exp(x.*0.2)+randn(size(x))/10
objfcn = @(b,x) b(1) + b(2).*exp(x.*b(3));
B = fsolve(@(b) norm(y - objfcn(b,x)), rand(3,1));
figure
plot(x, y, 'p')
hold on
plot(x, objfcn(B,x), '-r')
hold off
grid
text(1.5,6,sprintf('y = %.3f + %.3f\\cdote^{%.3f\\cdotx}',B))
producing (with this set of random values):
.
Experiment with this approach with your own data.