contentsetavernetti/ps22.pdfan concept related to the fact that the exponential function increases...

17
Professor Mohamed Hafez TA: Edward Tavernetti Contact: [email protected] Cluster 3 - Problem Set 2 with included notes July 20, 2010 Contents 1 First Order Problems 2 1.1 A first example: Polynomials ....................................... 2 1.2 Exponential and Logarithmic Growth .................................. 3 1.2.1 Non-Constant Coefficients ..................................... 4 1.2.2 Bernoulli Equation and reduction of order (Logistic Equation) ................ 4 2 Second Order Problems 5 2.1 Mass-Spring System (IVP) ........................................ 5 2.1.1 Classical Damped Mass Spring System .............................. 6 2.1.2 Pure resonance ........................................... 7 2.1.3 Beat Effect ............................................. 7 2.2 A Special Case of the Euler Cauchy Eq. ................................. 7 2.3 Van der Pol Oscillator ........................................... 8 2.4 Damped Pendulum ............................................. 8 2.5 Boundary Value Problems (BVP) ..................................... 9 2.5.1 Gaussian Elimination ....................................... 9 2.5.2 Jacobi Method ........................................... 10 2.5.3 Gauss-Seidel Method ........................................ 10 2.5.4 Successive-Over-Relaxation (SOR) ................................ 10 2.6 Special Topic: Series Solutions and Special Functions .......................... 11 2.6.1 Bessel Functions of the first kind (IVP) ............................. 11 2.6.2 Airy Functions (IVP) ....................................... 12 2.6.3 Legendre Polynomials (BVP) ................................... 12 3 A Fourth Order BVP - Bending of Beams 12 3.1 Fourth Order Discretization ........................................ 13 3.2 Solving as System of Second Order Equations .............................. 13 4 A Second Order Eigenvalue Problem 14 5 A Chaotic Third Order or ’Jerk’ Equation 16 1

Upload: others

Post on 05-Mar-2021

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Contentsetavernetti/ps22.pdfan concept related to the fact that the exponential function increases faster than any polynomial in the limit as x tends to in nity. Written another way,

Professor Mohamed HafezTA: Edward Tavernetti

Contact: [email protected] 3 - Problem Set 2 with included notes

July 20, 2010

Contents

1 First Order Problems 21.1 A first example: Polynomials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.2 Exponential and Logarithmic Growth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

1.2.1 Non-Constant Coefficients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.2.2 Bernoulli Equation and reduction of order (Logistic Equation) . . . . . . . . . . . . . . . . 4

