From the output we see that the largest eigenvalue of B is about (ii) Use the inverse power method to find the smallest eigenvalue.

Similar documents
Application 2.4 Implementing Euler's Method

x n x n stepnumber k order r error constant C r+1 1/2 5/12 3/8 251/720 abs. stab. interval (α,0) /11-3/10

Mathematics for chemical engineers

Direction Fields; Euler s Method

over The idea is to construct an algorithm to solve the IVP ODE (9.1)

Module1: Numerical Solution of Ordinary Differential Equations. Lecture 6. Higher order Runge Kutta Methods

ODEs occur quite often in physics and astrophysics: Wave Equation in 1-D stellar structure equations hydrostatic equation in atmospheres orbits

Euler s Methods (a family of Runge- Ku9a methods)

Maxima CAS presentation Chelton Evans

SYSTEMS OF NONLINEAR EQUATIONS

Interpolation. TANA09 Lecture 7. Error analysis for linear interpolation. Linear Interpolation. Suppose we have a table x x 1 x 2...

Discontinuous Galerkin Sparse Grid method for Maxwell s equations

Unit #22 - The Chain Rule, Higher Partial Derivatives & Optimization Section 14.7

Math Homework 3

A Study on Numerical Exact Solution of Euler, Improved Euler and Runge - Kutta Method

1.2 Round-off Errors and Computer Arithmetic

Lecture 3.3 Robust estimation with RANSAC. Thomas Opsahl

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

f xx + f yy = F (x, y)

Matlab Notes for Calculus 3. Lia Vas

(Part - 1) P. Sam Johnson. April 14, Numerical Solution of. Ordinary Differential Equations. (Part - 1) Sam Johnson. NIT Karnataka.

Section 1.1 The Distance and Midpoint Formulas; Graphing Utilities; Introduction to Graphing Equations

Module 2: Single Step Methods Lecture 4: The Euler Method. The Lecture Contains: The Euler Method. Euler's Method (Analytical Interpretations)

Application 7.6A The Runge-Kutta Method for 2-Dimensional Systems

ODE IVP. An Ordinary Differential Equation (ODE) is an equation that contains a function having one independent variable:

Homework 14 solutions

Ch 09 Multidimensional arrays & Linear Systems. Andrea Mignone Physics Department, University of Torino AA

Introduction to Computer Programming with MATLAB Calculation and Programming Errors. Selis Önel, PhD

Homework Set #2-3, Math 475B

Math/CS 467/667 Combined Programming 2 and Homework 2. The Shu Oscher Method

Answer sheet: Second Midterm for Math 2339

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

Analyzing Fractals SURFACE. Syracuse University. Kara Mesznik. Syracuse University Honors Program Capstone Projects

A Quick Guide to Gnuplot. Andrea Mignone Physics Department, University of Torino AA

3.1 Iterated Partial Derivatives

Teaching Manual Math 2131

AMS527: Numerical Analysis II

MATLAB primer for CHE 225

f(0.2) < 0 and f(0.3) > 0 f(1.2) > 0 and f(1.3) < 0 f(1) = 1 > 0 and f(2) 0.

USING SPREADSHEETS AND DERIVE TO TEACH DIFFERENTIAL EQUATIONS

MATH2071: LAB 2: Explicit ODE methods

Numerical Methods Lecture 1

MAT 275 Laboratory 3 Numerical Solutions by Euler and Improved Euler Methods (scalar equations)

22. LECTURE 22. I can define critical points. I know the difference between local and absolute minimums/maximums.

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

Introduction to Mathcad

Matlab Notes for Mathematical Modeling. Lia Vas

over The idea is to construct an algorithm to solve the IVP ODE (8.1)

Summer 2009 REU: Introduction to Matlab

Learning Packet. Lesson 6 Exponents and Rational Functions THIS BOX FOR INSTRUCTOR GRADING USE ONLY

Introduction to numerical algorithms

ECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu

