0
$\begingroup$

I wanted to know the exact solution to the following differential equation

$$ \frac{\mathrm{d}^2 y}{\mathrm{d} t^2} = - \frac{1}{y-1}, \quad \begin{aligned} y(0) &= 0 \\ \left. \frac{\mathrm{d} y}{\mathrm{d} t} \right|_{t = 0} &= 0 \end{aligned} $$

I expected some function that would increase with time until it hits one.

So I set up the DE in MMA

ClearAll[y];
DSolve[{y''[t] == -(1/(y[t] - 1)), y[0] == 0, y'[0] == 0}, y[t], t]

And the result is

{y[t] -> E^-InverseErf[-Sqrt[(2/\[Pi])] t]^2 (-1 + E^
     InverseErf[-Sqrt[(2/\[Pi])] t]^2)}

So I try to plot it with derivatives

y[t] := E^-InverseErf[-Sqrt[(2/\[Pi])] t]^2 (-1 + E^
     InverseErf[-Sqrt[(2/\[Pi])] t]^2);
Plot[Evaluate[{y[t], 1/(y[t] - 1), D[y[t], t], D[y[t], {t, 2}]}], {t, 
  0, 2}]

And everything goes fine.

However, when I'm trying to obtain the value at which the function stops (I think it is $t = \sqrt{\pi/2}$), MMA doesn't know

Solve[y[t] == 1, t]
{}

When I tried to get certain values, MMA doesn't even return a number!

y[0.5]
y[0.5]

or

Evaluate[y[0.5]]
y[0.5]

Clearly, the plot behaves well around $t = 0.5$, so why does it refuse to return a value?

The only thing that seems to work is the following

y[t] /. t -> 0.5
0.12777

Can someone please explain this behaviour? I am curious.

$\endgroup$
  • $\begingroup$ Simply y[t_] :=...., i.e. use the underscore in defining the function. $\endgroup$ – corey979 Apr 22 at 21:44
3
$\begingroup$

When you write:

y[t]:=rhs

That means, "when you see y[t], rewrite it as rhs and continue evaluating. Here, t is just a literal symbol, not an argument, so y[anything but t] doesn't match and nothing happens. But:

y[t_]:=rhs

is very different. Here, t is the name of a pattern, unrestricted in this case, so it matches anything at all. The rewrite here starts by rewriting every t in rhs by whatever matched the pattern. The result replaces y[whatever], and evaluation continues. This is how Mathematica, an expression rewriting language, imitates a function call.

$\endgroup$
  • $\begingroup$ Thank you very much! That might explain why the ./t-> thing worked! $\endgroup$ – user16320 Apr 22 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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