Why can't Mathematica solve this equation as stated?

DSolve[{z''[t]==(z'[t])^2+(z[t])^2-Sin[t]-1, z[0]==0,z[Pi/2]==1},z[t],t]
(* -> DSolve[{z''[t]==(z'[t])^2+(z[t])^2-Sin[t]-1, z[0]=0,z[Pi/2]=1},z[t],t] *)

Is there another way to solve it?

  • 1
    $\begingroup$ Even correcting for the ==, it still can't solve it: what makes you think it has a closed form solution? NDSolve gives an interpolating function as a solution. $\endgroup$ – bill s Jun 16 '13 at 13:22
  • 1
    $\begingroup$ What version of Mathematica are you using, by any chance? $\endgroup$ – J. M. is in limbo Jun 16 '13 at 13:45
  • 2
    $\begingroup$ Well, the problem is that the chasing method is the only method available in Mathematica 5.2, and the other methods for BVPs only showed up in later versions. So, at the very least, you can't use NDSolve[] directly. You might want to try implementing shooting yourself... $\endgroup$ – J. M. is in limbo Jun 16 '13 at 14:55
  • 5
    $\begingroup$ "implementing shooting yourself" - a bit harsh :) $\endgroup$ – cormullion Jun 16 '13 at 15:13
  • 2
    $\begingroup$ @cormullion, I suppose I could've suggested relaxation, but shooting is more effective for this matter... ;) $\endgroup$ – J. M. is in limbo Jun 16 '13 at 16:23

Although you're using an outdated Mathematica version, the problem should be solvable as follows:

Instead of specifying two boundary conditions for the unknown function z[t] (one at $0$ and the other at $\pi/2$), start by imposing initial conditions at one end of the interval. In addition to the boundary condition you already have, a complete set of initial conditions for this second-order differential equation can be formed by additionally specifying the first derivative at that point.

Depending on the differential equation, one side of the t interval may be preferable to the other, depending on how sensitive the solution is to variations in the first derivative on each side. Here I'll choose the right-hand boundary to impose the initial conditions:

backwardSolution[finalSlope_?NumericQ] := z[t] /. First[
   NDSolve[{z''[t] == (z'[t])^2 + (z[t])^2 - Sin[t] - 1, 
     z[Pi/2] == 1, z'[Pi/2] == finalSlope},
    z, {t, Pi/2, 0}]]

boundaryValue[finalSlope_?NumericQ] := 
 backwardSolution[finalSlope] /. t -> 0

slope = finalSlope /. FindRoot[
   {finalSlope, 1/2}

(* ==> -4.4082*10^-8 *)

Plot[Evaluate[backwardSolution[slope]], {t, 0, Pi/2}]


This method works by imposing an arbitrary "final" slope at $t = \pi/2$, and then "chasing" the solution back to the initial time $t = 0$ in the function backwardSolution[finalSlope]. The function boundaryValue returns the resulting initial value of the solution. This value is supposed to match the first boundary condition, z[0] == 0, but initially it will not, because the final slope that we used was wrong. So the FindRoot step looks for the correct value of this finalSlope.

Once it is found, we call it slope, re-do the backwardSolution[slope] for this value and plot the resulting InterpolatingFunction. To impose a different boundary condition at t = 0, you could change the boundaryValue function by subtracting the desired boundary value from it (so that it returns zero when the boundary condition is satisfied).


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