Phys102-Lecture06-11-10Fall-DiffEquations.pptx

advertisement
From 1 to
3.2…




For range 0-1,
converges to 0.
For range 1 to ~3,
convergence.
From ~3 to 3.2 the
iteration oscillates
between 2 values.
What happens in
the range 3.2 - 4?
1
Logistic Map Discussion

As the parameter r is increased
in the interval 3 < r <
3.5699456…



Fixed points obey the equation
x= f(m)(x)


there is “period doubling”
“pitchfork bifurcations” increase
the number of m-cycle periods by
a factor of 2 at each bifurcation.
f(m)(x) = f(f(f(…f(x)…))), m-times
Each branch of the bifurcation
diagram is a fractal.

Self-similarity at all magnification
scales.
2
Cobweb diagram:

For each starting point, find the
y value.


Project back to the diagonal line



Calculate r x(1-x)
Set the y value to be the new x
value.
Repeat.
Stable fixed points: inward
spiral.

Unstable: outward spiral.
3
Logistic Map, Cobweb diagram

Period 2 orbit


Period n orbit:


more complex closed loop.
Chaotic behavior:



diagram converges to a
rectangle.
Cobweb diagram “fills out” the
entire area.
Infinitely many non-repeating
values.
For the r = 4 case,



for almost all initial conditions:
chaotic sequence.
Nevertheless, there exist an
infinite number of initial
conditions which lead to
cycles.
There exist cycles of length k
for all integers k ≥ 1.
4
Logistic map: scatterplots of the
iteration for r=4

Stretching-Folding of the space:


Produces an exponential divergence of the sequence of iterates!
Chaotic behavior and unpredictability.

Small error in initial conditions leads to (exponentially) large error in
future evolution of the system.
5
For more information

On the web:




Course at UCD:


http://en.wikipedia.org/wiki/Logistic_map
http://en.wikipedia.org/wiki/Julia_set
http://en.wikipedia.org/wiki/Fractal
Phy 30 (or Geo 30): Fractals, Chaos and
Complexity.
Further reading:


“Chaos and Fractals”, by Peitgen, Jurgens,
Saupe.
“The Fractal Geometry of Nature”, by
Mandelbrot.
6
Computational Lab in Physics:
Solving Differential Equations.
Steven Kornreich
www.beachlook.com
Frequently in Physics, we are faced with solving a differential equation. Finding
solutions analytically can be difficult. We can use numerical methods to give us a
good idea of the solution in many cases.
Today’s topic:
Solving Differential eqs.

Newton’s Law:

Maxwell’s Eqs:
d 2r
F =m 2
dt
r
,
e0

Gauss’s Law

No monopoles
Ñ × B = 0,

Faraday’s Law
Ñ´E =-

Ampere-Maxwell
Ñ ´ B = m0 J + m0e0

Pendulum:

Schrodinger Eq:
Ñ× E =
¶B
,
¶t
¶E
¶t
d 2q g
+ sin q = 0
2
l
dt
æ 2ö 2
¶y
i
= - ç ÷ Ñ y +V y
¶t
è 2m ø
8
Ordinary Differential Eqs.: 1-variable

Order of equation:


Linear equations:




each term has only 1st power of function and
derivatives
no 2nd or higher powers
no cross-terms
Homogeneous equations:


highest derivative
no function of the independent variable appears by
itself.
Physics, time evolution of a dynamical
system:


2nd order eqs:
need two initial conditions.
9
Simple and Driven Harmonic oscillator


SHO
2
d x(t )
m
 kx(t )  0
2
dt
Driven Harmonic
d 2 x(t )
Oscillator
m
 kx(t )  F0 cos t
2
dt
10
Euler Method: Simplest way

Approximate derivative:

Rewrite


y ( x0  h)  y ( x0 )
y '( x0 ) 
( x0  h)  x0
Taylor expansion up to linear
y( x0
term
 h)  y( x0 )  hy '( x0 )
If we know:
y(x0), h, y’(x0)
Local information

then we know y(x0+h)
Drawback:


Not very precise
Error propagation is an issue
11
Example: Solve xy’+y=0

Analytic
solution:
dy
= -y
dx
dy
dx
=
ò y ò x
ln y = -ln x + A
C
y=
x
x

Numerical
solution:
dy
y
=dx
x
y(x0 )
y(x0 + h) = y(x0 ) - h
x0
 Start from a point
x0, going up to xf,
and use step size h.
 Initial condition:
 y(0.1) = 10
12
Comparison of Numerical/Analytic
void 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<int>((xmax-xmin)/step);
const int maxPoints = 1000;
if (Nsteps>maxPoints) {
cout << "Need to declare array of larger size: " << Nsteps << endl;
return;
}
cout << "Nsteps " << Nsteps << endl;
double yVal[maxPoints];
double xVal[maxPoints];
xVal[0] = xmin;
yVal[0] = 10;
for (int i=0; i<Nsteps; ++i) {
xVal[i+1]=xVal[i]+step;
yVal[i+1]=yVal[i]-step*yVal[i]/xVal[i];
}
TGraph* numerical = new TGraph(Nsteps,xVal,yVal);
numerical->SetLineColor(2);
numerical->Draw("L");
return;
13
Harmonic oscillator solution