Objectives Graph and Analyze Rational Functions Find the Domain, Asymptotes, Holes, and Intercepts of a Rational Function

Homework Set 5 (Sections )

Daily WeBWorK, #1. This means the two planes normal vectors must be multiples of each other.

Natasha S. Sharma, PhD

Mathematical Methods and Modeling Laboratory class. Numerical Integration of Ordinary Differential Equations

1) Generate a vector of the even numbers between 5 and 50.

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

Precomposing Equations

3.3 Here are VBA and MATLAB implementations of the algorithm:

Solving Algebraic Equations

LECTURE 18 - OPTIMIZATION

Assignment Assignment for Lesson 9.1

What is log a a equal to?

Bindel, Spring 2015 Numerical Analysis (CS 4220) Figure 1: A blurred mystery photo taken at the Ithaca SPCA. Proj 2: Where Are My Glasses?

A Quick Tutorial on MATLAB. Zeeshan Ali

Introduction to MATLAB Programming

Minima, Maxima, Saddle points

Ordinary differential equations solving methods

-t:ma. u V:. 1! *VV; jf >*4: t i f n - v i ' ONABI E :VISITd:Rs ; 8 A EASTBOURNE, SAT. 5? -tesiste- COLLEGE. D ressm aker.

Regularization by multigrid-type algorithms

Adding and subtracting rational expressions is quite similar to adding and subtracting rational numbers (fractions).

MAT 275 Laboratory 3 Numerical Solutions by Euler and Improved Euler Methods (scalar equations)

= f (a, b) + (hf x + kf y ) (a,b) +

MATLAB QUICK START TUTORIAL

An Investigation into Iterative Methods for Solving Elliptic PDE s Andrew M Brown Computer Science/Maths Session (2000/2001)

2-3 Graphing Rational Functions

Numerical Solutions of Differential Equations (1)

MATH2071: LAB 1(b): Selected topics in Matlab. This version of the first lab is intended only for students who have already taken Math 2070.

Numerical Methods for Differential Equations Contents Review of numerical integration methods Rectangular Rule Trapezoidal Rule Simpson s Rule How to

Introduction to Matlab

College Algebra. Quadratic Functions and their Graphs. Dr. Nguyen October 12, Department of Mathematics UK

3.2 Recursions One-term recursion, searching for a first occurrence, two-term recursion. 2 sin.

2-4 Graphing Rational Functions

Computer Simulations

On the regularizing power of multigrid-type algorithms

Simulation of Mechatronic Systems

A method to speedily pairwise compare in AHP and ANP

7.1 INVERSE FUNCTIONS

Introduction to Programming for Engineers Spring Final Examination. May 10, Questions, 170 minutes

Jason Yalim. Here we perform a few tasks to ensure a clean working environment for our script.

Things to Know for the Algebra I Regents

Introduction to MATLAB

A Random Variable Shape Parameter Strategy for Radial Basis Function Approximation Methods

1 of 34 7/9/2018, 8:08 AM

PHS3XXX Computational Physics

Mathematical preliminaries and error analysis

Today. Motivation. Motivation. Image gradient. Image gradient. Computational Photography

Convexization in Markov Chain Monte Carlo

Transcription:

. Let B be the matrix given by.8635.735.9593.5685.65.735.8984.7439.6447.553.9593.7439.699.635.643.5685.6447.635.056.430.65.553.643.430.5505 (i) Use the power method to find the largest eigenvalue. The following Matlab script clear all; getb; 3 v=ones(5,); 4 disp(sprintf("%0s %5s","iteration","lambda")); 5 for i=:8 6 w=b*v; 7 lambda=(v *w)/(v *v); 8 disp(sprintf("%0d %5.0f",i,lambda)); 9 [y,i]=max(abs(w)); 0 alpha=w(i); v=w/alpha; end along with the file getb.m given by B=[.8635.735.9593.5685.65; 3.735.8984.7439.6447.553; 4.9593.7439.699.635.643; 5.5685.6447.635.056.430; 6.65.553.643.430.5505]; implements the power method and produces the output iteration lambda 8.84400000 8.943037789 3 8.948076 4 8.9487504 5 8.9487993 6 8.9487997 7 8.9487998 8 8.9487998 From the output we see that the largest eigenvalue of B is about 8.948. (ii) Use the inverse power method to find the smallest eigenvalue. A slight modification of the above code to implement the inverse power method gives clear all

