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

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??

Best 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