Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


Torsten
Posts:
1,459
Registered:
11/8/10


Re: lsqcurvefit Problem
Posted:
Mar 26, 2013 3:41 AM


"Xiangtong He" <xiangton@buffalo.edu> wrote in message <kipr8e$nfq$1@newscl01ah.mathworks.com>... > Hello, > > This is my code, but finally it comes to an error information as follows; > > function myFit > %% create the first half of the data > xdata = [50 530 6.3e3 1.1e4 1.56e4 2.65e4 3.22e4 5.375e4 1.17e5 2.2e5 5.5e5]; > ydata = [1.6 1.56 1.48 1.44 1.39 1.31 1.28 1.15 0.95 0.84 0.68]/1.6; > > > %% call LSQNONLIN > p = lsqcurvefit(@mycurve,[2e7 6e6],[],[],xdata,ydata); > m = p(1) > n = p(2) > > %% plot the original data and fitted function in a figure > plot(xdata,ydata,'bo') > hold on > > fitted = (1./(2*xdata)+m*log2(xdata)).^(1(1exp((xdata/(p(2))).^0.3))/1.5).*(2*xdata).^(1(1exp((xdata/(p(2))).^0.3))/1.5); > semilogx(xdata,fitted,'r') > xlabel('x'); ylabel('y') > legend('Data', 'Fit') > > %% function that reports the error > function err = mycurve(parameter,real_x, real_y) > fit = exp(parameter(1).*(real_x + parameter(2))); > parameter(2); > err = fit  real_y; > > % weight the error according to the WEIGHT vector > %err_weighted = err.*weight; > %err = err_weighted; > end > > end > > ****ERROR INFORMATION: > > Warning: Imaginary parts of complex X and/or Y arguments ignored > > In myFit at 17 > Warning: Length of lower bounds is > length(x); ignoring extra bounds. > > In checkbounds at 27 > In lsqnsetup at 56 > In lsqcurvefit at 196 > In myFit at 8 > Warning: Length of upper bounds is > length(x); ignoring extra bounds. > > In checkbounds at 37 > In lsqnsetup at 56 > In lsqcurvefit at 196 > In myFit at 8 > Exiting due to infeasibility: 2 lower bounds exceed the corresponding upper bounds. > > Can you help me work it out? > > Thank you
Take a look at the documentation at http://www.mathworks.de/de/help/optim/ug/lsqcurvefit.html on how to call lsqcurvefit. The 5th and 6th argument are reserved for lower and upper bounds for the variables. In your call, the 5th and 6th argument are xdata and ydata. If you want to pass xdata and ydata to mycurve, call lsqcurvefit as p = lsqcurvefit(@(x,xdata)mycurve(x,xdata,ydata),[2e7; 6e6],xdata,ydata);
Best wishes Torsten.