getb; 3 v=ones(5,); 4 disp(sprintf("%0s %5s","iteration","lambda")); 5 for i=:8 6 w=b\v; 7 lambda=(v *v)/(v *w); 8 disp(sprintf("%0d %5.0f",i,lambda)); 9 [y,i]=max(abs(w)); 0 alpha=w(i); v=w/alpha; end with output iteration lambda.448364 0.0839793 3 0.0673843 4 0.0654353 5 0.0653976 6 0.06509497 7 0.0650888 8 0.0650875 From the output we see that the smallest eigenvalue of B is about 0.065. (iii) [ ] Use the shifted inverse power method to find one more eigenvalue. We decide to shift by s = to find another eigenvalue. A modification of the above code to implement the shifted inverse power method gives clear all getb; 3 v=ones(5,); 4 disp(sprintf("%0s %5s","iteration","lambda")); 5 s=; 6 BS=B-s*eye(5); 7 for i=:5 8 w=bs\v; 9 lambda=(v *v)/(v *w)+s; 0 disp(sprintf("%0d %5.0f",i,lambda)); [y,i]=max(abs(w)); alpha=w(i); 3 v=w/alpha; 4 end with output iteration lambda 9.4040886684

0.34578845 3 0.77866750 4 0.8780695 5 0.8839445 6 0.886438859 7 0.8876008577 8 0.888055335 9 0.88837436 0 0.8883783 0.888344866 0.888358853 3 0.8883650093 4 0.888367783 5 0.8883690388 From the output we see that another eigenvalue of B is about 0.88837. For reference note that the complete set of eigenvalue of B may be found using the built-in Matlab command eig and are given by >> eig(b) ans = 0.0650869706069 0.099909693658 0.3653895053996 0.888370095834445 8.948799750 3

