Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
Chapter 9 Solving Second order differential equations numerically, 2 Online lecture materials โขThe online lecture notes by Dr. Tai-Ran Hsu of San José State University, http://www.engr.sjsu.edu/trhsu/Chapt er%204%20Second%20order%20DEs.p df provides a very clear explanation of the solutions and applications of some typical second order differential equations. DSolve โขDSolve of Mathematica can provide analytical solution to a generic second order differential equation. See Math_built_in_2ODE.nb. Typical second order, non-homogeneous ordinary differential equations n(x) Typical second order, non-homogeneous ordinary differential equations n(x) Guess: After some algebra Simple Harmonic pendulum as a special case of second order DE Force on the pendulum for small oscillation, Equation of motion (EoM) ๐น๐ = ๐๐๐ ๐๐ฃ๐ โ๐๐๐ ๐๐๐=๐ ๐๐ก = ๐ ๐๐ ๐ ๐๐ก ๐๐ก l โ ๐2 ๐ 2 ๐๐ก ๐2 ๐ ๐๐ โโ 2 ๐๐ก ๐ n(x) ๐๐ r The period of the SHO is given by l T ๏ฝ 2๏ฐ g Simple Harmonic pendulum as a special case of second order DE (cont.) n(x) ๐ฅโก๐ก ๐ข ๐ฅ โก ๐(t) ๐โก0 ๐ ๐โก ๐ ๐(๐ฅ) โก 0 ๐ 2 ๐(๐ก) ๐๐ =โ 2 ๐๐ก ๐ Simple Harmonic pendulum as a special case of second order DE (cont.) ๐ 2 ๐(๐ก) ๐๐ =โ 2 ๐๐ก ๐ Analytical solution: ฮฉ = ๐/๐ natural frequency of the pendulum; ๐0 and ๐ are constant determined by boundary conditions Simple Harmonic pendulum with drag force as a special case of second order DE Drag force on a moving object, fd = - kv For a pendulum, instantaneous velocity v = wl = l (dq/dt) Hence, fd = - kl (dq/dt). l The net force on the forced pendulum along the tangential direction - kl (dq/dt). dq dq ๏ป ๏ญmgq ๏ญ kl ; dt dt d 2r d2 d 2q m 2 ๏ป m 2 ๏จ lq ๏ฉ ๏ฝ ml 2 ; d t dt dt d 2r d 2q g k dq g dq k Fq ๏ฝ m 2 ๏ฎ 2 ๏ฝ ๏ญ q ๏ญ ๏บ ๏ญ q ๏ญq ;q ๏ฝ l m dt l dt m d t dt Fq ๏ฝ ๏ญmg sin q ๏ญ kl fd r Simple Harmonic pendulum with drag force as a special case of second order DE (cont.) n(x) ๐ฅโก๐ก ๐ข ๐ฅ โก ๐(t) ๐โก๐ ๐ ๐โก ๐ ๐(๐ฅ) โก 0 l fd r d 2q dt 2 g dq k ๏ฝ ๏ญ q ๏ญq ;q ๏ฝ l dt m Analytical solution Underdamped regime (small damping). Still oscillate, but amplitude decay slowly over many period before dying totally. q ๏จ t ๏ฉ ๏ฝ q0 e๏ญqt /2 sin ๏ฆ๏ง ๏ช ๏ซ t ๏2 ๏ญ q 2 ๏ถ๏ท ๏ง ๏จ ๏๏ฝ 4 ๏ท ๏ธ g the natural frequency of the system l Overdamped regime (very large damping), decay slowly over several period before dying totally. q is dominated 2 ๏ฆ qt ๏ถ q by exponential term. 2 ๏ญ๏ง ๏ฑ t ๏ญ๏ ๏ท q ๏จ t ๏ฉ ๏ฝ q0 e ๏ง 2 ๏จ 4 ๏ท ๏ธ Critically damped regime, intermediate between under- and overdamping case. q ๏จ t ๏ฉ ๏ฝ ๏จq 0 ๏ซ Ct ๏ฉ e ๏ญ qt 2 Critically damped Overdamped q ๏จ t ๏ฉ ๏ฝ q0 q ๏จ t ๏ฉ ๏ฝ ๏จq 0 ๏ซ Ct ๏ฉ e ๏ฆ qt ๏ถ q2 2 ๏ท ๏ง ๏ญ ๏ฑt ๏ญ๏ ๏ง 2 ๏ท 4 ๏จ ๏ธ e ๏ญ qt 2 Underdamped 0.2 q ๏จ t ๏ฉ ๏ฝ q0 e ๏ญ qt /2 ๏ฆ q2 2 sin ๏ง ๏ช ๏ซ t ๏ ๏ญ ๏ง 4 ๏จ 0.1 2 0.1 0.2 4 6 8 10 ๏ถ ๏ท ๏ท ๏ธ See 2ODE_Pendulum.nb where DSolve solves the three cases of a damped pendulum analytically. Adding driving force to the damped oscillator: forced oscillator - kl (dq/dt) + FD sin(๏Dt) ๏D frequency of the applied force dq dq Fq ๏ฝ ๏ญmg sin q ๏ญ kl ๏ซ FD sin ๏จ ๏ D t ๏ฉ ๏ป ๏ญmgq ๏ญ kl ๏ซ FD sin ๏จ ๏ D t ๏ฉ ; dt dt d 2r d2 d 2q Fq ๏ฝ m 2 ๏ป m 2 ๏จ lq ๏ฉ ๏ฝ ml 2 ; d t dt dt d 2r d 2q dq Fq ๏ฝ m 2 ๏ฝ ml 2 ๏ป ๏ญmgq ๏ญ kl ๏ซ FD sin ๏จ ๏ D t ๏ฉ dt d t dt d 2q g dq FD sin ๏จ ๏ D t ๏ฉ k ๏ป ๏ญ q ๏ญq ๏ซ ;q ๏ฝ 2 l dt ml m dt Analytical solution q ๏จ t ๏ฉ ๏ฝ q 0 sin ๏จ ๏ D t ๏ซ ๏ฆ ๏ฉ q0 ๏ฝ FD / (ml ) ๏จ๏ 2 ๏ญ ๏ 2D ๏ฉ ๏ซ ๏จ q๏ ๏ฉ 2 2 D Resonance happens when ๏ D ๏ฝ ๏ ๏ฝ g / l Forced oscillator: An example of non homogeneous 2nd order DE n(x) ๐ฅโก๐ก ๐ข ๐ฅ โก ๐(t) ๐โก๐ ๐ ๐โก ๐ ๐น๐ท sin ๐บ๐ท ๐ก ๐ ๐ฅ โก ๐๐ d 2q dt 2 g dq FD sin ๏จ ๏ D t ๏ฉ ๏ฝ ๏ญ q ๏ญq ๏ซ l dt ml Exercise: Forced oscillator d 2q dt 2 g dq FD sin ๏จ ๏ D t ๏ฉ ๏ฝ ๏ญ q ๏ญq ๏ซ l dt ml Use DSolve to solve the forced oscillator. Plot on the same graph the analytical solutions of q(t) for t from 0 to 10 T , where T= 2๏ฐ/๐บ, ๐บ = ๐/๐, for ๐บ๐ท = 0.01๐บ, 0.5๐บ, 0.99๐บ, 1.5๐บ, 4๐บ. Assume the boundary conditions q(t=0)=0; dq/dt(t=0)=0; m=l=FD=1; q=0. See forced_Pendulum.nb. Second order Runge-Kutta (RK2) method Consider a generic second order differential equation. d u ๏จ x๏ฉ 2 dx 2 ๏ฝ G ๏จu ๏ฉ It can be numerically solved using second order Runge-Kutta method. First, split the second order DE into two first order parts: v ๏จ x๏ฉ ๏ฝ du ๏จ x ๏ฉ dv ๏จ x ๏ฉ dx dx ๏ฝ G ๏จu ๏ฉ Algorithm Set boundary conditions: u(x=x0)=u0, uโ(x=x0)=v(x=x0)=v0. calculate calculate 1 u ๏ฝ ui ๏ซ vi ๏x 2 1 v ๏ฝ vi ๏ซ G (u )๏x 2 calculate ui ๏ซ1 ๏ฝ ui ๏ซ v ๏x calculate vi ๏ซ1 ๏ฝ vi ๏ซ G ๏จ u ๏ฉ ๏x Translating the SK2 algorithm into the case of simple pendulum 2 2 g d u ๏จ x๏ฉ dx ๏ฝ G ๏จu ๏ฉ 2 v ๏จ x๏ฉ ๏ฝ dv ๏จ x ๏ฉ G ๏จ u ๏ฉ ๏บ ๏ญ q (t ) l du ๏จ x ๏ฉ dx ๏ฝ G ๏จu ๏ฉ dx Set boundary conditions: u(x=x0)=u0, uโ(x=x0)=v(x=x0)=v0 1 u ๏ฝ ui ๏ซ vi ๏x 2 1 v ๏ฝ vi ๏ซ G (u )๏x 2 ui ๏ซ1 ๏ฝ ui ๏ซ v ๏x vi ๏ซ1 ๏ฝ vi ๏ซ G ๏จ u ๏ฉ ๏x ๐ ๐(๐ก) ๐๐ =โ 2 ๐๐ก ๐ w (t ) ๏ฝ dw ๏จt ๏ฉ dq ๏จ t ๏ฉ dt ๏ฝ๏ญ gq ๏จ t ๏ฉ dt l Set boundary conditions: q(t=t0)= q0, qโ (t=t0)=w(t=t0)=w0 1 2 1 ๏ฆ gq w ๏ฝ wi ๏ซ ๏ง๏ง ๏ญ 2๏จ l q ๏ฝ qi ๏ซ wi ๏t ๏ถ ๏ท๏ท ๏t ๏ธ qi ๏ซ1 ๏ฝ qi ๏ซ w๏t wi ๏ซ1 ๏ฆ gq ๏ฝ wi ๏ซ ๏ง๏ง ๏ญ ๏จ l ๏ถ ๏ท๏ท ๏t ๏ธ Exercise: Develop a code to implement SK2 for the case of the simple pendulum. g w 0 ๏ฝ ;q ๏จ 0 ๏ฉ ๏ฝ 0 ๏จ ๏ฉ Boundary conditions: l See pendulum_RK2.nb Translating the SK2 algorithm into the case of damped pendulum 2 ๐ 2 ๐(๐ก) ๐๐ d u ๏จ x๏ฉ dx 2 v ๏จ x๏ฉ ๏ฝ dv ๏จ x ๏ฉ ๏ฝ G ๏จu ๏ฉ ๐๐ก 2 du ๏จ x ๏ฉ w (t ) ๏ฝ ๐๐ =โ โ๐ ๐ ๐๐ก dq ๏จ t ๏ฉ dt dw ๏จ t ๏ฉ gq ๏ฝ๏ญ ๏ญ qw ๏จ t ๏ฉ dt l dx g ๏ฝ G ๏จ u ๏ฉ G ๏จ u ๏ฉ ๏บ ๏ญ q (t ) ๏ญ qw (t ) l dx Set boundary conditions: Set boundary conditions: u(x=x0)=u0, uโ(x=x0)=v(x=x0)=v0 q(t=t0)= q0, qโ (t=t0)=w(t=t0)=w0 1 1 q ๏ฝ qi ๏ซ wi ๏t u ๏ฝ ui ๏ซ vi ๏x 2 2 g ๏ฆ ๏ถ w ๏ญ q ( t ) ๏ t ๏ง i 2l ๏ท 1 1๏ฆ g ๏ถ ๏จ ๏ธ v ๏ฝ vi ๏ซ G (u )๏x w ๏ฝ wi ๏ซ ๏ง ๏ญ q (t ) ๏ญ qw ๏ท ๏t ๏ w ๏ฝ 2 2๏จ l ๏ฆ 1 ๏ถ ๏ธ 1 ๏ซ q ๏ t ๏ง 2 ๏ท ๏จ ๏ธ ui ๏ซ1 ๏ฝ ui ๏ซ v ๏x qi ๏ซ1 ๏ฝ qi ๏ซ w๏t vi ๏ซ1 ๏ฝ vi ๏ซ G ๏จ u ๏ฉ ๏x wi ๏ซ1 ๏ฆ gq ๏ถ ๏ฝ wi ๏ซ ๏ง๏ง ๏ญ ๏ญ qw ๏ท๏ท ๏t l ๏จ ๏ธ Exercise: Develop a code to implement SK2 for the case of a pendulum experiencing a drag force, with damping coefficient q= 0.1* (4๏), ๏๏ฝ ๐/๐, ๐ = 1.0 m. Boundary conditions: ฮธ 0 = 0.2; ๐ ๐ก = 0 = 0; d 2q dt 2 g dq ๏ฝ ๏ญ q ๏ญq l dt See pendulum_RK2.nb Exercise: Develop a code to implement SK2 for the case of a forced pendulum experiencing no drag force but a driving force๐น๐ท sin ๐บ๐ท ๐ก , ๏๏ฝ ๐/๐, ๐ = 1.0 m, m=1kg; ๐นD = 1N; ฮฉD =0.99 ๏; Boundary conditions: ฮธ 0 = 0.0; ๐ ๐ก = 0 = 0; d q 2 dt 2 g dq FD sin ๏จ ๏ D t ๏ฉ ๏ฝ ๏ญ q ๏ญq ๏ซ l dt ml Exercise: Stability of the total energy a SHO in RK2. ๐= ๐๐ , ๐๐ก angular velocity. M=1kg; l=1m. User your RK2 code to track the total energy for t running g w 0 ๏ฝ ;q ๏จ 0 ๏ฉ ๏ฝ 0 from t=0 till t=25T; T= ๐/๐. Boundary conditions: ๏จ ๏ฉ l ๐ธ๐ should remain constant throughout all ๐ก๐ . Exercise: Develop a RK2 code for planetary motion in polar y coordinates E S q O ๐ฟ ๐๐ โ ๐๐ ๐๐ 2 where 2 ๐บ๐๐ ๐๐ 2 ๐ = ๐ฟ =โ 2 ๐ ๐2๐ ๐๐ ๐ = 2 ;๐ = ๐๐ก ๐๐ก x Velocity verlet algorithm for solving the Newton second law Newtonโs second law โขGiven a position-dependent force acting on a particle, F(r), Newton second law determines the acceleration of a particle, a. d2r/dt2= F(r)/m โขThis is a second order differential equation. โขGiven F(r), we wish to know what are the subsequent evolution of r(t), v(t) beginning from the boundary values of r(0), v(0). โขPreviously we solve the second order DE using RK2 to obtain r(t), v(t). Verlet algorithms โขThe equation d2r/dt2=F(r)/m can be integrated to obtain r(t), v(t), via a numerical scheme: Verlet algoritm โขThree types: ordinary Verlet, velocity Verlet, leap frog verlet. โขIn the following, we shall denote the RHS as F(r)/m โ a So that d2r/dt2=F(r)/m โ d2r/dt2= a โขSee http://en.wikipedia.org/wiki/Verlet_integration Velocity Verlet algorithm Global error in velocity Verlet algorithm โขThe global (cumulative) error in x over a constant interval of time is given by ฮ๐ฅ ~ O(ฮt2) โขBecause the velocity is determined in a noncumulative way from the positions in the Verlet integrator, the global error in velocity is also ฮv ~ O(ฮt2) Exercise: SHO โขSolve for x(t), v(t), for a simple harmonic oscillator with constant k, mass m, initial displacement x0, and velocity v0 =0, using velocity Verlet algorithm. โขFor SHO, F = -kx โ a = -(k/m)x d2x/dt2 = -(k/m)x See verlet_algorithm_samples.nb Exercise: 2D free-fall projectile โขSolve for x(t), y(t), v(t) of a 2D free-fall projectile with initial speed v0=0 and launching angle q0 using velocity Verlet algorithm. โขFor 2D projectile motion, ๐ญ = โ๐๐๐ฆ + 0๐ฅ. a = ๐ญ/m ax๐ฅ + ay๐ฆ = 0๐ฅ โ ๐๐ฆ d2x/dt2๐ฅ+ d2y/dt2๐ฅ= โ๐๐ฆ โ d2x/dt2 = 0, d2y/dt2 = โ๐ See verlet_algorithm_samples.nb Exercise: Scattering of a projectile charge via Coulomb force F=F๐ = ๐๐๐ ๐ 2 2 (๐ฅโ๐ฅ๐ ) +(๐ฆโ๐ฆ๐ ) = ๐๐๐ ๐ 2 ๐ q ๐๐ = (๐ฅ, ๐ฆ) ๐ฆ (projectile, with mass m) R=(rq โ rQ)=R๐, ๐ = ๐qโ๐๐ ๐qโ๐๐ Q(Fixed) ๐๐ = ๐ฅ๐, ๐ฆ๐ rQ o ๐ฅ Notation for scattering of a projectile charge via Coulomb force โข ๐๐ = ๐ฅ๐, ๐ฆ๐ ; ๐q = (๐ฅ, ๐ฆ) โข๐ญ = ๐๐ ๐ ๐; 2 2 (๐ฅโ๐ฅ๐ ) +(๐ฆโ๐ฆ๐ ) โขโ โข ๐๐ฆ = โข ๐๐ฅ = 1 ๐ญโ๐ฆ ๐ 1 ๐ญโ๐ฅ ๐ = = ๐q โ ๐๐ ๐= ๐q โ ๐๐ ๐ ๐๐ ๐ ๐ (๐ฅโ๐ฅ๐ )2 +(๐ฆโ๐ฆ๐ )2 ๐ ๐๐ ๐ 2 2 ๐ (๐ฅโ๐ฅ๐ ) +(๐ฆโ๐ฆ๐ ) โ๐ฆ = โ๐ฅ= ๐2๐ฆ , ๐๐ก 2 ๐2๐ฅ . 2 ๐๐ก The equations required by Verlet algorithm โข ๐๐ = ๐ฅ๐, ๐ฆ๐ ; ๐q = (๐ฅ, ๐ฆ) ๐2 ๐ฆ ๐๐ก 2 = ๐q โ ๐๐ ๐= ๐q โ ๐๐ ๐๐๐ ๐โ๐ฆ , 2 2 ๐ (๐ฅโ๐ฅ๐ ) +(๐ฆโ๐ฆ๐ ) ๐2 ๐ฅ ๐๐๐ ๐โ๐ฅ = 2 ๐๐ก ๐ (๐ฅ โ ๐ฅ๐ )2 +(๐ฆ โ ๐ฆ๐ )2 See verlet_algorithm_2D_coulomb_scatterings.nb Störmer-Verlet integration algorithm ๐ฅ๐+1 = 2๐ฅ๐ โ ๐ฅ๐โ1 + ๐๐ โ๐ก 2 ๐ฃ๐+1 = (๐ฅ๐+1 โ๐ฅ๐ )/โ๐ก โข Another variant of Verlet algoritm โข Use this for integrating dynamical system with a velocity-dependent acceleration, such as Lorentz force on a moving charge particle. โข The cumulative error in the velocity is larger than that in velocity Verlet algorithm Exercise: Charge moving in a magnetic field โข A charge (mass m and charge q) moving with velocity v =(vx, vy , vz) in a magnetic field B=(Bx, By , Bz) experiences a velocity-dependent Lorentz force F=(Fx, Fy , Fz) = q v × B. Develop a code based on the Störmer-Verlet integration algorithm to simulate the dynamical path of the charge particle moving through the magnetic field. Assume: q=+1 unit, mass m = 1 unit, initially located at (0,0,0), initial velocity (v0x,v0y, v0z), v0x=v0y=0.1 unit, v0z =0.05 unit, B=(0, 0, Bz), Bz = 0.1 unit. You should see a helical trajectory circulating about the z-direction. โข verlet_algorithm_3D_coulomb_helix.nb