Message Boards Message Boards

Graph for damped oscillator is not working

Posted 2 years ago

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:

enter image description here

enter image description here

POSTED BY: Daniel Z
2 Replies

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]
POSTED BY: Mariusz Iwaniuk
Posted 2 years ago

Thank you a lot now everything seems to be working correctly!

POSTED BY: Daniel Z
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract