# Using the results from NDSolve in another equation

I want to use the results sol returned from NDSolve (values of f at different z) in acc and also f[z] appears in my Gam variable. How can I get these values?

sol = NDSolve[
{Dt[f[z], {z, 2}] == YY, f[0] == 1, f'[0] == 0},
f[z], {z, 0, 6*10^(-4)}]

Plot[Evaluate[f[z] /. sol], {z, 0, 6*10^(-4)}, PlotRange -> All]

A1 = Exp[(-3/2)*t]* t^((3*n - 1)/2)* (LaguerreL[m, n, t]^2)

A2 = 1.0 - ((1/Gam)*(Wpo / Wo)^2) - (ko*vth/Wo)^2

A3 =
(n + 2*m)*LaguerreL[m, n, t] - t*LaguerreL[m, n, t] -
2*(m + n)*LaguerreL[m - 1, n, t]

G1 = A1*A3/A2

G = Integrate[G1, {t, 0, Infinity}]

acc = (Factorial[m]/Factorial[m + n])*((Wpo^2*ro)/(c*Wo))*(E1^(1/2))/f[z]^2)*G

---

m = 2

n = 1

E1 = 1.5
(*intensity=E1=b E1^2*)

Wpo = 1.7683*10^(15)

Wo = 1.7773*10^(15)

ro = 15.0*10^(-6)

c = 3.0*10^8

ko = 1.38* 10^(-23)

to = 10^7

me = 9.1*10^(-31)

vth = 2*ko*to/(3*me*(c^2))

Gam = (1 + (E1/((f[z])^2)) t^n Exp[-t] (LaguerreL[m, n, t])^2)^(-1/2)

s1 = Exp[-t] t^(n - 1) LaguerreL[m, n, t]^2

s2 = Exp[-t] t^(n - 1) (LaguerreL[m - 1, n, t])^2

s3 = Exp[-t] t^(n - 1) (LaguerreL[m, n, t]*LaguerreL[m - 1, n, t])

s4 = t^(2*n + 1) Exp[-t] (LaguerreL[m, n, t])^2

s5 = (2*n + 4*m)*(LaguerreL[m, n, t])^2/t -
2*(LaguerreL[m, n, t])^2 -
4*(m + n)*LaguerreL[m, n, t]*LaguerreL[m - 1, n, t]/t

Y1 = ((n + 2*m)^2 Integrate[s1, {t, 0, Infinity}] +
Factorial[m + n]*(2*m + n + 1)/Factorial[m] +
4*(m + n)^2 Integrate[s2, {t, 0, Infinity}] -
2*(n + 2*m)*Factorial[m + n]/Factorial[m] -
4*(m + n)*(n + 2*m)*Integrate[s3, {t, 0, Infinity}])

Y = (1 - (3/2)*(E1/((f[z])^2)*
t^n Exp[-t] (LaguerreL[m, n, t])^2)) (t^(2*n +
1) Exp[-t] (LaguerreL[m, n, t])^2) ((2*n +
4*m)*(LaguerreL[m, n, t])^2/t - 2*(LaguerreL[m, n, t])^2 -
4*(m + n)*LaguerreL[m, n, t]*LaguerreL[m - 1, n, t]/t)

Y3 = Integrate[Y, {t, 0, Infinity}]

Y4 = Factorial[
m]/(Factorial[
m + n]*(2*m + n + 1)*(f[z])^3)*(Y1 + (E1*Wpo^2*ro^2/(c^2)) Y3)

Y5 = (1/f[z])*(D[f[z], z])^2

YY = Y4 - Y5

sol = NDSolve[{Dt[f[z], {z, 2}] == YY, f[0] == 1, f'[0] == 0},
f[z], {z, 0, 6*10^(-4)}]

Plot[Evaluate[f[z] /. sol], {z, 0, 6*10^(-4)}, PlotRange -> All]

A1 = Exp[(-3/2)*t]* t^((3*n - 1)/2)* (LaguerreL[m, n, t]^2)

A2 = 1.0 - ((1/Gam)*(Wpo / Wo)^2) - (ko*vth/Wo)^2

A3 = (n + 2*m)* LaguerreL[m, n, t] - t* LaguerreL[m, n, t] -
2*(m + n)* LaguerreL[m - 1, n, t]

G1 = A1*A3/A2

G = Integrate[G1, {t, 0, Infinity}]

acc = (Factorial[m]/ Factorial[m + n])* ((Wpo^2 *ro)/(c * Wo))*((E1^(1/2))/f[z]^2) * G

I want to plot acc by using the value of F[z] in the integration of G

• Before you can use NDSolve your ode must be properly defined: YY  isn't defined, use D[f[z], {z, 2}](not Dt). Nov 15 '19 at 10:42
• I had defined it but not shown here. The result till plot equation is achieved, but I want to use the solution of f[z] from the first equation sol in my last equation. Nov 16 '19 at 12:55
• Please check the document of ReplaceAll (/.) carefully, you cannot live without this function when using Mathematica. Nov 20 '19 at 8:14

Assuming your ode is well defined(YY still isn't defined ) you can use NDSolveValue(I changedDtto D in your original ode andYY=1) :

F = NDSolveValue[{D[f[z], {z, 2}] == 1, f[0] == 1, f'[0] == 0}, f , {z, 0, 6*10^(-4)}]


Now you can use F[z] in your calculations!

F[.0002] (*1.*)
Plot[ F[z] , {z, 0, 6*10^(-4)}, PlotRange -> All]


• Thanks for the answer Nov 20 '19 at 9:00
• Actually, I want to ask whether I can use this F[z] at some other place, where a new equation is a function of F[z]? Can I have a plot between the new-made function and z? Nov 20 '19 at 9:09
• You can use F[z] like other built in functions. Nov 20 '19 at 9:11
• but it is pasting the same function as it is. I mean interpolated function graph as it is Nov 20 '19 at 9:18
• Sorry I didn't get what you really want to do with F[z] Nov 20 '19 at 9:21