4
$\begingroup$

I reviewed Q1 and Q2, but I can not use of they. I wrote the following code:

eq = D[u[x], {x, 2}] - Pi^2*Exp[u[x]] == 0; 
init = {u[0] == 0, u[1] == 0}; 
Eqe = Quiet[NDSolve[Join[eq, init], u[x], {x, 0, 1}]]

I do not know why it does not work. Any suggestions?

$\endgroup$
  • 1
    $\begingroup$ First, it should be Join[{eq}, init]. $\endgroup$ – corey979 Jan 7 '17 at 19:36
5
$\begingroup$

This is one hell of a simple BVP, which Mathematica does not handle with ease.

Here is my experimentation,

eq = u''[x] - Pi^2*Exp[u[x]] == 0;
init = {u[0] == 0, u[1] == 0};

First, I tried without specifying the method like the OP

sol = NDSolve[Join[{eq}, init], u[x], {x, 0, 1}]

NDSolve::ndsz: At x == 0.7071067304302846`, step size is effectively zero; singularity or stiff system suspected.

Then, with a method,

sol = NDSolve[Join[{eq}, init], u[x], {x, 0, 1}, 
  Method -> {"ExplicitRungeKutta", "StiffnessTest" -> False}]

NDSolve::ndsz: At x == 0.7071067304302846`, step size is effectively zero; singularity or stiff system suspected.

Shooting

After trying different method's, finally I got lucky with shooting

sol = NDSolve[Join[{eq}, init], u[x], {x, 0, 1}, 
  Method -> {"Shooting", 
    "StartingInitialConditions" -> {u[0.0] == 0, u'[0.0] == 0}}]

NDSolve::ndsz: At x == 0.7071067304302846`, step size is effectively zero; singularity or stiff system suspected.

The singularity seems to occur in the vicinity of x=1. So, I tried with different StartingInitialConditions and finally got able to produce an answer without any warning.

sol = NDSolve[Join[{eq}, init], u[x], {x, 0, 1}, 
  Method -> {"Shooting", 
    "StartingInitialConditions" -> {u[0.5] == 0, u'[0.5] == 0}}]
Plot[u[x] /. sol, {x, 0, 1}]

enter image description here

Note

This BVP can easily be solved with maple numerically,

restart;with(plots):
eq := diff(u(x),x$2)-Pi^2*exp(u(x));
ibcs:=(u)(0)=0,u(1)=0;
sol:=dsolve({eq,ibcs},numeric);
odeplot(sol,[[x,u(x)]],0..1,color=[red],axes=boxed);

enter image description here

Finally, comparing the solutions from both Mathematica and Maple

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ Many many thanks. In this way, output just is plot. Is the function of solution can be found with Plot? $\endgroup$ – user45459 Jan 8 '17 at 6:29
  • $\begingroup$ @user45459 The output of NDSolve is an interpolating function not just a plot InterpolatingFunction[data][x]. Plot command is only used for plotting nothing else. $\endgroup$ – zhk Jan 8 '17 at 6:50
  • $\begingroup$ I am confused. Because I do not have any output. I want to have a function u[x] on [0,1], but I gain Plot on [0,1]. Is there any way which I gain a function u[x] or a polynomial for interpolation function? $\endgroup$ – user45459 Jan 8 '17 at 7:22
  • $\begingroup$ @user45459 Well, NDSolve produces numerical solution in terms of interpolation function. If you are looking for analytical solution then you should use DSolve? DSolve[eq, u, x] $\endgroup$ – zhk Jan 8 '17 at 8:07

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.