I want to solve the below differential equation:
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.
I want to solve the below differential equation:
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.
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]
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)
]
]
Note the result of DSolve is a DifferentialRoot, but it can be evaluated like other expressions.
thank you!
do you also know if i can give a vector of values to a ?
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
)
]
]
Thank you so much this was exactly what i needed!