Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have the equation

 y = a + b Exp[-x/c] 
 data = {{462.36, 8872}, {408.18, 8780}, {374.4, 8915}, {322.8, 8937},
        {274.00, 8919}, {243.03, 911‌4}, {209.32, 9277}, {178.91, 9394},
        {140.71, 9508}, {113.08, 9592}}; 

 nlm = FindFit[data, y = a + b Exp[-x/c], {{a, 100}, {b, 100}, {c, 10}}, x] 

     PlotStyle -> {Darker@Green, PointSize[0.03]}],
   Plot[y/. nlm, {x, 1, 600}]] 

The above is how I currently have everything working and graphing.


I have actually got almost everything working I have theline bieing drwan the only issue I am having is that the first 2 points of data and the beginning of the line being drawn actuall start before the y axis on the graph so if you look at the graph it is skewed to the left. I am trying to understand what value I will need to change to move this back to the right and I am struggling a little bit. any help will be appreciated.

how can I enter that into the FindFit function?

FindFit[data, model, parms];

I have my data I just can't figure out how to get this into the model and params correctly. This is the eqaution that was given me for the data and just don't know how to input it or to show that it is going to be an exponential curve.

share|improve this question
Ok, here is my question i've got everything working for teh most part. the only thing I am having an issue is tha the X axis is starting at 150 and my first point is at 113. you see the problem, it plots behind the y axis. So, is there a way to initiaize the x-axis. –  Bill Sep 12 '13 at 18:19
your updated question is just about setting the plot range I think. In this case manually setting it works best, put PlotRange -> {{0, 800}, {8000, 11000}} inside your ListPlot. –  george2079 Sep 12 '13 at 19:01
add comment

2 Answers

up vote 2 down vote accepted

It's better to use NonlinearModelFit:

data = {{0, 10}, {1, 5}, {3, 2}, {5, 1}, {6, 0}, {7, 0}};
nlm = NonlinearModelFit[data, a + b Exp[-x/c], {a, b, c}, x]
Show[Plot[nlm[x], {x, 0, 7}]
    ,ListPlot[data, PlotStyle -> {Darker@Green, PointSize[0.03]}]

enter image description here

To see parameters you can use nlm["BestFitParameters"] to get



Using your new test data with @george2079 tip you get:

data = {{462.36,8872},{408.18,8780},{374.4,8915},{322.8,8937},

 nlm=NonlinearModelFit[data, a + b Exp[-x /c], {{a, 100}, {b, 100}, {c, 10}},x] 

 Show[ListPlot[data, PlotStyle -> {Darker@Green, PointSize[0.03]}]

enter image description here

share|improve this answer
I having trouble getting the nonlinearModelfit to Plot it is giving me syntax errors. I think it is something with the ListPlot that it is not liking. –  Bill Sep 11 '13 at 17:36
You can append some sample data into your question, so we can test it. –  Murta Sep 11 '13 at 18:05
@Bill edit your question instead of using comments. –  george2079 Sep 11 '13 at 19:09
I have added data and the functions that I am trying to use to my original question. any suggestions will be greatly appreciated. –  Bill Sep 11 '13 at 19:23
This works great. the only issue I am having is actually getting the line to show. I get the data to plot but don't actually get the curve to plot. any idea what I may be doing wrong. –  Bill Sep 12 '13 at 12:50
show 2 more comments

In this case FindFit and NonlinearModelFit do not readily find a good fit, you need to supply reasonable starting values for the parameters:

data = {{462.36, 8872}, {408.18, 8780}, {374.4, 8915}, {322.8, 
        8937}, {274.00, 8919}, {243.03, 9114}, {209.32, 9277}, {178.91, 
        9394}, {140.71, 9508}, {113.08, 9592}}
FindFit[data, a + b Exp[-x /c], {a, b, c}, x]

(* error The step size in the search has become less than the tolerance ... *)

FindFit[data, a + b Exp[-x /c], {{a, 100}, {b, 100}, {c, 10}}, x]

(* {a -> 8692.35, b -> 1910.19, c -> 161.513} *)

This is a good looking fit, sorry I cant post graphics.

So how do you come up with starting values? I plotted the expression and played with the constants by hand until i got pretty close. Sorry if that is unsatisfactory, but there really is a bit of an art to data fitting that goes beyond what mathematica can do in a fully automatic way.

share|improve this answer
I actually got the line to graph with your code but I am still getting a skewed graph. any ideas. –  Bill Sep 12 '13 at 18:13
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.