0
$\begingroup$

I kindly ask if someone could help me solve this problem:

I have solved a differential equation by varying a parameter that I called by $\alpha$ as follows:

n=1;
solution = 
 Table[NDSolveValue[{(D[ω[z], {z, 2}] + 2/z*D[ω[z], z] - 
        5*α*
         D[ω[z], z]^2) + (1 + α*(4*n + 18)*ω[
           z])*ω[z]^n == 0, ω[0.0001] == 
     1, ω'[0.0001] == 0}, ω, {z, 0.0001, 10}, 
   MaxSteps -> 1000], {α, 0, 0.5, 0.01}];

After that, I found the first root for each function resulting from the above solution according to the $\alpha$ value:

For[ i = 0, i <= 50, i++,q = FindRoot[a[[i]][z], {z, firstzero, 0, 10}]; Print[q]]

I would like to construct a table where I can have all the values of $\alpha$, the solutions of differential equation according to $\alpha$, the first root of solutions according to $\alpha$, and also I would like to include in this table the results of the following calculations (for each value of $\alpha$):

x = -z^2*((1 - (4*n + 18)*α*ω[z])*(D[ω[z], {z, 
      2}] + 2/z*D[ω[z], z]) - 
 5*α*D[ω[z], z]^2) /. solution
m = NIntegrate[x, {z, 0.0001, firstroot}]

I want to export this table and use its data to plot some graphics.

Thank you!

$\endgroup$

1 Answer 1

2
$\begingroup$

I would include your auxiliary integral into the ODE, and then use WhenEvent to find the first zero crossing:

n = 1;
pf[α_] := Block[{z0},
    NDSolveValue[
        {
        ω''[z] + 2/z ω'[z] - 5 α ω'[z]^2 + (1 + α (4 n+18) ω[z]) ω[z]^n == 0,
        ω[0.0001]==1, ω'[0.0001]==0,
        int'[z] == -z^2 ((1 - (4 n+18) α ω[z]) (ω''[z] + 2/z ω'[z]) - 5 α ω'[z]^2),
        int[0.0001]==0,
        WhenEvent[ω[z]==0, z0 = z; "RemoveEvent"]
        },
        {ω, z0, int[z0]},
        {z,0.0001,10},
        MaxSteps->1000
    ]
]

The function pf returns the interpolating function, the crossing point and the integral. For example:

pf[.05]

{InterpolatingFunction[Domain: {{0.0001,10.}} Output: scalar], 2.5631,1.06507}

(It is also possible to use ParametricNDSolveValue, but in that case capturing the zero crossing with a global variable doesn't work well)

$\endgroup$
1
  • $\begingroup$ Thank you! It worked very well. $\endgroup$
    – R.Andre
    Apr 11, 2018 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.