0
$\begingroup$

Hi everyone could anyone have look why this code is not running?

    Clear["Global`*"]
   eqn = {(s''[x]/s[x]) + ((3 \[Gamma])/2 - 1) (s'[x]/s[x])^2 - (3 \[Gamma]*f)/2 == 0};
  sol = NDSolveValue[{eqn /. {f -> 0.7, \[Gamma] -> 1}, s'[1] == 1,s[1] == 1}, s[x], {x, 0.1, 8}];
 pp1 = Plot[Evaluate[{s[x] /. {sol {f -> 0.7, \[Gamma] -> 1}}}], {x, 0.1, 8}, 
 PlotStyle -> {Opacity[.2], AbsoluteThickness[5]}];
  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];
  p = 0.7; \[Gamma] = 1;
  pp2 = Plot[w[t] /. sol1, {t, 0.1, 8}, PlotStyle -> {Dashed, Red}];
  Show[pp1, pp2]
$\endgroup$

2 Answers 2

3
$\begingroup$
$Version

(* "14.0.0 for Mac OS X ARM (64-bit) (December 13, 2023)" *)

Clear["Global`*"]

eqn = (s''[x]/s[x]) + ((3  γ)/2 - 1)  (s'[x]/s[x])^2 - (3  γ*f)/
     2 == 0;

Look at the form of sol to better understand why your syntax was wrong

sol = NDSolveValue[{eqn /. {f -> 0.7, γ -> 1}, s'[1] == 1, s[1] == 1}, 
  s[x], {x, 0.1, 8}]

enter image description here

pp1 = Plot[sol, {x, 0.1, 8}, 
   PlotStyle -> {Opacity[.2], AbsoluteThickness[5]}];

To simplify solution of the equation, assign the parameter values first.

p = 7/10; γ = 1;

sol1 = DSolve[{(w''[t]/
        w[t]) + ((3  γ)/2 - 1)  (w'[t]/w[t])^2 - (3 γ*p)/2 == 0,
     w'[1] == 1, w[1] == 1}, w[t], t] // Simplify

(* Solve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.

{{w[t] -> ((-7 + Sqrt[70])^(
      1/3) (7 + Sqrt[70]) E^-Sqrt[(7/
       10)] ((-17 + 2 Sqrt[70]) E^(3 Sqrt[7/10]) + 3 E^(3 Sqrt[7/10] t))^(
      2/3))/(21 2^(2/3) (E^(3 Sqrt[7/10] t))^(1/3))}} *)

pp2 = Plot[Evaluate[w[t] /. sol1[[1]]], {t, 0.1, 8}, 
   PlotStyle -> {Dashed, Red}];

Show[pp1, pp2]

enter image description here

$\endgroup$
1
  • $\begingroup$ thank you now I understand! $\endgroup$ Commented Jun 18 at 18:28
1
$\begingroup$

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

$\endgroup$

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