简体   繁体   中英

Curve fitting with 5 parameters in Matlab

I am working on a curve fitting problem with the input function of the form

n=((xi-xa)-a*cos(theta))^2+(h-a*sin(theta))^2;
d=((xi-xa)+a*cos(theta))^2+(h+a*sin(theta))^2;
v=k*log(n/d) : Input function

Here xa,a,theta,h and k are parameters and we are required to compute v(xi)

The plot looks like this 在此处输入图片说明

Here blue dots represent observed value and red line is the theoretical curve obtained from the input function.

This fitting process was done by manually varying the parameters and matching the curves using hit and trial. Could this be accomplished using any optimization technique in Matlab. if so how ?

You can try to use lsqcurvefit ( http://nl.mathworks.com/help/optim/ug/lsqcurvefit.html ), eg

function F = myfun(x,xdata)
   %your parameters xa,a,theta,h,k
   %map to parameter vector x(1),x(2),x(3),x(4),x(5)

   n = ((xdata-x(1))-x(2)*cos(x(3)))^2+(x(4)-x(2)*sin(x(3)))^2;
   d = ((xdata-x(1))+acos(x(3)))^2+(x(4)+asin(x(3)))^2;
   F =  x(5)*log(n/d);
end

and a call to solver

x0 = [1;1;1;1;1]; % your guess for starting values of the x vector of parameters
x = lsqcurvefit(@myfun,x0,xdata,ydata);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM