Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
curve fitting tool

Subject: curve fitting tool

From: Jessica

Date: 25 Feb, 2011 14:22:06

Message: 1 of 7

Hi,

Using the curve fitting tool, I know you can provide some "guesses" to help guide how the curves are fit. Is it possible to set up and lower bounds? For example, I know in my data that x must be greater than zero and y must be greater than zero.

Thanks!

Jessica

Subject: curve fitting tool

From: Charbel

Date: 25 Feb, 2011 15:05:16

Message: 2 of 7

"Jessica" wrote in message <ik8due$h4g$1@fred.mathworks.com>...
> Hi,
>
> Using the curve fitting tool, I know you can provide some "guesses" to help guide how the curves are fit. Is it possible to set up and lower bounds? For example, I know in my data that x must be greater than zero and y must be greater than zero.
>
> Thanks!
>
> Jessica

yes...

you just have to make to vectors:
lb=[]; % is the lower bounds vector
ub=[]; % is the upper bounds vector

they must be the same length of ur x0 ( which is the initial parameters vector) % ur curving tool start with this vector to find the ideal values of ur parameters

example:
u have 4 parameters:
x0=[2 3 10 25];
lb=[0 0 0 0];
ub=[5 5 20 50];

and when ur callin ur curve fittin function, don't forget to mention lb and un in ur inputs:
[................]=fminsearch(x0,Xdata,Ydata,lb,ub)

Best Regards
CSA

Subject: curve fitting tool

From: Charbel

Date: 25 Feb, 2011 15:13:09

Message: 3 of 7

More precisely:
[x,resnorm,residual,exitflag,output,lambda,jacobian] =K(fun,x0,xdata,ydata,lb,ub)
with K=fminsearch/fmincon/nonlin.... etc

> Best Regards
> CSA

Subject: curve fitting tool

From: John D'Errico

Date: 25 Feb, 2011 15:15:09

Message: 4 of 7

"Charbel" wrote in message <ik8gfc$f3j$1@fred.mathworks.com>...
> "Jessica" wrote in message <ik8due$h4g$1@fred.mathworks.com>...
> > Hi,
> >
> > Using the curve fitting tool, I know you can provide some "guesses" to help guide how the curves are fit. Is it possible to set up and lower bounds? For example, I know in my data that x must be greater than zero and y must be greater than zero.
> >
> > Thanks!
> >
> > Jessica
>
> yes...
>
> you just have to make to vectors:
> lb=[]; % is the lower bounds vector
> ub=[]; % is the upper bounds vector
>
> they must be the same length of ur x0 ( which is the initial parameters vector) % ur curving tool start with this vector to find the ideal values of ur parameters
>
> example:
> u have 4 parameters:
> x0=[2 3 10 25];
> lb=[0 0 0 0];
> ub=[5 5 20 50];
>
> and when ur callin ur curve fittin function, don't forget to mention lb and un in ur inputs:
> [................]=fminsearch(x0,Xdata,Ydata,lb,ub)
>
> Best Regards
> CSA

WRONG, WRONG, WRONG, WRONG, WRONG.

fminsearch does NOT accept bounds on the parameters!!!!!!

Read the help!

John

Subject: curve fitting tool

From: Charbel

Date: 25 Feb, 2011 15:30:22

Message: 5 of 7

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <ik8h1t$a6k$1@fred.mathworks.com>...
> "Charbel" wrote in message <ik8gfc$f3j$1@fred.mathworks.com>...
> > "Jessica" wrote in message <ik8due$h4g$1@fred.mathworks.com>...
> > > Hi,
> > >
> > > Using the curve fitting tool, I know you can provide some "guesses" to help guide how the curves are fit. Is it possible to set up and lower bounds? For example, I know in my data that x must be greater than zero and y must be greater than zero.
> > >
> > > Thanks!
> > >
> > > Jessica
> >
> > yes...
> >
> > you just have to make to vectors:
> > lb=[]; % is the lower bounds vector
> > ub=[]; % is the upper bounds vector
> >

Yes John U're right, i didn't look which curve fit functions she's using that's y i named a bunch of functions...
but in the case she needs to use constraints then my method is correct and she needs to use lsqcurvefit!

Best Regards,
CSA
> > they must be the same length of ur x0 ( which is the initial parameters vector) % ur curving tool start with this vector to find the ideal values of ur parameters
> >
> > example:
> > u have 4 parameters:
> > x0=[2 3 10 25];
> > lb=[0 0 0 0];
> > ub=[5 5 20 50];
> >
> > and when ur callin ur curve fittin function, don't forget to mention lb and un in ur inputs:
> > [................]=fminsearch(x0,Xdata,Ydata,lb,ub)
> >
> > Best Regards
> > CSA
>
> WRONG, WRONG, WRONG, WRONG, WRONG.
>
> fminsearch does NOT accept bounds on the parameters!!!!!!
>
> Read the help!
>
> John

Subject: curve fitting tool

From: Tom Lane

Date: 28 Feb, 2011 17:58:57

Message: 6 of 7

> Using the curve fitting tool, I know you can provide some "guesses" to
> help guide how the curves are fit. Is it possible to set up and lower
> bounds? For example, I know in my data that x must be greater than zero
> and y must be greater than zero.

Jessica, you got some other replies related to setting up bounds on the
parameters. Perhaps that's what you want.

It sounds to me though like you are talking about bounds on the data. In
cftool the x values are taken as given, and y is fit as a function of x. So
you just don't predict at negative x values if that doesn't make sense.

Depending on the form of the function you are fitting, you might be able to
constrain parameters so that the fitted curve takes only positive y values.
The other posters' advice might help. I can't think of a good simple general
way to, say, fit a second-order polynomial f(x) with the constraint that
f(x)>0 when x>0. If that's what you need, maybe someone else has a good
idea.

Sometimes people enforce constrains by transforming. For example, if you
model log(y) = f(x) then you get y back by exponentiation, so you are
guaranteed to get a positive value. This might work when you think a model
on the log scale is reasonable.

-- Tom

Subject: curve fitting tool

From: Jessica

Date: 1 Mar, 2011 20:52:05

Message: 7 of 7

"Tom Lane" <tlane@mathworks.nospam.com> wrote in message <ikgnor$7ks$1@fred.mathworks.com>...
> > Using the curve fitting tool, I know you can provide some "guesses" to
> > help guide how the curves are fit. Is it possible to set up and lower
> > bounds? For example, I know in my data that x must be greater than zero
> > and y must be greater than zero.
>
> Jessica, you got some other replies related to setting up bounds on the
> parameters. Perhaps that's what you want.
>
> It sounds to me though like you are talking about bounds on the data. In
> cftool the x values are taken as given, and y is fit as a function of x. So
> you just don't predict at negative x values if that doesn't make sense.
>
> Depending on the form of the function you are fitting, you might be able to
> constrain parameters so that the fitted curve takes only positive y values.
> The other posters' advice might help. I can't think of a good simple general
> way to, say, fit a second-order polynomial f(x) with the constraint that
> f(x)>0 when x>0. If that's what you need, maybe someone else has a good
> idea.
>
> Sometimes people enforce constrains by transforming. For example, if you
> model log(y) = f(x) then you get y back by exponentiation, so you are
> guaranteed to get a positive value. This might work when you think a model
> on the log scale is reasonable.
>
> -- Tom

Thanks for all these suggestions-- they were a big help!

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us