Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: lsqcurvefit Problem
Replies: 2   Last Post: Mar 26, 2013 7:54 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Torsten

Posts: 1,477
Registered: 11/8/10
Re: lsqcurvefit Problem
Posted: Mar 26, 2013 7:54 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Torsten" wrote in message <kirjeh$8p9$1@newscl01ah.mathworks.com>...
> "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,[2e-7 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-(1-exp(-(xdata/(-p(2))).^0.3))/1.5).*(2*xdata).^-(1-(1-exp(-(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),[2e-7; 6e6],xdata,ydata);
>
> Best wishes
> Torsten.


By the way:
When you use lsqcurvefit instead of lsqnonlin, you will only have to supply
the vector "fit" in "mycurve", _not_ "fit - real_y".

Best wishes
Torsten.




Date Subject Author
3/26/13
Read Re: lsqcurvefit Problem
Torsten
3/26/13
Read Re: lsqcurvefit Problem
Torsten

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.