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: custom

Subject: curve fitting: custom

From: Jessica

Date: 25 Feb, 2011 20:11:20

Message: 1 of 4

I am trying to make a custom equation to fit a curve. I would like the equation to be:

a*exp(-b*x)+c*exp(-d*x)+e*exp(-f*x)

But I get the error:


Fit could not be computed due to error:

Inf computed by model function.


I get this same error even if I only put in: a*exp(-b*x)

Am I doing something wrong?

Thanks!

Subject: curve fitting: custom

From: Steven_Lord

Date: 25 Feb, 2011 20:39:07

Message: 2 of 4



"Jessica" <jyorzinski@ucdavis.edu> wrote in message
news:ik92d8$jct$1@fred.mathworks.com...
> I am trying to make a custom equation to fit a curve. I would like the
> equation to be:
>
> a*exp(-b*x)+c*exp(-d*x)+e*exp(-f*x)
>
> But I get the error:
>
>
> Fit could not be computed due to error:
>
> Inf computed by model function.
>
>
> I get this same error even if I only put in: a*exp(-b*x)
>
> Am I doing something wrong?

Remember when computing exp(q) that if q is greater than about:

log(realmax)

then exp(q) will overflow to Inf. So have you set bounds on b and/or scaled
your x data such that -b*x is no greater than about 709?

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: curve fitting: custom

From: Jessica

Date: 25 Feb, 2011 20:57:06

Message: 3 of 4

"Steven_Lord" <slord@mathworks.com> wrote in message <ik9418$mks$1@fred.mathworks.com>...
>
>
> "Jessica" <jyorzinski@ucdavis.edu> wrote in message
> news:ik92d8$jct$1@fred.mathworks.com...
> > I am trying to make a custom equation to fit a curve. I would like the
> > equation to be:
> >
> > a*exp(-b*x)+c*exp(-d*x)+e*exp(-f*x)
> >
> > But I get the error:
> >
> >
> > Fit could not be computed due to error:
> >
> > Inf computed by model function.
> >
> >
> > I get this same error even if I only put in: a*exp(-b*x)
> >
> > Am I doing something wrong?
>
> Remember when computing exp(q) that if q is greater than about:
>
> log(realmax)
>
> then exp(q) will overflow to Inf. So have you set bounds on b and/or scaled
> your x data such that -b*x is no greater than about 709?
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com




My data look like:


x2=[1 50 200 500 800 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 14000 16000];
y2=[-67.192431503785585 -43.728937550421549 0 26.763054442509919 30.580325239212350 31.313687388344004 37.325816541275245 39.905287727730567 37.766775948976964 33.290940478772150 28.072810933830446 22.968921142266289 18.386543637280138 14.476446776414663 11.250690904796071 3.757746258933735 2.095333107797992];

When I use the exponential that is provided (a*exp(-b*x)+c*exp(-d*x)), the fit is not quite right. That is why I want to try the next order up: a*exp(-b*x)+c*exp(-d*x)+e*exp(-f*x).

I tried setting some bounds but don't really know how to do this. I run this data with the provided a*exp(-b*x)+c*exp(-d*x), then I can get approximate coefficients. But when I enter in these values are starting points for a custom fit to a*exp(-b*x)+c*exp(-d*x)+e*exp(-f*x), it does not work.

I tried setting the bounds for b differently and this did not help.

Thanks!

Subject: curve fitting: custom

From: Steven_Lord

Date: 26 Feb, 2011 00:42:00

Message: 4 of 4


"Jessica" <jyorzinski@ucdavis.edu> wrote in message
news:ik9532$298$1@fred.mathworks.com...
> "Steven_Lord" <slord@mathworks.com> wrote in message
> <ik9418$mks$1@fred.mathworks.com>...

*snip*

> x2=[1 50 200 500 800 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000
> 14000 16000];

So for one of these points you're computing exp(-16000*b); if b is smaller
than -0.044 then this will overflow, and if it's larger than 0.044 it'll
underflow to 0.

> y2=[-67.192431503785585 -43.728937550421549 0 26.763054442509919
> 30.580325239212350 31.313687388344004 37.325816541275245
> 39.905287727730567 37.766775948976964 33.290940478772150
> 28.072810933830446 22.968921142266289 18.386543637280138
> 14.476446776414663 11.250690904796071 3.757746258933735
> 2.095333107797992];
>
> When I use the exponential that is provided (a*exp(-b*x)+c*exp(-d*x)), the
> fit is not quite right. That is why I want to try the next order up:
> a*exp(-b*x)+c*exp(-d*x)+e*exp(-f*x).

Are you sure that this form is appropriate for your data?

> I tried setting some bounds but don't really know how to do this. I run
> this data with the provided a*exp(-b*x)+c*exp(-d*x), then I can get
> approximate coefficients. But when I enter in these values are starting
> points for a custom fit to a*exp(-b*x)+c*exp(-d*x)+e*exp(-f*x), it does
> not work.
>
> I tried setting the bounds for b differently and this did not help.

Rescale your data instead, and make sure that you're using that form of
equation because it's appropriate for your data, not just because "it
fits" -- for the latter you could just use a spline!

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

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