Transform 2nd order
eq. into two coupled
linear equations:
Solution, with initial
conditions


v(0)=0
x(0)=A
d 2 x(t)
m
+ kx(t) = 0
2
dt
dx
m = mv
dt
dv
m = -kx
dt
x(t) = Acos w t
v(t) = -w Asin w t
k
w=
m
14
Numerical Solution using Euler Method

Equations become:
dx
= v Þ Dx = vDt Þ x(t + Dt) = x(t) + Dt × v(t)
dt
dv
k
k
k
= - x Þ Dv = - xDt Þ v(t + Dt) = v(t) - Dt × x(t)
dt
m
m
m

Initial conditions:


x(0) = 1
v(0) = 0
15
ROOT macro for SHO with Simple
Euler
Set m=k=1 for simplicity.
void eulerExample2() {
TF1* analytic = new
TF1("analytic","sin(x+TMath::Pi()/2.0)",0.1,20);
analytic->SetNpx(1000);
TCanvas* euCnv2 = new TCanvas("euCnv2","SHOEuler",500,500);
analytic->Draw();
double tmin=0.0;
double tmax=20.0;
double step=0.01;
int Nsteps=static_cast<int>((tmax-tmin)/step);
const int maxPoints = 2001;
if (Nsteps>maxPoints) {
cout << "Need to declare array of larger size: "
<< Nsteps << endl;
return;
}
cout << "Nsteps " << Nsteps << endl;
double vVal[maxPoints];
double xVal[maxPoints];
double tVal[maxPoints];
tVal[0] = tmin;
xVal[0] = 1.0;
vVal[0] = 0.0;
for (int i=0; i<Nsteps; ++i) {
tVal[i+1]=tVal[i]+step;
xVal[i+1]=xVal[i]+step*vVal[i];
vVal[i+1]=vVal[i]-step*xVal[i];
}
TGraph* numericalX = new
TGraph(Nsteps,tVal,xVal);
numericalX->SetLineColor(2);
numericalX->Draw("L");
TGraph* numericalV = new
TGraph(Nsteps,tVal,vVal);
numericalV->SetLineColor(4);
numericalV->Draw("L");
return;
}
16
Result of Simple Euler Method for SHO

Analytic solution


Numerical solutions:



x(t)=sin(t+p/2) in
BLACK
x(t) in RED
v(t) in BLUE
Problem:

Amplitude of numerical
solution grows!
17
Spring is gaining energy?!

As particle propagates from say, x=0 to x=1:




Force is evaluated at x(ti)
Average displacement of spring during propagation:
x(ti+Dt/2).
Velocity value, v(ti)used is larger than average
velocity 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 overestimated…
Cycle repeats.
x(ti+Dt/2)
xi
xi+1
x
18
Modified Euler Method 1: Midpoint

Simple Euler:

derivative at the beginning of interval
y( x0  h)  y( x0 )  hy '( x0 )

Modified Euler

derivative at the midpoint of interval
h
y ( x0  h)  y ( x0 )  hy '( x0  )
2

For first problem:
dy
y

dx
x
h
h
y ( x0  )  y ( x0 )  y '( x0 )
2
2
y ( x0  h / 2)
y ( x0  h)  y ( x0 )  h
x0  h / 2
19
Modified Euler Method 2: Make the two
errors “cancel” (to first order) in SHO.

Original:
dx
 v  Dx  vDt  x(t  Dt )  x(t )  Dt  v(t )
dt
dv
  x  Dv   xDt  v(t  Dt )  v(t )  Dt  x(t )
dt

Modified: calculate v(t+Dt) first:
dv
  x  Dv   xDt  v(t  Dt )  v(t )  Dt  x (t )
dt
dx
 v  Dx  vDt  x(t  Dt )  x(t )  Dt  v(t  Dt )
dt
20
Simple vs Modified Euler: 1/x

Much better agreement with Modified Euler Method.
21
Modified Euler Method 1 for SHO


Need to first calculate x and v at
midpoint.
Use midpoint values to find x and v
at end of interval t+Dt.
Dt
 Dt 
vmid  v  t    v(t )  x(t )
2 
2

Dt
 Dt 
xmid  x  t    x(t )  v(t )
2 
2

x(t  Dt )  x(t )  Dt  vmid
v(t  Dt )  v(t )  Dt  xmid
22
Simple vs Modified Euler: SHO

Works better!
23
For smaller step size, can still have
problems…

With step size = 0.3, obvious
problems as t grows.
24
Homework 6: Differential Equations




From Chapter 8
Exercise 1
Exercise 2
Use the Modified Euler Method 2 to solve the SHO and show that this
also gives a solution that conserves energy


Show a plot where the amplitude doesn’t grow after 5 periods, compared
to the analytic solution (see plot in slide 23)
Extra Problem (Not in Book)




Solve the full pendulum equation of motion (no approximations), using the
modified Euler method 1 (midpoint).
Use initial angle = p/2, initial angular speed = 0. Take gravity = 9.81 m/s2
and l=1 m.
Make a plot of angle vs time.
In that same plot, compare the plot to the SHO of frequency g/l and
amplitude p/2 which starts at the same angle and same angular speed.
25
Download