. Consider the two-point linear boundary problem { y + cos(x)y (x + )y = y( ) = y() =. (i) Solve the above boundary problem for grid sizes of h = 4/n where n = 4, 8, 6, 3,..., 56. Plot your solutions. The Matlab code for this consisted of the script clear all p=@(x) -cos(x); 3 q=@(x) x.*x+; 4 r=@(x) +0*x; 5 6 dataout=fopen("data.dat","w"); 7 for N=.^[:8] 8 fprintf(dataout,"# n=%d\n",n); 9 [xn,yn]=solvebvp(p,q,r,-,,n,,); 0 for j=:length(xn) fprintf(dataout,"%.5e %.5e\n",xn(j),yn(j)); end 3 fprintf(dataout,"\n\n"); 4 end 5 fclose(dataout); along with solvebvp.m for solving for the two-point boundary value problem %solvebvp.m -- Solve boundary value problem % y =py +qy+r 3 % y(a)=g, y(b)=g 4 function [xn,yn]=solvebvp(p,q,r,a,b,n,g,g) 5 h=(b-a)/n; 6 xn=[a:h:b] ; 7 Aa=-(+h/*p(xn(3:N))); 8 Ab=+h^*q(xn(:N)); 9 Ac=(+h/*p(xn(:N))); 0 f=-h^*r(xn(:n)); f()=f()+(+h/*p(xn()))*g; f(n)=f(n)+(-h/*p(xn(n)))*g; 3 ym=tridiag(aa,ab,ac,f); 4 yn=[g; ym; g]; and the tridiagonal solver tridiag.m developed in class function f=tridiag(a,b,c,f) n=length(b); 3 for i=:n 4

4 a(i)=a(i)/b(i); 5 b(i+)=b(i+)-a(i)*c(i); 6 end 7 for i=:n 8 f(i+)=f(i+)-a(i)*f(i); 9 end 0 f(n)=f(n)/b(n); for i=n:: f(i)=(/b(i))*(f(i)-c(i)*f(i+)); 3 end 4 end This code creates a data file data.dat consisting of the solution for each resolution separated by two blank lines. We plot the data file using the plotting program gnuplot along with the script data.gnu which contains the commands set terminal pstex set style data lines 3 set size 0.8,0.8 4 set key spacing. 5 set key bottom 6 set output "data-0.tex" 7 plot [:] [.35:-0.85] "data.dat" index 0 ti "$n=4$" 8 set output "data.tex" 9 plot [:] [.35:-0.85] "data.dat" index ti "$n=8$" 0 set output "data-.tex" plot [:] [.35:-0.85] "data.dat" index ti "$n=6$" set output "data-3.tex" 3 plot [:] [.35:-0.85] "data.dat" index 3 ti "$n=3$" 4 set output "data-4.tex" 5 plot [:] [.35:-0.85] "data.dat" index 4 ti "$n=64$" 6 set output "data-5.tex" 7 plot [:] [.35:-0.85] "data.dat" index 5 ti "$n=8$" 8 set output "data-6.tex" 9 plot [:] [.35:-0.85] "data.dat" index 6 ti "$n=56$" The resulting output was 5

-0.9...3 n = 4 -.5-0.5 0 0.5.5-0.9...3 n = 8 -.5-0.5 0 0.5.5-0.9...3 n = 6 -.5-0.5 0 0.5.5 6

-0.9...3 n = 3 -.5-0.5 0 0.5.5-0.9...3 n = 64 -.5-0.5 0 0.5.5-0.9...3 n = 8 -.5-0.5 0 0.5.5 7

-0.9...3 n = 56 -.5-0.5 0 0.5.5 (ii) Calculate the value of y() to 5 significant digits. The following Matlab code uses the relationship that y j y() for j = + 3n/4. Note that 0.05 is added in the code and the integer part is taken to ensure correct rounding. clear all p=@(x) -cos(x); 3 q=@(x) x.*x+; 4 r=@(x) +0*x; 5 6 disp(sprintf("%5s %5s %8s %5s","n","j","xj","yj")); 7 for N=.^[5:] 8 [xn,yn]=solvebvp(p,q,r,-,,n,,); 9 j=floor(3/4*n+.05); 0 disp(sprintf("%5d %5d %8.4g %5.0g",N,j,xn(j),yn(j))); end The output is n j xj yj 3 5.0099565 64 49.009703 8 97.007353 56 93.006499 5 385.006339 04 769.00693 048 537.006809 4096 3073.0067958 It is clear that y().006 to 5 significant digits. (iii) [ ] Numerically verify the order of convergence of your solution with theoretical expectations. 8

Since this ordinary differential equation two-point boundary value problem solver employs a nd order method, theoretical expectations are that the error decreases by a factor of 4 every time n is doubled. The following Matlab program computes an approximation for the exact answer using n = 5 and then checks from n = 6,3,...,04 that the error decreases by a factor of 4 each time. clear all p=@(x) -cos(x); 3 q=@(x) x.*x+; 4 r=@(x) +0*x; 5 6 N=[.^[4:0],^5]; 7 M=length(N); 8 for i=:m 9 [xn,yn]=solvebvp(p,q,r,-,,n(i),,); 0 j=floor(3/4*n(i)+.05); y(i)=yn(j); end 3 e=y-y(m); 4 5 disp(sprintf("%5s %6s %0s %6s","n","y","error","ratio")); 6 for i=:m 7 disp(sprintf("%5d %6.f %0.e %6.f",... 8 N(i),y(i),e(i),e(i)/e(i))); 9 end; The output is n y error ratio 3.009956465.3636860405e-03 3.94037053496 64.0097035-3.4536077700e-04 3.98443378054 8.00735333-8.564469648e-05 3.996038803 56.00649990 -.436550475e-05 3.99960933385 5.00633908-5.35044543e-06 4.0049475649 04.0069306.3344445633e-06 4.009549849906 The fact that the list of ratios given in the last column of the above table is close to 4 verifies the method is converging with second order. 9

3. Consider the initial value problem { y = cos(y) + cos(x) y(0) = 0. (i) Construct a 3rd-order Taylor method for solving this problem. In general, a third order Taylor method has the update rule where y n+ = y n + hf 0 (x n,y n ) + h f (x n,y n ) + h3 3! f (x n,y n ) f i (x,y) = di dx i f(x,y). The following Maple script creates C and Matlab code for a Taylor method with order N and forcing function f. #Build a Taylor method for y =f of order N restart; 3 with(codegen): 4 N:=3; 5 f:=cos(y(x))+cos(x); 6 s:=[seq(diff(y(x),x$(n-i+))=f (N-i),i=..N),y(x)=yn,x=xn]; 7 r[]:=f; 8 for i from to N 9 do 0 r[i]:=diff(r[i],x); end; jet:=seq(f (i)=subs(s,r[i]),i=..n); 3 t:=yn; 4 for i from to N 5 do 6 t:=t+h^i/i!*f (i); 7 end; 8 t:=horner(t,h); 9 jeto:=optimize([jet,yn=t]); 0 C([jeto]); The output of this script is t = cos(yn); t3 = cos(xn); F0 = t+t3; t4 = sin(yn); t6 = sin(xn); F = -t4*f0-t6; t7 = F0*F0; F = -t*t7-t4*f-t3; 0

yn = yn+(f0+(f/.0+f*h/6.0)*h)*h; which we embed into Matlab to make the Taylor integrator function yn=taylor3a(x0,y0,xn,n) h=(xn-x0)/n; 3 xn=x0; 4 yn=y0; 5 for n=:n 6 7 % The following Taylor time step was generated by Maple 8 t = cos(yn); 9 t3 = cos(xn); 0 F0 = t+t3; t4 = sin(yn); t6 = sin(xn); 3 F = -t4*f0-t6; 4 t7 = F0*F0; 5 F = -t*t7-t4*f-t3; 6 yn = yn+(f0+(f/.0+f*h/6.0)*h)*h; 7 8 xn=x0+h*n; 9 end; (ii) Compute y(0) to 5 significant digits using your 3rd-order Taylor method. The script for computing y(0) is given by clear all disp(sprintf("%5s %6s","n","y")); 3 for N=.^[3:8]; 4 y=taylor3a(0,0,0,n); 5 disp(sprintf("%5d %6.f",N,y)); 6 end with output n y 8 0.8645754856 6 0.864838490 3 0.864078690 64 0.863986465 8 0.86396474966 56 0.86396463 It is clear that y(0) 0.86396 to 5 significant digits. (iii) [ ] Numerically verify the order of convergence of your code to be 3rd order.

Since this is a 3nd order method, theoretical expectations are that the error decreases by a factor of 3 = 8 every time n is doubled. The following Matlab program computes an approximation for the exact answer using n = 5 and then checks from n = 6,3,...,04 that the error decreases by a factor of 8 each time. N=[.^[3:0],^5]; M=length(N); 3 for i=:m 4 y(i)=taylor3a(0,0,0,n(i)); 5 end 6 e=y-y(m); 7 8 disp(sprintf("%5s %6s %0s %6s","n","y","error","ratio")); 9 for i=:m 0 disp(sprintf("%5d %6.f %0.e %6.f",... N(i),y(i),e(i),e(i)/e(i))); end; The output is n y error ratio 6 0.864838490 8.608797790e-04 0.73484085 3 0.864078690.48707504e-04 5.7904954504 64 0.863986465.05654746689e-05 7.3087088949 8 0.86396474966.673474348347e-06 7.694398543 56 0.86396463 3.3994496560e-07 7.8644338494 5 0.8639690 4.836037404e-08 7.93667467864 04 0.863960856 5.37444634e-09 7.969638305 The fact that the list of ratios given in the last column of the above table is close to 8 verifies the method is converging with third order.

4. Consider the general initial value problem { y = f(x,y) y(x 0 ) = y 0. (i) Starting with Euler s explicit method, use Richardson extrapolation with step sizes h and 3h to create a method that is nd-order convergent. Since Euler s explicit method is first order, it has an asymptotic error formula of the form y(x) y h (x) = hd(x) + h E(x) + O(h 3 ) where y(x) is the exact solution and y h is the approximation obtained by Euler s method. It may be assumed that D(x) and E(x) do not depend greatly on h. Therefore and y(x) y h (x) = hd(x) + 4h E(x) + O(h 3 ) y(x) y 3h (x) = 3hD(x) + 9h E(x) + O(h 3 ). Multiplying the first equation by 3, the second by and subtracting eliminates D(x) and obtains y(x) 3y h (x) + y 3h (x) = 6h E(x) + O(h 3 ). Therefore, the method given by y(x) 3y h (x) y 3h (x) is second order. Starting with (ii) Starting with Euler s explicit method, use Richardson extrapolation with step sizes h, h and 3h to create a method that is 3rd-order convergent. and y(x) y h (x) = hd(x) + h E(x) + O(h 3 ) y(x) y h (x) = hd(x) + 4h E(x) + O(h 3 ). multiply the first equation by and subtract to obtain y(x) y h (x) + y h (x) = h E(x) + O(h 3 ). Now, multiply this result by 3 and subtract from the answer to the previous part to obtain y(x) + 6y h (x) 6y h (x) + y 3h (x) = O(h 3 ). Therefore, the method given by y(x) 3y h (x) 3y h (x) + y 3h (x) is third order. (iii) [ ] Use the 3rd-order method created above to compute y() to 5 significant digits when f(x,y) = xy + (4x/y), x 0 = 0 and y 0 =. 3

The extrapolation method may be coded as function yn=richard4c(x0,y0,xn,f,n) h=(xn-x0)/n; 3 xn=x0; 4 yn=y0; 5 for n=:n 6 y=euler4c(xn,yn,xn+h,f,6); 7 y=euler4c(xn,yn,xn+h,f,3); 8 y3=euler4c(xn,yn,xn+h,f,); 9 yn=3*(y-y)+y3; 0 xn=x0+h*n; end; where the Euler method is given by function yn=euler4c(x0,y0,xn,f,n) h=(xn-x0)/n; 3 xn=x0; 4 yn=y0; 5 for n=:n 6 yn=yn+h*f(xn,yn); 7 xn=x0+h*n; 8 end; Test this method using the script clear all f=@(x,y) -x*y+(4*x/y); 3 N=[.^[3:0],^5]; 4 M=length(N); 5 for i=:m 6 y(i)=richard4c(0,,,f,n(i)); 7 end 8 e=y-y(m); 9 0 disp(sprintf("%5s %6s %0s %6s","n","y","error","ratio")); for i=:m disp(sprintf("%5d %6.f %0.e %6.f",... 3 N(i),y(i),e(i),e(i)/e(i))); 4 end; 4

which produces the output n y error ratio 6.98697476.34057733e-05 7.069644645 3.986746967.70008640983e-06 7.88499753436 64.98659885.7634868e-07 8.00897667889 8.986579605.6478653664e-08 8.088007363 56.98657789 3.3037346909e-09 8.070937800 5.986576999 4.63498935e0 8.00685054660 04.986576963 5.566588476e 8.00575989838 Therefore y().986 to 5 significant digits. Moreover, the fact that the list of ratios given in the last column of the above table is close to 8 verifies the method is converging with third order. 5