0
|
4431 Views
|
4 Replies
|
4 Total Likes
View groups...
Share
GROUPS:

# Solving y'=y, y(0)=1

Posted 9 years ago
 Why does the following keep happening to me. Using 10.0.1.0. This is with a clean start, quit the kernel, evaluate the notebook. 4 Replies
Sort By:
Posted 9 years ago
 David,One of the best answers I have seen thus far.Thanks.
Posted 9 years ago
 In this code sequence In:= Clear[y] In:= sol = DSolve[{y'[t] == y[t], y == 1}, y[t], t] Out= {{y[t] -> E^t}} In:= y[t_] := y[t] /. First[sol] In:= y[x] During evaluation of In:= \$RecursionLimit::reclim: Recursion depth of 1024 exceeded. >> Out= Hold[y[x]] In uses a SetDelayed. (=. ) This means that the kernel now has a definition for y[t_] ( meaning y[anything], but call it t ) for which the defined substitution is the rule on the right hand side. But DELAYED set means that the right hand side is not evaluated until the definition is applied. When In is encountered, the engine has a definition for y[x] which tells it to first substitute x for t into y[t]/.First[sol], which gives y[x]/.First[sol], and then to evaluate that, which gives y[x]. It gives y[x] because the rule being applied defines y[t], not y[x]. But it does not stop there. When y[x] is returned the evaluation engine again looks to see if it has a rule for y[x]. It does, it still has the definition for y[anything]. The evaluation process in Mathematica works like that. It continues to evaluate until the result is such that no rule will apply. That's why the engine stops at a RecursionLimit.In the code below In:= Clear[y] In:= y[t_] := Evaluate[y[t] /. First[sol]] In:= y[x] Out= E^x The Evaluate on the right hand side forced the evaluation so that the definition for y[t] that is produced is really y[t_]:=E^t, since the right hand side was evaluated before the definition was made. Now, when In is evaluated, the first evaluation finds that there is a rule in the kernel for y[anything] which takes it to E^anything. so y[x] becomes E^x. The engine finds it has no further rule for E^x, so it returns that. (If x=2 was previously executed, it would find it had a rule for x, and would return E^2.Evaluate on the right hand side of SetDelayed is functionally equivalent to using Set rather than SetDelayed, as in the code below In:= Clear[y] In:= y[t_] = y[t] /. First[sol] Out= E^t In:= y[x] Out= E^x Kind regards,David
Posted 9 years ago
 What does the phrase "otherwise the rule is executed only if y is called ..." mean? Thanks.
Posted 9 years ago
 This works, In:= Clear[y] sol = DSolve[{y'[t] == y[t], y == 1}, y[t], t] Out= {{y[t] -> E^t}} In:= y[t_] := Evaluate[y[t] /. First[sol]] In:= y[x] Out= E^x otherwise the rule is executed only if y is called ...