Skip to main content
Improved code spacing.
Source Link
Somos
  • 4.9k
  • 1
  • 9
  • 15

The code provided has a few issues and can be refined to ensure it runs correctly in Mathematica. Here's a corrected version of the code:

(*Define the differential equation*)
    eqn = (s''[x]/
          s[x]) + ((3 \[Gamma])/2 - 1) (s'[x]/s[x])^2 - (3 \[Gamma]*f)/
         2 == 0;
    
      
(*Solve the differential equation numerically with specified \
    parameters*)
    sol = NDSolveValue[{eqn /. {f -> 0.7, \[Gamma] -> 1}, s'[1] == 1, 
        s[1] == 1}, s, {x, 0.1, 8}];
    
      
(*Plot the numerical solution*)
    pp1 = Plot[Evaluate[sol[x]], {x, 0.1, 8}, 
           PlotStyle -> {Opacity[.2], AbsoluteThickness[5]}];
    
      
(*Solve the differential equation symbolically*)
    sol1 = DSolve[{(w''[t]/
            w[t]) + ((3 \[Gamma])/2 - 1) (w'[t]/w[t])^2 - (3 \[Gamma]*p)/
           2 == 0, w'[1] == 1, w[1] == 1}, w[t], t];
    
      
(*Set parameters*)
    p = 0.7; \[Gamma] = 1;
    
      
(*Plot the symbolic solution*)
    pp2 = Plot[Evaluate[w[t] /. sol1], {t, 0.1, 8}, 
           PlotStyle -> {Dashed, Red}];
    
      
(*Show both plots together*)
    Show[pp1, pp2]

It took 15 minutes and it gave me the following plot

enter image description here

The code provided has a few issues and can be refined to ensure it runs correctly in Mathematica. Here's a corrected version of the code:

(*Define the differential equation*)
    eqn = (s''[x]/
          s[x]) + ((3 \[Gamma])/2 - 1) (s'[x]/s[x])^2 - (3 \[Gamma]*f)/
         2 == 0;
    
     (*Solve the differential equation numerically with specified \
    parameters*)
    sol = NDSolveValue[{eqn /. {f -> 0.7, \[Gamma] -> 1}, s'[1] == 1, 
        s[1] == 1}, s, {x, 0.1, 8}];
    
     (*Plot the numerical solution*)
    pp1 = Plot[Evaluate[sol[x]], {x, 0.1, 8}, 
       PlotStyle -> {Opacity[.2], AbsoluteThickness[5]}];
    
     (*Solve the differential equation symbolically*)
    sol1 = DSolve[{(w''[t]/
            w[t]) + ((3 \[Gamma])/2 - 1) (w'[t]/w[t])^2 - (3 \[Gamma]*p)/
           2 == 0, w'[1] == 1, w[1] == 1}, w[t], t];
    
     (*Set parameters*)
    p = 0.7; \[Gamma] = 1;
    
     (*Plot the symbolic solution*)
    pp2 = Plot[Evaluate[w[t] /. sol1], {t, 0.1, 8}, 
       PlotStyle -> {Dashed, Red}];
    
     (*Show both plots together*)
    Show[pp1, pp2]

It took 15 minutes and it gave me the following plot

enter image description here

The code provided has a few issues and can be refined to ensure it runs correctly in Mathematica. Here's a corrected version of the code:

(*Define the differential equation*)
eqn = (s''[x]/
       s[x]) + ((3 \[Gamma])/2 - 1) (s'[x]/s[x])^2 - (3 \[Gamma]*f)/
       2 == 0;
         
(*Solve the differential equation numerically with specified parameters*)
sol = NDSolveValue[{eqn /. {f -> 0.7, \[Gamma] -> 1}, s'[1] == 1, 
      s[1] == 1}, s, {x, 0.1, 8}];
         
(*Plot the numerical solution*)
pp1 = Plot[Evaluate[sol[x]], {x, 0.1, 8}, 
           PlotStyle -> {Opacity[.2], AbsoluteThickness[5]}];
         
(*Solve the differential equation symbolically*)
sol1 = DSolve[{(w''[t]/
           w[t]) + ((3 \[Gamma])/2 - 1) (w'[t]/w[t])^2 - (3 \[Gamma]*p)/
           2 == 0, w'[1] == 1, w[1] == 1}, w[t], t];
         
(*Set parameters*)
p = 0.7; \[Gamma] = 1;
         
(*Plot the symbolic solution*)
pp2 = Plot[Evaluate[w[t] /. sol1], {t, 0.1, 8}, 
           PlotStyle -> {Dashed, Red}];
         
(*Show both plots together*)
Show[pp1, pp2]

It took 15 minutes and it gave me the following plot

enter image description here

Source Link

The code provided has a few issues and can be refined to ensure it runs correctly in Mathematica. Here's a corrected version of the code:

(*Define the differential equation*)
    eqn = (s''[x]/
          s[x]) + ((3 \[Gamma])/2 - 1) (s'[x]/s[x])^2 - (3 \[Gamma]*f)/
         2 == 0;
    
    (*Solve the differential equation numerically with specified \
    parameters*)
    sol = NDSolveValue[{eqn /. {f -> 0.7, \[Gamma] -> 1}, s'[1] == 1, 
        s[1] == 1}, s, {x, 0.1, 8}];
    
    (*Plot the numerical solution*)
    pp1 = Plot[Evaluate[sol[x]], {x, 0.1, 8}, 
       PlotStyle -> {Opacity[.2], AbsoluteThickness[5]}];
    
    (*Solve the differential equation symbolically*)
    sol1 = DSolve[{(w''[t]/
            w[t]) + ((3 \[Gamma])/2 - 1) (w'[t]/w[t])^2 - (3 \[Gamma]*p)/
           2 == 0, w'[1] == 1, w[1] == 1}, w[t], t];
    
    (*Set parameters*)
    p = 0.7; \[Gamma] = 1;
    
    (*Plot the symbolic solution*)
    pp2 = Plot[Evaluate[w[t] /. sol1], {t, 0.1, 8}, 
       PlotStyle -> {Dashed, Red}];
    
    (*Show both plots together*)
    Show[pp1, pp2]

It took 15 minutes and it gave me the following plot

enter image description here