0
$\begingroup$

I want to plot the solution to the following differential equation with different values of parameters. What is the best way to do it instead of solving the equation individually by inserting the parameters?

1/xi^2 D[xi^2 D[theta[xi],xi],xi] == - theta[xi]^n 
xi = {0,10} 
n = 0,1,1.5,3

n is the parameter that takes all these above values. And theta needs to be solved as a function of xi.

$\endgroup$
1
  • $\begingroup$ You need to give initial conditions also. $\endgroup$
    – Nasser
    Jun 21 at 1:01

1 Answer 1

4
$\begingroup$

Something to get you started,. You can use Manipulate

enter image description here

ClearAll[theta, xi, n];
ode = 1/xi^2 D[xi^2 D[theta[xi], xi], xi] == -theta[xi]^n
ic = {theta[$MachineEpsilon] == 1, (D[theta[xi], xi] == 1) /. xi -> $MachineEpsilon};
Manipulate[
 sol = NDSolveValue[{ode /. {n -> n0}, ic}, 
   theta, {xi, $MachineEpsilon, 10}, Method -> {"StiffnessSwitching"}];
 Plot[sol[xi], {xi, 0, 10}, PlotRange -> All, PlotStyle -> Red, 
    GridLines -> Automatic, GridLinesStyle -> LightGray]
 ,
 {{n0, 0, "n"}, {0, 1, 1.5, 3}},
 TrackedSymbols :> {n0}
 ]
$\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.