Message Boards Message Boards

Solve $y'' -2*(x^4-e)y = 0$ 2nd order non-linear differential equation?

Posted 7 years ago

I want to solve the below differential equation:

$$y'' -2*(x^4-e)y = 0$$

with i.c. y(0) = 1 , y'(0) = 0

the values of e can be different, and I want to plot the result for different given values of e. I would be grateful if someone could help me answer this question.

6 Replies
sol = DSolve[{y''[t] - 2*(t^4 - e) y[t] == 0, y[0] == 1, y'[0] == 0}, y, t]
sol = First@sol;

With[{erange = Range[2, -2, -1]},
 Plot[
  Evaluate@Table[
    y[t] /. sol,
    {e, erange}],
  {t, 0, 2},
  PlotLegends -> (HoldForm[e = #] & /@ erange)
  ]
 ]

plot of solutions

Note the result of DSolve is a DifferentialRoot, but it can be evaluated like other expressions.

POSTED BY: Michael Rogers

This is exactly what I want except that it doesn't work with non-integer values for 'e' :( Can you help me to fix that? Id really appreciate it

You can use Rationalize[.., 0] or SetPrecision[.., Infinity] to convert approximate numbers to the exact numbers required by DifferentialRoot[]. (There is a slight difference between the two functions, on the order of 10^-16 or less, but it makes no difference in plotting these solutions.)

SeedRandom[2];
With[{erange = Sort[RandomReal[{-3, 3}, 6]]},
 Plot[
  Evaluate@Table[
    y[t] /. sol,
    {e, Rationalize[erange, 0]}],
  {t, 0, 2},
  PlotLegends -> (HoldForm[e = #] & /@ erange
    )
  ]
 ]

enter image description here

POSTED BY: Michael Rogers

Thank you so much this was exactly what i needed!

ParametricNDSolve is the function that you are looking for. Use the second example on the page:

sol = ParametricNDSolve[{y''[t] - 2*(t^4-a)  y[t] == 0, y[0] == 1, y'[0] == 0},y, {t, 0, 1}, {a}]
Plot[Evaluate[Table[y[a][t] /. sol, {a, -1, 1, .1}]], {t, 0, 1}, PlotRange -> All]
POSTED BY: Shenghui Yang

thank you! do you also know if i can give a vector of values to a ?

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract