How to get the coefficient of the function using non-linear regression analysis?

I coded like the picture to get the coefficient of the function with data by using non-linear regression analysis. but I don't know why the errors continue. What is the problem with that??

 Accepted Answer

Needs to be more like this:
xm = 0:0.5:5;
ym = [0 0.223904 0.323333 0.372308 0.359143 0.332033 0.278462 0.243394 ...
0.232222 0.198334 0.172414];
a0 = [1 1 1 1 1];
a = fminsearch(@(a)fssr(a,xm,ym), a0);
disp(a)
x = linspace(0,5,100);
y = a(1)*x./(a(2) + a(3)*x + a(4)*x.^2 + a(5)*x.^3);
plot(xm,ym,'o',x,y),grid
xlabel('x'),ylabel('y')
legend('data','curvefit')
function f = fssr(a, xm, ym)
yp = a(1)*xm./(a(2) + a(3)*xm + a(4)*xm.^2 + a(5)*xm.^3);
f = norm(ym-yp);
end

9 Comments

What shoul I do just to get the coefficient without plotting?
Just delete the plotting from the above if you don't want it. The
disp(a)
command displays the values of a in the command window.
I'm so sorry to keep asking, but how to get the maximum value of that function?
What's the error? When I do it I get 0.3673 for the max value.
I solved it. I get that one too. Thank you sooo much !!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!