0
$\begingroup$

I want to plot solution of differential equations. I can get real values out of my function, and get no errors from the Plot, but also no curve shows up.

Assume initial condition θ[0] = π/6, θ'[0] = 1.

Here is my code:

Clearall

T[t_] = 
  ExpToTrig[
    DSolve[
      {θ''[t] + 2 g θ[t]/(3(R - ρ)) == 0 /. {R -> 1, ρ -> 2, g -> 9.81}, 
       θ[0] == 0.52, θ'[0] == 1}, θ[t], t]]

T1[t_] = 
  NDSolve[
    {θ''[t] + 2 g θ[t]/(3*(R - ρ)  == 0 /. {R -> 1, ρ -> 2, g -> 9.81 },
     θ[0] == π/6, θ'[0] == 1}, θ[t], {t, 0, 10}]

 T[t]
 Plot[T[t], {t, 0.1, 1}]
 T[2]
 T1[2]

Any help would be appreciated.

$\endgroup$

closed as off-topic by m_goldberg, xzczd, Henrik Schumacher, Öskå, MarcoB Feb 11 at 0:50

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – m_goldberg, xzczd, Henrik Schumacher, Öskå, MarcoB
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    $\begingroup$ Try these syntax fixes T[t_] =ExpToTrig[θ[t]/.DSolve[{θ''[t] + 2*g*θ[t]/(3*(R - ρ)) ==0 /. {R->1, ρ->2, g->9.81 },θ[0]==0.52,θ'[0] == 1}, θ[t], t][[1]]]; T1[t_] = θ[t]/.NDSolve[{θ''[t] + 2*g*θ[t]/(3*(R - ρ))==0/.{R->1, ρ->2, g->9.81 }, θ[0] == \[Pi]/6, θ'[0] == 1}, θ[t], {t, 0, 10}][[1]]; and then you can use your last four lines T[t], Plot[... $\endgroup$ – Bill Feb 10 at 3:52
  • 1
    $\begingroup$ Be aware that Clearall standing alone accomplishes nothing. It is not a command. It is a symbol naming a function. You must give it arguments. Hower, in your situation Clear is more appropriate. It not a command either, so give it arguments. $\endgroup$ – m_goldberg Feb 10 at 5:57
  • $\begingroup$ @m_goldberg Clearall is not even a built-in symbol. OP probably meant to use ClearAll... $\endgroup$ – Henrik Schumacher Feb 10 at 11:18
  • $\begingroup$ @HenrikSchumacher. Yeah, I automatically read it as ClearAll. $\endgroup$ – m_goldberg Feb 10 at 16:06
2
$\begingroup$
T[t_] = ExpToTrig[
   First@DSolve[{θ''[t] + 2*g*θ[t]/(3*(R - ρ)) == 
        0 /. {R -> 1, ρ -> 2, g -> 9.81}, θ[0] == 
       0.52, θ'[0] == 1}, θ[t], t]];
T1[t_] = First@
   NDSolve[{θ''[t] + 2*g*θ[t]/(3*(R - ρ)) == 
       0 /. {R -> 1, ρ -> 2, g -> 9.81}, θ[0] == π/
       6, θ'[0] == 1}, θ, {t, 0, 10}];

Plot[{θ[t] /. T[t]}, {t, 0, 10}, PlotStyle -> {Red}, PlotRange -> All]

Plot[{θ[t] /. T1[t]}, {t, 0, 10}, PlotStyle -> {Red}, PlotRange -> All]
$\endgroup$
  • 1
    $\begingroup$ +1 Recommend that you use exact numbers for the parameters and in the first plot set the WorkingPrecision. The plot will be much smoother. $\endgroup$ – Bob Hanlon Feb 10 at 4:40

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