0
$\begingroup$

I'm having a problem with using NDSolve. It might be a simple problem, and related to the method's parameters, yet I'm not sure how.

I have two deferential equations, and I'm trying to get the solution between two points a and b where my B.C. are that both of the function are zero at a and b. In the code below, for some reason when d=10 there is a solution, yet for d=1, it returns 1/0 encountered. I'm not sure how to fix it and solve for d=1? I saw that it is related to several factors:

  1. step sizes, and maybe max steps.
  2. the values of a and b
  3. the value of b-a

If I want to get a solution for any a,b that are non zero and positive, how can I fix the other parameters so the code would give me an answer for any value of d?

The code:


a = 0.5; b = 1;
e = 100; d = 10;
sol = NDSolve[{u''[x] == -(1/x)*(u'[x]) - (h'[x])*(h''[x]), (h''[x])*((3/2)*(h'[x])^2 + u'[x]) 
+ h'[x]*u''[x] + d/e == 0, u[a] == 0, u[b] == 0, h[a] == 0, h[b] == 0}, {u[x], h[x]}, {x,a,b}, 
   Method -> "ExplicitRungeKutta", MaxSteps -> \[Infinity], StartingStepSize -> 0.001];
U[x_] := Evaluate[u[x] /. sol[[1, 1]]]; 
H[x_] := Evaluate[h[x] /. sol[[1, 2]]];
Plot[{Evaluate[U[x]], Evaluate[H[x]]}, {x, a, b}]

$\endgroup$
3
  • $\begingroup$ Code works fine for a=1/2 and ` StartingStepSize ->10^-3`. So you can try rational numbers as input parameters. $\endgroup$ Jun 27 '21 at 10:54
  • $\begingroup$ It still does not work for d=1 $\endgroup$
    – jonathan
    Jun 27 '21 at 16:01
  • $\begingroup$ See my answer with possible solution. $\endgroup$ Jun 27 '21 at 18:28
2
$\begingroup$

We can use different options when try to solve BVP, for instance

a = 1/2; b = 1;
e = 100; d = 1;
sol = NDSolve[{u''[
      x] == -(1/x)*(u'[x]) - (h'[x])*(h''[x]), (h''[
         x])*((3/2)*(h'[x])^2 + u'[x]) + h'[x]*u''[x] + d/e == 0, 
    u[a] == 0, u[b] == 0, h[a] == 0, h[b] == 0}, {u[x], h[x]}, {x, a, 
    b}, Method -> "ExplicitEuler", MaxSteps -> \[Infinity], 
   StartingStepSize -> 10^-3];
U[x_] := Evaluate[u[x] /. sol[[1, 1]]];
H[x_] := Evaluate[h[x] /. sol[[1, 2]]];
Plot[{Evaluate[U[x]], Evaluate[H[x]]}, {x, a, b}, PlotLegends -> {"U", "H"}]  

Figure 1

$\endgroup$

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.