Using Mathematica to solve oscillator differential equations Unforced, damped oscillator General solution to forced harmonic oscillator equation (which fails when b^2=4k, i.e. at perfect damp- ing). C[1] and C[2} are integration constants. In[8]:= DSolve@x''@tD + bx'@tD + kx@tD 0, x@tD,tD Out[8]= ::x@tD fiª 1 2 -b- b 2 -4k t C@1D +ª 1 2 -b+ b 2 -4k t C@2D>> Now let's solve with boundary conditions: x=1 at t=0 and it is at rest. Then get a fully defined solution. In[9]:= res1 = DSolve@8x''@tD + bx'@tD + kx@tD 0, x@0D 1,x'@0D 0<,x@tD,tD Out[9]= ::x@tD fi 1 2 b 2 - 4k - b ª 1 2 -b- b 2 -4k t + b ª 1 2 -b+ b 2 -4k t +ª 1 2 -b- b 2 -4k t b 2 - 4k +ª 1 2 -b+ b 2 -4k t b 2 - 4k >> Set up a function to plot the result, here setting k=1 so the undamped frequency is 1, and keeping the damping constant as a variable. Note the construction with two "/." in turn ("use the assignment res1, and, within that, make the assignments to b and k"). In[10]:= res1plot@b0_D := Plot@x@tD. res1 . 8b fi b0, k fi 1<, 8t, 0, 20<, PlotRange fi 880, 20<, 8- 1, 1<<, PlotStyle fi Thick, PlotLabel fi b0D Here's what the oscillations look like with no damping: In[11]:= res1plot@0D Out[11]= 5 10 15 20 -1.0 -0.5 0.0 0.5 1.0 0 Underdamping (b^2 < 4 k). First, very weak damping (b=0.1), which is the value used below for the driven oscillator.
7
Embed
Unforced, damped oscillator - UW Courses Web Servercourses.washington.edu/ph227814/227/A13/notes/Oscillator.nb.pdf · Using Mathematica to solve oscillator differential equations
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Using Mathematica to solve oscillator differential equations
Unforced, damped oscillator
General solution to forced harmonic oscillator equation (which fails when b^2=4k, i.e. at perfect damp-
ing). C[1] and C[2} are integration constants.
In[8]:= DSolve@x''@tD + b x'@tD + k x@tD � 0, x@tD, tD
Out[8]= ::x@tD ® ã
1
2-b- b
2-4 k t
C@1D + ã
1
2-b+ b
2-4 k t
C@2D>>
Now let's solve with boundary conditions: x=1 at t=0 and it is at rest. Then get a fully defined solution.
In[9]:= res1 = DSolve@8x''@tD + b x'@tD + k x@tD � 0, x@0D � 1, x'@0D � 0<, x@tD, tD
Out[9]= ::x@tD ®1
2 b2 - 4 k
-b ã
1
2-b- b
2-4 k t
+
b ã
1
2-b+ b
2-4 k t
+ ã
1
2-b- b
2-4 k t
b2
- 4 k + ã
1
2-b+ b
2-4 k t
b2
- 4 k >>
Set up a function to plot the result, here setting k=1 so the undamped frequency is 1,
and keeping the damping constant as a variable. Note the construction with two "/." in turn ("use the
assignment res1, and, within that, make the assignments to b and k").