I have to plot the following function and I also need to export it somehow, as an image or another kind of file (I need to use it in $\LaTeX$ after),

Here is the function:

\begin{equation} y(t)=656.96-156.96e^{0.25t}+39.24t \end{equation} I know how to plot simple functions in Mathematica: Plot[ f, {x , xmin, xmax}] and then shift+enter.

However I have been trying to plot the function above and it doesn't work. What I obtain is clearly a wrong graph. I've realised maybe my problem could be how to write the exponential inside that expression. Could someone please tell me the command the plot this function? y(t) should be on the ordinates and $t$ in the abscissa.

This is the code that I have used in Mathematica:

Plot[656.96 - 156.96*Exp[0.25*t] + 39.24*t, {t, -500, 500}]
  • $\begingroup$ Include the code you tried in your question. Someone will be able to see what you have done and point you in the correct direction. $\endgroup$ – Edmund Feb 27 '16 at 20:07
  • $\begingroup$ The exponential function in Mathematica is either represented as E^(0.25 t) (note the capital E), or as Exp[0.25 t]. A lowercase e would not work. Also, have you substituted t for x in your plot range? $\endgroup$ – MarcoB Feb 27 '16 at 20:09
  • $\begingroup$ I've just edited my question Edmund, thank you! And yeah I used t, in my plot range, you can see my code above now. $\endgroup$ – Physics_Student Feb 27 '16 at 20:10
  • $\begingroup$ That seems to be correct syntax. What is wrong with the output you get? In other words, what were you expecting instead? $\endgroup$ – MarcoB Feb 27 '16 at 20:11
  • 1
    $\begingroup$ Well, think about it for a moment, don't just put in random numbers as the range. The difference of your roots is ~23, that's 0.02 times the width of your range. Mathematica's default images size is 360 pixels, so your roots would be a barely visible 7 pixels apart. Thin about what values you expect from your equation and choose a reasonable range based on that, e.g. just around your roots. Also play with PlotRange to show an interesting vertical range, not everything dow to $-10^{56}$, which is the value of your function at 500. $\endgroup$ – Szabolcs Feb 27 '16 at 20:20
y[t_] = 656.96 - 156.96 E^(0.25 t) + 39.24 t // Rationalize

(*  16424/25 - (3924*E^(t/4))/25 + 
   (981*t)/25  *)

The zeroes are

Solve[y[x] == 0, x, Reals] // N

(*  {{x -> -16.6803}, {x -> 7.14882}}  *)

The maximum value is

max = Maximize[y[x], x, Reals][[1]]

(*  500  *)

Absent some other criteria, set the plot domain such that the plot range is {-max, max}

{xmin, xmax} = x /. Solve[y[x] == -max, x, Reals] // N

(*  {-29.4817, 9.06228}  *)

Plot[y[t], {t, xmin, xmax}]

enter image description here


WolframAlpha is a reasonably good tool for beginners to explore how to figure out code on such a problem as this.

Just paste your formula into a string for WolframAlpha and it will try to figure out a reasonable way to graph it.


enter image description here

There are min and max sliders that allow dynamic adjustment of the plot domain. Clicking the + button in the upper right corner of the pod and selecting "Input" yields the following code:

{HoldComplete[Plot[656.96 - 156.96 E^(0.25 t) + 39.24 t, {t, -12, 12}]], 
 HoldComplete[Plot[656.96 - 156.96 E^(0.25 t) + 39.24 t, {t, -72, 72}]]}

One can copy the Plot command from inside HoldComplete and perhaps change -12 to something like -30 that would include the other root. The output that is not shown also includes the roots of the function and its maximum, among other things.


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