0
$\begingroup$

I have a recursively-defined sequence of functions, g[t,n], that I cannot seem to plot without first evaluating and then referencing the result. What do I need to do to g to get it to plot correctly?

Mathematica Example

$\endgroup$

closed as off-topic by zhk, Daniel Lichtblau, m_goldberg, MarcoB, garej Jul 10 '17 at 9:19

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – zhk, Daniel Lichtblau, m_goldberg, MarcoB, garej
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    $\begingroup$ Post your code not image. $\endgroup$ – zhk Jul 9 '17 at 16:21
  • 3
    $\begingroup$ Try this Plot[Evaluate@g[t, 1], {t, 0, 4}] $\endgroup$ – zhk Jul 9 '17 at 16:26
1
$\begingroup$
g[t_, 0] := -9.8*t^2 + 10

s[n_] := u /. Solve[g[u, n - 1] == 0, u][[2]]

v[n_] := D[g[t, n - 1], t] /. (t -> s[n])

g[t_, n_] := -9.8*(t - s[n])^2 - v[n]/2*(t - s[n])

Plot[Evaluate@g[t, 1], {t, 0, 4}]
$\endgroup$
  • $\begingroup$ Great, thanks! This works. What is the underlying issue though? $\endgroup$ – libcrypt Jul 9 '17 at 16:33
  • 3
    $\begingroup$ Try evaluating Block[{t = 0.1}, g[t, 1]] vs Block[{t = 0.1}, Evaluate @ g[t, 1]] $\endgroup$ – Carl Woll Jul 9 '17 at 17:09

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