Phys102 Lecture06!08!10Fall DiffEquations
-
Upload
benefit187 -
Category
Documents
-
view
222 -
download
0
Transcript of Phys102 Lecture06!08!10Fall DiffEquations
-
8/14/2019 Phys102 Lecture06!08!10Fall DiffEquations
1/20
Computational Lab in Physics:Solving Differential Equations.
Steven Kornreich www.beachlook.com
Frequently in Physics, we are faced with solving a differential equation. Findingsolutions analytically can be difficult. We can use numerical methods to give us agood idea of the solution in many cases.
-
8/14/2019 Phys102 Lecture06!08!10Fall DiffEquations
2/20
2
Logistic Map, Cobweb diagram
-
8/14/2019 Phys102 Lecture06!08!10Fall DiffEquations
3/20
3
Logistic Map Discussion
As the control parameter ris increased in the interval 3< r < 3.5699456
there is period doubling pitchfork bifurcations increase the number of m-cycle periods by a factor of 2at each bifurcation.
Fixed points obey theequation x= f (m) (x)
f (m) (x) = f(f(f(f(x)))), m-
times
-
8/14/2019 Phys102 Lecture06!08!10Fall DiffEquations
4/20
4
Examples of differential eqs.Newtons Law:
Maxwells Eqs:Gausss Law
No monopolesFaradays LawAmpere-Maxwell
Pendulum:
Schrodinger Eq:
d r F m
dt
E
B
B E
t E
B J t
d g dt l
i V
t m
r
r r
r r
r r
r r r
hh
-
8/14/2019 Phys102 Lecture06!08!10Fall DiffEquations
5/20
5
Ordinary Differential Eqs.: 1-variable
Order : highest derivativeLinear: each term has only 1 st power of function and derivatives
no 2 nd or higher powersno cross-terms
Homogeneous: no function of the
independent variable appears by itself.Physics: 2 nd order eqs: need two initialconditions.
-
8/14/2019 Phys102 Lecture06!08!10Fall DiffEquations
6/20
6
Simple and Driven Harmonic oscillator
SHO
Driven HarmonicOscillator
d x t m kx t
dt
d x t m kx t F t
dt
-
8/14/2019 Phys102 Lecture06!08!10Fall DiffEquations
7/20
-
8/14/2019 Phys102 Lecture06!08!10Fall DiffEquations
8/20
8
Example: xy+y=0
Analyticsolution:
dy x ydxdy dx y x
y x AC
y x
Numericalsolution:
Start from apoint x 0 , goingup to x f , and use
step size h .
dy ydx x
y x y x h y x h
x
-
8/14/2019 Phys102 Lecture06!08!10Fall DiffEquations
9/20
9
Comparison of Numerical/Analyticvoid eulerExample1() {
TF1* analytic = new TF1("analytic","1/x",0.1,5);analytic->SetNpx(1000);TCanvas* euCnv1 = new TCanvas("euCnv1","ODE",500,500);analytic->Draw();gPad->SetLogy();
double xmin=0.1;double xmax=5.0;double step=0.01;
int Nsteps=static_cast((xmax-xmin)/step);const int maxPoints = 1000;if (Nsteps>maxPoints) {
cout
-
8/14/2019 Phys102 Lecture06!08!10Fall DiffEquations
10/20
10
Harmonic oscillator solution
Transform 2 nd order eq.into two coupled linearequations:
Solution, with initialconditions
v(0)=0x(0)=A
Set m=k=1 forsimplicity.
d x t m kx t dt
dxm mv
dt
dvm kxdt
x t A t
v t A t k m
-
8/14/2019 Phys102 Lecture06!08!10Fall DiffEquations
11/20
11
Numerical Solution
Equations become:dx
v x v t dt dv
x v x
x t t x t t v t
v t t v t t t t dt
x
-
8/14/2019 Phys102 Lecture06!08!10Fall DiffEquations
12/20
12
ROOT macro for SHO with SimpleEuler
void eulerExample2() {TF1* analytic = new
TF1("analytic","sin(x+TMath::Pi()/2.0)",0.1,20);analytic->SetNpx(1000);TCanvas* euCnv2 = new TCanvas("euCnv2","SHO-
Euler",500,500);analytic->Draw();
double tmin=0.0;double tmax=20.0;double step=0.01;int Nsteps=static_cast((tmax-tmin)/step);const int maxPoints = 2001;if (Nsteps>maxPoints) {
cout
-
8/14/2019 Phys102 Lecture06!08!10Fall DiffEquations
13/20
13
Result of Simple Euler Method for SHO
Analytic solutionx(t)=sin(t+ /2) inBLACK
Numerical solutions:x(t) in RED
v(t) in BLUEProblem:Amplitude of numericalsolution grows!
-
8/14/2019 Phys102 Lecture06!08!10Fall DiffEquations
14/20
14
Spring is gaining energy?!As particle propagates from say, x=0 to x=1:
Force is evaluated at x(t i)Average displacement of spring during propagation:x(t i+ t/2).Velocity value used is also larger than averagevelocity over the displacement.
Result:restoring force is weaker than it should be.Acts on the particle a shorter amount of time.Displacement overshoots the true maximum.
When returning to zero, force is overestimatedCycle repeats.
xi xi+1
x(t i+ t/2)
x
-
8/14/2019 Phys102 Lecture06!08!10Fall DiffEquations
15/20
15
Modified Euler Method
Simple Euler:derivative at the beginning of interval
Modified Eulerderivative at the midpoint of interval
For first problem:
y x h y x hy xh
y x h y x hy x
dy ydx x
h h y x y x y x
y x h y x h y x h x h
-
8/14/2019 Phys102 Lecture06!08!10Fall DiffEquations
16/20
16
Simple vs Modified Euler: 1/x
Much better agreement with Modified Euler Method.
-
8/14/2019 Phys102 Lecture06!08!10Fall DiffEquations
17/20
17
Modified Euler Method for SHO
Need to calculate x and v atmidpoint .
t t v v t v t x t
t t x x t x t v t
x t t x t t vv t t v t t x
-
8/14/2019 Phys102 Lecture06!08!10Fall DiffEquations
18/20
18
Simple vs Modified Euler: SHO
Works better!
-
8/14/2019 Phys102 Lecture06!08!10Fall DiffEquations
19/20
19
For smaller step size, can still haveproblems
With step size = 0.3, obviousproblems as t grows.
-
8/14/2019 Phys102 Lecture06!08!10Fall DiffEquations
20/20
20
HomeworkFrom Chapter 15Exercise (5): Duffing Oscillator
Damped, nonlinear (pendulum at NLO), driven oscillator.Your program should make a plot of the resulting equation xvs t as well as the v vs x.
Use Modified Euler Method, (ignore the last sentence on page201)Instead of instructions in page 202, you can use a TGraph forthis, as in the examples shown in lecture.
Extra Problem (Not in Book)Solve the full pendulum equation of motion (noapproximations), using the modified Euler method.
Use initial angle = /2, initial angular speed = 0. Take gravity= 9.81 m/s 2 and l=1 m.Make a plot of angle vs time.In that same plot, compare the plot to the SHO of frequencyg/l and amplitude /2 which starts at the same angle andsame angular speed.