0
$\begingroup$

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
$\endgroup$
3
  • 2
    $\begingroup$ Before you can use NDSolve your ode must be properly defined: YY isn't defined, use D[f[z], {z, 2}](not Dt). $\endgroup$ Nov 15 '19 at 10:42
  • $\begingroup$ 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. $\endgroup$
    – Proxy Kad
    Nov 16 '19 at 12:55
  • $\begingroup$ Please check the document of ReplaceAll (/.) carefully, you cannot live without this function when using Mathematica. $\endgroup$
    – xzczd
    Nov 20 '19 at 8:14
1
$\begingroup$

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]

enter image description here

$\endgroup$
6
  • $\begingroup$ Thanks for the answer $\endgroup$
    – Proxy Kad
    Nov 20 '19 at 9:00
  • $\begingroup$ 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? $\endgroup$
    – Proxy Kad
    Nov 20 '19 at 9:09
  • $\begingroup$ You can use F[z] like other built in functions. $\endgroup$ Nov 20 '19 at 9:11
  • $\begingroup$ but it is pasting the same function as it is. I mean interpolated function graph as it is $\endgroup$
    – Proxy Kad
    Nov 20 '19 at 9:18
  • $\begingroup$ Sorry I didn't get what you really want to do with F[z] $\endgroup$ Nov 20 '19 at 9:21

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.