259778
(Daniel Z)
October 18, 2021, 2:08pm
1
I was trying to follow http://courses.washington.edu/ph227814/227/A13/notes/Oscillator.nb.pdf but for some reason I can’t generate graph correctly :
Clear["Global'*"]
DSolve[x''[t]+bx'[t]+kx[t]==0,x[t],t]
res1=DSolve[{x''[t]+bx'[t]+kx[t]==0,x[0]==1,x'[0]==0},x[t],t]
res1plot[b0_]:=Plot[x[t]/.res1/.{b->b0,k->1},{t,0,20},PlotRange->{{0,20},{-1,1}},PlotStyle->Thick,PlotLabel->b0]
res1plot[0]
Clear["Global'*"]
DSolve[{x''[t]+bx'[t]+kx[t]==Sin[\[Omega]t]},x[t],t]
res3=DSolve[{x''[t]+bx'[t]+kx[t]==Sin[\[Omega]t],x[0]==1,x'[0]==0},x[t],t];
res3f[t0_,omin_]=x[t]/.res3/.{b->0.1,k->1,\[Omega]->omin}/.t->t0;
res3plot[omega_]:=Plot[res3f[t,omega],{t,0,200},PlotRange->{{0,200},{-5,5}},PlotStyle->Thick,PlotLabel->omega]
res3plot[.2]
I tried to restart session and made sure to evaluate all cells but it still doesn’t work.Thank you for any help in advance. Screenshots below for visibility:
Syntax is incorrect.Use: “k*x[t]” not “kx[t]” !
Try:
Clear["Global'*"]
DSolve[x''[t] + b*x'[t] + k*x[t] == 0, x[t], t]
res1 = DSolve[{x''[t] + b*x'[t] + k*x[t] == 0, x[0] == 1, x'[0] == 0},
x[t], t]
res1plot[b0_] :=
Plot[x[t] /. res1 /. {b -> b0, k -> 1}, {t, 0, 20},
PlotRange -> {{0, 20}, {-1, 1}}, PlotStyle -> Thick, PlotLabel -> b0]
res1plot[0]
Clear["Global'*"]
DSolve[{x''[t] + b*x'[t] + k*x[t] == Sin[\[Omega]t]}, x[t], t]
res3 = DSolve[{x''[t] + b*x'[t] + k*x[t] == Sin[\[Omega]*t],
x[0] == 1, x'[0] == 0}, x[t], t];
res3f[t0_, omin_] =
x[t] /. res3 /. {b -> 0.1, k -> 1, \[Omega] -> omin} /. t -> t0;
res3plot[omega_] :=
Plot[res3f[t, omega], {t, 0, 200}, PlotRange -> {{0, 200}, {-5, 5}},
PlotStyle -> Thick, PlotLabel -> omega]
res3plot[.2]
259778
(Daniel Z)
October 18, 2021, 3:17pm
3
Thank you a lot now everything seems to be working correctly!