2 Second Order Problems 52.1 Mass-Spring System (IVP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

2.1.1 Classical Damped Mass Spring System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.1.2 Pure resonance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.1.3 Beat Effect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

2.2 A Special Case of the Euler Cauchy Eq. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72.3 Van der Pol Oscillator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82.4 Damped Pendulum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82.5 Boundary Value Problems (BVP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

2.5.1 Gaussian Elimination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.5.2 Jacobi Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102.5.3 Gauss-Seidel Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102.5.4 Successive-Over-Relaxation (SOR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

2.6 Special Topic: Series Solutions and Special Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 112.6.1 Bessel Functions of the first kind (IVP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112.6.2 Airy Functions (IVP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122.6.3 Legendre Polynomials (BVP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

3 A Fourth Order BVP - Bending of Beams 123.1 Fourth Order Discretization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133.2 Solving as System of Second Order Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

4 A Second Order Eigenvalue Problem 14

5 A Chaotic Third Order or ’Jerk’ Equation 16

1

Page 2: Contentsetavernetti/ps22.pdfan concept related to the fact that the exponential function increases faster than any polynomial in the limit as x tends to in nity. Written another way,

Motivation

Two concepts we should become familiar with are integral and differential equations. These are complementaryformulations. In the integral formulation we have:∫ xi

−∞f(y)dx = yxi − y∞

Thus we can estimate (letting i correspond with xi in the above, e.g. yi → y(xi)):∫ i

−∞f(y)dx = yi − y∞ and

∫ i+1

−∞f(y)dx = yi+1 − y∞

Taking the difference of these we get the finite difference approximation:

∆xf(yi)− f(yi+1)

2= yi+1 − yi

In the differential formulation we have:dy

dx= f(y)

Discretizing this we get:yi+1 − yi

∆x=f(yi)− f(yi+1)

2In this problem set we will study differential equations (D.E.’s – generally divided into two classes: ODE,PDE).DE’s are very useful to us because very often this is the means by which we observe the world. Often a scientisttakes a measurement at several times and is able to write down an equation that approximately captures what hasbeen observed in several measurements. Such a function relates the state of what is measured at several differenttimes and so is a description of how it has changed. In practice this is how many differential equations come intoexistence. For a classic example, suppose a race car is accelerating off the line at the start of race. If we observe itat time = 0 sec. the car to be at 0 m., time = 6 sec. to be 100 m., ... , time = 12 sec. to be at 1000m, etc... whatis the best we say can say about the position of the car at at 15 sec.? Notice first that from this type of data wehave a position function of the form:

dp(t)dt

= f(t)

To go about using the data to make a projection about the position of the car based on the data we have collectedwe would need to integrate this differential equation, which is given as a rate of change in track position with time,with respect to time in order to get a position function in terms of the position with respect to time. That is wecompute: ∫

dp

dtdt = p(t) + c

We use given information about the initial conditions, namely the car started from the starting line position at sayp(0) = 0, to eliminate the constant term, in this case c = 0, and get a unique function p(t) that is an estimate of thecars position at any time t based on the known data (physically t ≥ 0 is what makes sense). This type of procedureis known as solving the differential equation. We will numerically solve several different types of examples. Therace car example above is an initial value problem. We will see other classes of differential equations below thatare fundamentally different (e.g. boundary value and eigenvalue problems).

1 First Order Problems

1.1 A first example: Polynomials

First we will consider a simple example to get a conceptual idea of what we are doing. Suppose We know that:

dy

dx= x

2

Page 3: Contentsetavernetti/ps22.pdfan concept related to the fact that the exponential function increases faster than any polynomial in the limit as x tends to in nity. Written another way,

What can we then say about y? Well, from only the most elementary understanding of integration theory we canrespond that infinitely many functions satisfy this differential equation and in fact:

y =x2

2

If we impose an additional requirement that, say for example: y(1) = 1, then we could further narrow our responseto a unique solution:

y =x2

2+

12

Now, generalizing this concept, for n = 1, 2, 3, ..., find a general solution to the problem:

xdy

dx= ny, s.t. y(1) = 1

Plot the solution for n = 1, 2, 3 and y = exp(x) for x = 1,1.1,....,8 on the same figure. This example illustratesan concept related to the fact that the exponential function increases faster than any polynomial in the limit as xtends to infinity. Written another way, for any n ≥ 0

limx→∞

xn1ex

= 0

1.2 Exponential and Logarithmic Growth

For exponential growth we will first study:dy

dt= y, y(0) = 1

This is the classic Intial Value Problem (IVP). We are given the rate of change dydt = y and an initial value y(0) = 1

and our goal is to find the function y(t) that satisfies the differential equation and boundary condition. First let’sdo this analytically:

dy

dx= y ⇒ dy

y= dx∫

dy

y=∫dx⇒ ln(y) = x+ c

⇒ y(x) = e(ln(y)) = ex+c = exec = kex

Use IC to find k :y(0) = 1⇒ k = 1⇒ y = ex

You can easily check this makes sense because the exponential function is its own derivative. Now, how do youdo this numerically? There are several known methods, we will use finite difference methods. First we dis-cretize the equation. We use the initial value to set the first grid points and then we iterate by approximatingthe function based on its derivative. The smaller the step size we use, the more accurate our approximation will be.

We will implement these methods:

(a) Forward Differenceyn+1 − yn

∆x= yn

(b)Backward Differenceyn − yn−1

∆x= yn

3

Page 4: Contentsetavernetti/ps22.pdfan concept related to the fact that the exponential function increases faster than any polynomial in the limit as x tends to in nity. Written another way,

(c) Trapezoidal Rule (2 point)

yn+1 − yn∆x

= 0.5(yn+1 + yn) or equivalently,yn − yn−1

∆x= 0.5(yn + yn−1)

(d) Central Difference (3 point) ← In this case this method is unstable!

yn+1 − yn−1

2∆x= yn

To implement these, just set y(0) = 1. Then solve for general formula relating y(n) in terms of y(n − 1). Useh = ∆x = 0.2 and solve from t = 0 to t = 2. When you get stuck think first what is y(0), then what is y(1),then is y(2), etc... For the last method you will need to set y(1) before you can apply the general formula foryn+1 = fnc(yn, yn−1). To do this just set y(1) to be the same value you used for y(1) in the forward differencemethod before you iterate.

Compute the absolute error and relative numerical error at each time value. These are given by the standardformulas:

τabsolute = |yexact − yapprox|

and:τrelative =

|yexact − yapprox||yexact|

Note that the local truncation is not defined wherever yexact = 0.

Next for an exponential decay problem we will can study:

dx

dy=

1y, x(1) = x1 = 0

You should discretize this and generate the solution numerically for h = 0.1 and from x1 = 1 to xn = 10. Whatis the analytic solution? Plot it against the analytic solution.

1.2.1 Non-Constant Coefficients

We have up until now only delt with so called constant coefficient problems. Now will see a non-constant coefficientproblem:

dy

dx= −2xy, y(0) = 1

Discretize this and solve it numerically. Check your plot against the analytic solution:

y = e−x2

1.2.2 Bernoulli Equation and reduction of order (Logistic Equation)

The Bernoulli equation is given by:dy

dx= p(x)y = g(x)ya

It is a non-linear, variable coefficient differential equation. It is linear if a = 0 or a = 1. If we set:

u(x) = [y(x)]1−a

Now, we will study here the class of logistic functions or logistic curves. These curves are sigmoid shaped curvesand were first studied in the 1840’s by Pierre Franois Verhulst who studied population growth. It can model the ”S-shaped” curve (abbreviated S-curve) of growth of some population P. The initial stage of growth is approximatelyexponential; then, as saturation begins, the growth slows, and at maturity, growth stops. The logistic function

4

Page 5: Contentsetavernetti/ps22.pdfan concept related to the fact that the exponential function increases faster than any polynomial in the limit as x tends to in nity. Written another way,

finds applications in a range of fields, including artificial neural networks, biology, biomathematics, demography,economics, chemistry, mathematical psychology, probability, sociology, political science, and statistics. One wayto give the model is by the Verhulst equation:

dy

dx= Ay −By2, A > 0, B > 0

This is equation is sometimes refered to as The logistic equation. Notice here that a = 2, and hence this isnon-linear. We seek non-trivial solutions to this problem (clearly y = 0 is always a solution). In general this woulddifficult; however, using the reduction of order technique, if we set u = 1

y , then we get a linear ODE:

u′ +Au = B

Here the solution is at once found by the well-known integrating factor method to be:

u(x) = ce−Ax +B

A

Thus setting y = 1/u we get

y =1

(B/A) + ce−Ax

Solve this equation numerically and plot the solution for the two cases: (1) y(0) > A/B, and (2) y(0) < A/B.

2 Second Order Problems

2.1 Mass-Spring System (IVP)

First recall Newton’s law:

md2y

∆t2= F (t)

where f denotes the sum of all forces acting on the objective mass. In a mass-spring system we want to considerthree forces: restoring, damping and external. We define these respectively as:

Frestoring = −kx, Fdamping = −c dy∆t

, Fexternal = f(t)

Taking these forces together in F (t) we get a governing equation for the mass-spring system:

md2y

∆t2+ c

dy

∆t+ ky = f(t)

It is a second order, constant coefficient, non-homogeneous linear differential equation. Physically, it really onlymakes sense to consider cases: m > 0, k > 0, b ≥ 0. Mathematically one can consider other parameter values,and you might find it rewarding to think about that. If f(t) = 0, the dynamics are unforced, we then say it ishomogeneous.

One solves this equation by finding:

y(t) = yhomogeneous + yparticular = yh + yp

First we set:

md2y

∆t2+ c

dy

∆t+ ky = 0

and find yh(t) depending on whether the characteristic equation has real unequal (overdamped), real repeated(critically damped), or imaginery (underdamped) roots. Then depending on the forcing function f(t) we use themethod of undetermined coefficients to find yp. It is several weeks worth of an undergraduate course in differentialequations to learn to do this. If you figure it out now you will be well ahead of the curve.

5

Page 6: Contentsetavernetti/ps22.pdfan concept related to the fact that the exponential function increases faster than any polynomial in the limit as x tends to in nity. Written another way,

2.1.1 Classical Damped Mass Spring System

First let’s first let f(t) = 10 cos(3t), m = 1, c = 4, and k = 5 to get a differential equation of the form:

d2y

∆t2+ 4

dy

∆t+ 5y = 10 cos(3t)

subject to the initial conditions:

y(0) = 0,dy(0)

∆t= 0.

Use h = ∆t = 0.1 and solve out to time t = 2. To check your answers the true solution is given by:

y(t) = e−2t

(14

cos(t)− 74

sin(t))− 1

4cos(3t) +

34

sin(3t)

We will implement finite difference methods to numerically solve this initial value problem. To solve the generalequation we can descretize the system as follows:

(a)

myn+1 − 2yn + yn−1

∆t2+ c

yn+1 − yn−1

2∆t+ kyn = f(tn)

(b)

myn+1 − 2yn + yn−1

∆t2+ c

yn+1 − yn−1

2∆t+ k

yn+1 − yn−1

2∆t= f(tn)

(c)

myn+1 − 2yn + yn−1

∆t2+ c

yn+1 − yn−1

2∆t+ k

yn+1 + 2yn + yn−1

4= f(tn)

Find the general formula for: yn+1 = fnc(yn, yn−1). Notice y0 is given. To find y1 use from the initial conditionthat:

y1 − y−1

2∆t= 0

in the general formula for yn+1 to solve for y1 = fnc(y0, y−1) and use this relation to write y1 = fnc(y0) only. Youshould get something like:

y1 =10 cos(3t0)

2/(∆t)2

We can also reduce the order by rewriting the differential equation as a system of first order equations:

y′ = v; mv′ + cv + ky = f(t)

Discretizing this system we get:yn+1 − yn

∆t=vn+1 + vn

2; m

vn+1 − vn∆t

+ cvn+1 + vn

2+ k

yn+1 − yn2

= sin(ωntn)

We will implement this subject to initial conditions:

y(0) = 0,dy(0)

∆t= v0 = 0

How do we implement this? Again notice:y1 − y−1

2∆t= v0 = 0⇒ y1 = y−1

We will then use this to solve for y1. Take careful note of how we used the boundary condition to handle findingy1. This procedure is very important to understand.

Above is a classical damped mass-spring system. Several other interesting examples are available. The caseof beats and pure resonance are of particular interest.

6

Page 7: Contentsetavernetti/ps22.pdfan concept related to the fact that the exponential function increases faster than any polynomial in the limit as x tends to in nity. Written another way,

2.1.2 Pure resonance

In the case of pure resonance we have the natural frequency of the system matching the forcing frequency ofthe forcing function. In this case oscillations in the solutions are self-reinforcing and the solution always growsin amplitude with time (until, as occurs in the natural world, they become unsustainable). An example of thisphenomenon is:

d2y

∆t2+ y = 2 cos(t), y(0) = 0,

dy(0)∆t

= 0

Here, discretize this equation as above and numerically solve it. Use h = 0.5 and numerically solve to t = 10. Tocheck your answer use:

y(t) = c1 cos(t) + c2 sin(t) + t sin(t) = t sin(t) c1 = c2 = 0 from the initial conditions

2.1.3 Beat Effect

The case of beats is related to the phenomenon of the solution reinforcing itself and diminishing itself periodically.The regularity, or periodicity, of this phenomenon is what makes it special. Here we will consider:

d2y

∆t2+ 484π2y = cos(20πt), y(0) = 0,

dy(0)∆t

= 0

Next discretize this equation as above and numerically solve it. Use h = 0.005 and numerically solve to t = 1(this will take alot of rows!). Experiment with how much accuracy you lose with a large step size. To check youranswer use:

y(t) =2

(22π)2 − (20π)2sin(0.5(22π − 20π)t) sin(0.5(22π + 20π)t)

Note that because of the highly oscillatory nature of this problem that a very fine discretization is required toget accurate results. This is a common and important problem that often needs to be dealt with computer aidedmathematics.

2.2 A Special Case of the Euler Cauchy Eq.

The second order Euler Cauchy equation appears in a number of applications, and is related to solving Laplace’sequation in polar coordinates. In general this refers to a linear homogeneous ordinary differential equation withvariable coefficients of order n:

fn(x)dyn

dxn+ ...+ f1(x)

dy

dx+ y0f0(x) = 0

We will consider a special case where:

x2 dy2

dx2+ ax

dy

dx+ by = 0

This is a homogeneous ODE. Here we want to pay careful attention to the root structure and how that affectsthe solution. We will study solutions for three cases where we have: (1) Two distinct roots, (2) One real repeatedroot, (3) Complex roots, depending on our choice of parameters.

(1) Two distinct roots (m1,m2)

x2 dy2

dx2− 5

2xdy

dx− 2y = 0

Here the analytic solution is given by:

y(x) = c1xm1 + c2x

m2

(2) One real repeated root

x2 dy2

dx2− 3x

dy

dx+ 4y = 0

7

Page 8: Contentsetavernetti/ps22.pdfan concept related to the fact that the exponential function increases faster than any polynomial in the limit as x tends to in nity. Written another way,

Here the analytic solution is given by:

y(x) = (c1 + c2 ln(x))x(1−a)/2

(3) Complex Conjugate roots (m1 = µ+ iν,m2 = µ− iν)

x2 dy2

dx2+ 7x

dy

dx+ 13y = 0

Here the analytic solution is given by:

y(x) = xµ [A cos(ν ln(x) +B sin(ν ln(x)]

In addition we also want to consider a non-homogeneous case:

x2 dy2

dx2− 4x

dy

dx+ 6y = −7x4 sin(x)

Here the analytic solution is given by:

y(x) = c1x2 + c2x

3 + 7x2 sin(x)

For each of the above problems try using y(1) = 1, dy(1)dx = 1 and solve the equations numerically. You can find c1

and c2 from the solutions and these initial conditions in order to compare your result with the true solution.

2.3 Van der Pol Oscillator

The Van der Pol oscillator is a non-conservative oscillator with non-linear damping. It evolves in time accordingto the second order differential equation:

d2y

dx2− µ(1− y2)

dy

dx+ y = 0

Try using µ = 1.5. Discretize this equation and solve it numerical subject to y(0) = 2 and dy(0)dx = 0.

There is nice software available for this type of calculation. Try downloading pplane7 and using it in MATLABto generate a figure similar to this one.

2.4 Damped Pendulum

The damped pendulum is a classical and very intuitive problem:

d2θ

dt2− cdθ

dt+ k sin θ = 0, k ≥ 0, c ≥ 0

Discretize this equation and solve it numerical subject to θ(0) = π/4 and dy(0)dx = 0. Play with changing the initial

angle and plotting the solution. Can you have initial conditions for which the pendulum might remain stationaryfor all future times? Choosing c = .2, k = 1 I you should get curves that are trajectories in this plot showing manytrajectories of the general solution:

8

Page 9: Contentsetavernetti/ps22.pdfan concept related to the fact that the exponential function increases faster than any polynomial in the limit as x tends to in nity. Written another way,

2.5 Boundary Value Problems (BVP)

We will again solve the same differential equation as we say in the mass-spring system:

md2y

∆x2+ c

dy

∆x+ ky = 0

this time in the reduced form:

md2y

dx2− y = f(x)

What will change is nature of the known data. With Boundary Value Problems (BVP) we are given boundaryinformation. For example we might be given:

y(a) = α, y(b) = β

and we seek to find an equation that satisfies these boundary conditions and the differential equation. For ourpurposes we will let f(t) = 1 and let us set the boundary conditions as:

y(0) = cosh(0)− 1 = 0, y(1) = cosh(1)− 1 =e+ e−1

2− 1

The true solution is:y(x) = cosh(x)− 1

We will solve this BVP by four different methods: Direct Solve by Gaussian Elimination, Jacobi Method, Gauss-Seidel Method, and Successive-Over-Relaxation (SOR). In each case we are going to set the problem up as:

Ay = d

Our goal is to solve for y. Keep in mind that if knew A−1 we would be done, since the solution we seek is y, andy = A−1Ay = A−1d. So each of these methods really boil down to finding or approximating A−1. As before ourfirst step is to discretize the equation:

yn+1 − 2yn + yn−1

∆x2− yn = 1

2.5.1 Gaussian Elimination

We will implement a simple version (n = 3 = dim(A)) of this method by hand in Excel. Afterward, there is amore involved algorithm that you can play with in MATLAB. The first step is to recast our problem as:

Ay = d

9

Page 10: Contentsetavernetti/ps22.pdfan concept related to the fact that the exponential function increases faster than any polynomial in the limit as x tends to in nity. Written another way,

We will index our vector in y for programming purposes as y(1),y(2),y(3), where y(1) = y(x(0)) = 0, y(2) =y(x(1)) = 1/2, y(3) = y(x(3)) = 1. We know y(1),y(3), from the boundary conditions. So really all we need tofind is y(2). Write down the system in matrix form. You should have something like this: 1 0 0

1dx2 ... ...... ... ...

y(1)y(2)y(3)

=

0......

Fill in the blanks. Solve the resulting system of linear equations directly for y(2). Plot your answer against thetrue solution. When you have done this there is a MATLAB code in the solutions that you can compare with andrun.

2.5.2 Jacobi Method

First we will implement the Jacobi Method. Once this is working, it only requires a small modification to getGauss-Seidel and SOR working.

This is an iterative process. Let k denote the iteration number. Now we will solve for:

yk+1(i) = fnc(yk(i− 1), yk(i), yk(i+ 1), f(x(i)))

Jacobi’s Method (for solving Ax = b):Guess any y0, but fix: y0(0) = 0y0(1) = 0Iteration Step:

for i = 2:length(y)-1ynewk(i+ 1) = fnc(yk(i− 1), yk(i), yk(i+ 1), f(x(i)))

endSet: y = ynewCheck the residual:

residual = max(|y”+y - f(x)|)If residual <= TOL then Stop Proceduce else repeat Iteration Step

2.5.3 Gauss-Seidel Method

The only difference now for the Gauss-Seidel Method is that we will not lagg the values of y. This is what they, ynew variables do. This time we will use updated values of y as soon as they are available. In effect yk(i − 1)will now be yk+1(i− 1) on each iteration. So now we will be computing:

for i = 2:length(y)-1yk(i+ 1) = fnc(yk(i− 1), yk(i), yk(i+ 1), f(x(i))

end

That’s the only modification!

2.5.4 Successive-Over-Relaxation (SOR)

To implement SOR, we have 2 things we must first do beyond Gauss-Seidel. First we must specify the relaxationparameter ω. We must have 0 < ω < 2. For ω = 1, we have SOR is equivalent to Gauss-Seidel. Generally there isan optimal value of omega. It is not always easy to find analytically or numerically as it requires computing thespectral radius of the matrix A. For this problem:

ωoptimal ≈2√

1 + sin(πdx)

10

Page 11: Contentsetavernetti/ps22.pdfan concept related to the fact that the exponential function increases faster than any polynomial in the limit as x tends to in nity. Written another way,

Second, although we use a similar algorithm to Gauss-Seidel, we have for SOR:

for i = 2:length(y)-1yk+1(i) = (1− omega) ∗ yk(i) + ω ∗ fnc(yk(i− 1), yk(i), yk(i+ 1), f(x(i))

end

Now you are asked to take the provided MATLAB code and run it. You will need to set a numerical toler-ance value. TOL = 1e-5 or 1e-6 would be a good choice. Then for step-sizes (using optimal ω for the SORalgorithm) run the code for:

dx =π

8,π

16,π

32,π

64Then, in Excel make a table recording for each step size and method the number of iterations needed by Jacobi,Gauss-Seidel and SOR respectively to converge to the specified tolerance. You are encouraged to modify the code(e.g. add a loop over the dx values) so that it does this in one run. For each method, if you half the step size dxwhat happens to the number of iterations required?

Finally, of the four methods, Gaussian Elimination, Jacobi, Gauss-Seidel and SOR, which do you think is thebest? Why? In particular, comment on what sort of things make one numerical method better than another. Itis strongly recommended for those new to Matlab to look over the code and figure out how it works.

2.6 Special Topic: Series Solutions and Special Functions

Recalling that elementary functions are built from a finite number of exponentials, trigonometric functions, loga-rithms, constants, one variable, and nth roots and their inverses through composition and combinations using thefour elementary operations (+,−,×,÷).

2.6.1 Bessel Functions of the first kind (IVP)

We can derive the celebrated Bessel function by solving Bessel’s differential equation:

y′′ +1xy′ +

(1− ν2

x2

)y = 0, ν ≥ 0 ∈ R

Bessel functions are also known as cylinder functions or cylindrical harmonics because they are found in the so-lution to Laplace’s equation in cylindrical coordinates. They are ubiquitous in a variety of applications such as:electromagnetic waves in a cylindrical waveguide, heat conduction in a cylindrical object, modes of vibration of athin circular (or annular) artificial membrane (such as a drum or other membranophone), diffusion problems ona lattice, solutions to the radial Schrdinger equation (in spherical and cylindrical coordinates) for a free particle,solving for patterns of acoustical radiation. Bessel functions also have useful properties for other problems, suchas signal processing (e.g., see FM synthesis, Kaiser window, or Bessel filter).

We will find the first 2 Bessel functions. For ν = 0 solve the Bessel D.E. subject to y(0) = 1, y′(0) = 0. Forν = 1 solve the Bessel D.E. subject to y(0) = 0, y′(0) = 1/2. You can check your solution against:

y0 ≈ 1− x2

22(1!)2+

x4

24(2!)2− x6

26(3!)2+ ...

and

y1 ≈x

2− x3

23(1!2!)+

x5

25(2!3!)− x7

27(3!4!)+ ...

You can also check these in MATLAB very simply with: plot(0:.01:10,besselj(1,0:.01:10),0:.01:10,besselj(0,0:.01:10))

11

Page 12: Contentsetavernetti/ps22.pdfan concept related to the fact that the exponential function increases faster than any polynomial in the limit as x tends to in nity. Written another way,

2.6.2 Airy Functions (IVP)

d2y

dx2− xy = 0

Solve for functions Ai(x) and Bi(x) subject to: Ai(0) = 0.3550, Ai’(0)=-0.2588, and also Bi(0) = 0.6419, Bi’(0) =0.4483.

2.6.3 Legendre Polynomials (BVP)

Legendre functions are solutions to Legendre’s differential equation:

d

dx

[(1− x2)

d

dxPn(x)

]+ n(n+ 1)Pn(x) = 0.

They are very important in physics. Let n = 0,1,2,3... note this is a BVP, we want to solve this boundary valueproblem subject to the boundary conditions:

y(1) = 1, y(−1) = −1 if n is odd, or y(−1) = 1 if n is even

To check our result we can use the Rodrigues formula to obtain:

Pn(x) =1

2nn!dn

dxn[(x2 − 1)n] =

{1, x,

12

(3x2 − 1),12

(5x3 − 3x), ...}

A plot of the first four Legendre Polynomials is shown below:

3 A Fourth Order BVP - Bending of Beams

For a fourth order problem, we will investigate:

d4y

∆x4+ y = 1, y(0) = y′′(0) = y(1) = y′′(1) = 0

and we will also investigate:d4y

∆x4= 1, y(0) = y′′(0) = y(1) = y′′(1) = 0

12

Page 13: Contentsetavernetti/ps22.pdfan concept related to the fact that the exponential function increases faster than any polynomial in the limit as x tends to in nity. Written another way,

We will do these problems in MATLAB. There are two primary ways we want to consider solving this problem.We can use a fourth order discretization or we can use a reduction of order of the equations we are solving bydecomposing the fourth equation into a system of lower order equations. Conceptually the idea of this problem issimple and the solutions are similar for both problems at the first mode.

Will do the first problem with a Fourth Order Discretization and we will do the second problem with decomposeinto a system of second order equations.

3.1 Fourth Order Discretization

Here we use:y4i =

yi+2 − 4yi+1 + 6yi − 4yi−1 + yi−2

∆x4

We need to be a little clever in order to get the boundary conditions just right. You should write out the differenceequations for i = 1, i = 2, i = 3 to see the boundary conditions. They will similar at the left and right boundaries.We want to write the problem in matrix form Ay = b where A is a penta-diagonal matrix. We can then solve:

y = A−1b

To do this numerically we explicity write the matrix A. Suppose N is the dimension of A, where N = 1∆x + 1. We

want to write A as penta-diagonal matrix with non-zero diagonals:

ayi−2 + byi−1 + cyi + dyi+1 + eyi+2 = f

Following this we have:for i = 3:N-2

a(i) = 1/h4;b(i) = -4/h4;c(i) = ...;d(i) = -4/h4;e(i) = 1/h4;f(i) = ...;

endYou may find it easier to multiply the discretized equation by h4 before inputing the coefficients for (a) − (f).Special conditions will be needed for i = 1, 2, N − 1, N . These are derived from the boundary conditions. Whenyou have the coeffcients use the template code provided in the solutions. All you need to do is input your matrixA and run the program.

3.2 Solving as System of Second Order Equations

In this case we set the problem up as:

y′′ = M

M ′′ = y(4) = 1

13

Page 14: Contentsetavernetti/ps22.pdfan concept related to the fact that the exponential function increases faster than any polynomial in the limit as x tends to in nity. Written another way,

See that this is equivalent to:d4y

∆x4= 1

Now we first solve the equation: M ′′ = 1 subject to the boundary conditions. Then we take this solution M anduse it in the equation for: y′′ = M , again, subject to the boundary conditions.

4 A Second Order Eigenvalue Problem

For another second order problem we seek solutions λ to the equation: M ′′ = 1. Discretize as usual subject to theboundary conditions. Then take this solution for M = Mi and use it as the right hand side to solve the secondequation: m

d2y

dx2+ λy = 0

This is an Eigenvalue Problem (EVP) first studied by Euler in 1757. It is also Boundary Value problem whensubject to the initial conditions:

y(a) = α, y(b) = β

We say λ is an eigenvalue of the nxn matrix A if there is a non-zero vector v s.t.

Av = λv

In such a case we call v an eigenvector of A associated with the eigenvalue λ. James Bernoulli in 1691 made thefirst investigations into Buckling of elastic objects. He stated that the curvature at any point of an initially straightbeam would be proportional to the bending moment at that point. Following this work, Daniel Bernoulli in 1751demonstrated that the resultant curve of a bent elastic media took the shape that gave minimum strain energywhile bending. He also proposed that Euler’s variational calculus should be the tool applied to the inverse problemof finding the curve of a given length satisfing the boundary conditions of position and direction to minimize tothe strain energy. The Buckling problems form a rich class of problems and solutions.

We will set boundary conditions:y(0) = 0, y(1) = 0

First note that the general solution to this problem is:

y(x) = a cos(x√λ) + b sin(x

√λ)

Enforcing the boundary conditions we have a = 0 from y(0) = 0 and from y(1) = 0 we get:√λ = nπ, n = 0,±1,±2, ...⇒ λ = n2π2, n = 0,±1,±2, ...

Now suppose we did not know the above and we wanted to numerically find for which values of λ does the boundaryvalue problem have solutions other than the trivial solution for which y = 0. Let h = 1/3 we will solve for anapproximation of the eigenvalues by a classical method. Then we will use the Power Method to numerically findthe dominant eigenvalue and an associated eigenvector for h = 1/3. We can also use the inverse power method tofind the smallest eigenvalue and we will see that as well.

14

Page 15: Contentsetavernetti/ps22.pdfan concept related to the fact that the exponential function increases faster than any polynomial in the limit as x tends to in nity. Written another way,

First discretize the system by hand. You should get two equations in unknowns y(1), y(2) and λ. Write this systemas Ay = −λy. Since we seek λ and y 6= 0 s.t. Ay = λy this is equivalent to: (A+λ)y = 0. From elementary linearalgebra, the system has a non-trivial solution y = [y(1), y(2)] if and only if:

det (A+ λ) = 0

where det is the matrix determinant. Solve for the values of λ such that this is true. You will get a quadraticequation in λ. You should get λ = 9, 27. Note that these values are actually approximations for π2, 4π2 respec-tively. This is not a very good approximation and we cannot even approximate the higher eigenvalues with such alarge step size, nevertheless, fully understanding this example will help you greatly with your future studies. Onceyou have done this, we will implement the following algorithm to find the dominant eigenvalue and its associatedeigenvector numerically:

Power Method (use to find the dominant e-value and associated e-vector):Guess y = [1 0]T

Set a Tolerance = TOLDo While error > TOL

x = Ayλ = max(x)error = max(|y-x/λ|)y = x/λ

endInverse Power Method (use to find the smallest e-value and associated e-vector):

Guess y0

Set a Tolerance = TOLDo While error > TOL

xn+1 = Axnλ = xn+1·xn

xn·xn

xn+1 = xn+1√xx+1·xn+1

error = max(|xn+1 − xn|)end

Carry out both of these alogorithms by hand in Excel, or on paper for 5-7 iterations, or in MATLAB up to a fixedTOL. Then check explicity that:

Ay ≈ λy

Notice that this implies that:Ay − λy ≈ 0

Since A is a matrix that discretizes d2

dx , indeed we have solved the problem. Make sure to show you work and giveyour approximation to the dominant eigenvalue λ = µ and the associated eigenvector x. What do you think thetrue solution is for λ and y? Use this eigenvector for your initial guess x. What happens?

The next thing to do is to implement the algorithms above for a finer mesh and approximate the largest andsmallest eigenvalues and their associated eigenfunctions (e.g. their ’eigenvectors’) using the power and inversepower methods respectively. Proceeding thus we obtain from the power method:

15

Page 16: Contentsetavernetti/ps22.pdfan concept related to the fact that the exponential function increases faster than any polynomial in the limit as x tends to in nity. Written another way,

Where the top plot corresponds with the smallest eigenvalue output from the inverse power method and the bottomplot is for the largest eigenvalue and the power method output.

5 A Chaotic Third Order or ’Jerk’ Equation

For a third order problem we will study:

d3y

dt2+A

d2y

dt2− dy

dt+ y = 0

It is unlikely that any algebraically simpler form of an autonomous chaotic flow exists because this equation has theminimum number of terms that allows an adjustable parameter and it has only a single quadratic nonlinearity (Am.J. Phys., Vol. 65, No. 6, June 1997. [Sprott, 539]). The equation has bounded solutions for A ∈ (2.017, 2.082)along with a period doubling route to chaos and nearly parabolic map similar to that associated with the logisticequation. We will let A = 2.017.

Algorithm: A Simple Euler Method Solve:Set: x = 0.02, v = 0, a = 0, h = 0.01, A = 2.017, imax

while i < imaxx = x+ h ∗ vv = v + h ∗ aj = −A ∗ a+ v ∗ v − xa = a+ h ∗ ji = i+ 1

end while loop

You are asked to implement this algorithm in Excel. Your result should look something like this:

16

Page 17: Contentsetavernetti/ps22.pdfan concept related to the fact that the exponential function increases faster than any polynomial in the limit as x tends to in nity. Written another way,

17