MATH 552 Spectral Methods Spring Homework Set 5 - SOLUTIONS

Similar documents
HW #3 Solutions: M552 Spring (c)

Math 552 Scientific Computing II Spring SOLUTIONS: Homework Set 1

Homework Set 4 - SOLUTIONS

HW #1 Solutions: M552 Spring 2006

Assignment 6, Math 575A

Finite Difference Methods for Boundary Value Problems

MATH 590: Meshfree Methods

Interpolation and the Lagrange Polynomial

Background. Background. C. T. Kelley NC State University tim C. T. Kelley Background NCSU, Spring / 58

AMSC/CMSC 466 Problem set 3

MATH 221, Spring Homework 10 Solutions

Homework and Computer Problems for Math*2130 (W17).

MATH 590: Meshfree Methods

Flow Instability Matlab Tutorial Bangalore, January 2010 Matthew Juniper, Dan Henningson, Peter Schmid 1

Numerical Solutions to Partial Differential Equations

Math/Phys/Engr 428, Math 529/Phys 528 Numerical Methods - Summer Homework 3 Due: Tuesday, July 3, 2018

Maria Cameron Theoretical foundations. Let. be a partition of the interval [a, b].

Phonon dispersion relation and density of states of a simple cubic lattice

Boundary Layer Problems and Applications of Spectral Methods

Numerical Analysis of Differential Equations Numerical Solution of Elliptic Boundary Value

Class notes: Approximation

Physics with Matlab and Mathematica Exercise #1 28 Aug 2012

Part 1. The diffusion equation

INTERPOLATION Background Polynomial Approximation Problem:

Homework 1 Math 471, Fall 2008

Preliminary Examination, Numerical Analysis, August 2016

S(c)/ c = 2 J T r = 2v, (2)

EEE161 Applied Electromagnetics Laboratory 1

New Mexico Tech Hyd 510

18.06 Problem Set 9 - Solutions Due Wednesday, 21 November 2007 at 4 pm in

MATH 235/W08: Orthogonality; Least-Squares; & Best Approximation SOLUTIONS to Assignment 6

Functional Analysis Review

MATH 412 Fourier Series and PDE- Spring 2010 SOLUTIONS to HOMEWORK 5

Homework 6 MA/CS 375, Fall 2005 Due December 15

Chapter 1: Introduction

Lecture 1 INF-MAT3350/ : Some Tridiagonal Matrix Problems

Math 502 Fall 2005 Solutions to Homework 5. Let x = A ;1 b. Then x = ;D ;1 (L+U)x +D ;1 b, and hence the dierences

Math 308 Week 8 Solutions

(Linear equations) Applied Linear Algebra in Geoscience Using MATLAB

Math 515 Fall, 2008 Homework 2, due Friday, September 26.

January 18, 2008 Steve Gu. Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,

Outline. 1 Boundary Value Problems. 2 Numerical Methods for BVPs. Boundary Value Problems Numerical Methods for BVPs

INF-MAT Mandatory Exercise 1

Statistical methods. Mean value and standard deviations Standard statistical distributions Linear systems Matrix algebra

Introduction and Stationary Iterative Methods

Matlab Exercise 0 Due 1/25/06

18.06 Problem Set 8 Due Wednesday, 23 April 2008 at 4 pm in

3.1 Interpolation and the Lagrange Polynomial

MATH 425, HOMEWORK 5, SOLUTIONS

Qualifying Examination

Numerical Methods for PDEs

MATH 3511 Lecture 1. Solving Linear Systems 1

2.4 Eigenvalue problems

The University of Texas at Austin Department of Electrical and Computer Engineering. EE381V: Large Scale Learning Spring 2013.

Cheat Sheet for MATH461

PHYS 410/555 Computational Physics Solution of Non Linear Equations (a.k.a. Root Finding) (Reference Numerical Recipes, 9.0, 9.1, 9.

MATH2071: LAB #5: Norms, Errors and Condition Numbers

Math 118, Handout 4: Hermite functions and the Fourier transform. n! where D = d/dx, are a basis of eigenfunctions for the Fourier transform

Lecture 1. Finite difference and finite element methods. Partial differential equations (PDEs) Solving the heat equation numerically

Notes for CS542G (Iterative Solvers for Linear Systems)

L3: Review of linear algebra and MATLAB

Problem set 3: Solutions Math 207B, Winter Suppose that u(x) is a non-zero solution of the eigenvalue problem. (u ) 2 dx, u 2 dx.

Math 4263 Homework Set 1

x x2 2 + x3 3 x4 3. Use the divided-difference method to find a polynomial of least degree that fits the values shown: (b)

Math 577 Assignment 7

2 Solving Ordinary Differential Equations Using MATLAB

Introduction. Math 1080: Numerical Linear Algebra Chapter 4, Iterative Methods. Example: First Order Richardson. Strategy

Eigenvalues and Eigenvectors

Math 224, Fall 2007 Exam 3 Thursday, December 6, 2007


Math 1080: Numerical Linear Algebra Chapter 4, Iterative Methods

Computing Eigenvalues and/or Eigenvectors;Part 1, Generalities and symmetric matrices

HAND IN PART. Prof. Girardi Math 142 Spring Exam 3 PIN:

Linear Least Squares. Using SVD Decomposition.

Laboratory handout 1 Mathematical preliminaries

EE364a Homework 8 solutions

Math 502 Fall 2005 Solutions to Homework 3

The answer in each case is the error in evaluating the taylor series for ln(1 x) for x = which is 6.9.

MATH 1014 Tutorial Notes 8

Programs for Natural Cubic Spline Interpolation

2D Plotting with Matlab

Homework 5 - Solutions

1 Inner Product and Orthogonality

Computational Foundations of Cognitive Science

Harman Outline 1A Calculus CENG 5131 PDF

MAE 107 Homework 7 Solutions

Final Exam May 4, 2016

Lesson 11: Mass-Spring, Resonance and ode45

Linear Systems. Class 27. c 2008 Ron Buckmire. TITLE Projection Matrices and Orthogonal Diagonalization CURRENT READING Poole 5.4

Matlab Instruction Primer; Chem 691, Spring 2016

(Mathematical Operations with Arrays) Applied Linear Algebra in Geoscience Using MATLAB

Theory of Iterative Methods

Romberg Integration. MATH 375 Numerical Analysis. J. Robert Buchanan. Spring Department of Mathematics

to have roots with negative real parts, the necessary and sufficient conditions are that:

Chapter #4 EEE8086-EEE8115. Robust and Adaptive Control Systems

Numerical Analysis and Computing

1 Finite difference example: 1D implicit heat equation

What is on this week. 1 Vector spaces (continued) 1.1 Null space and Column Space of a matrix

A = 3 B = A 1 1 matrix is the same as a number or scalar, 3 = [3].

Iterative solvers for linear equations

Transcription:

MATH 55 Spectral Methods Spring 9 Homework Set 5 - SOLUTIONS. Suppose you are given an n n linear system Ax = f where the matrix A is tridiagonal b c a b c. A =.........,. a n b n c n a n b n with x = (x, x,..., x n ) T and f = (f, f,..., f n ) T. (a) Write a MATLAB M-file trisolve.m which computes the solution of the tridiagonal system Ax = f given the n-vectors a, b, c, and f. Include a copy of your code. The first line of the M-file should read function x = trisolve(a,b,c,f) (b) To check your code, let n =, a, b 5 and c. Compute the solution for f = (,,...,, ) T, with the exact solution easily seen to be x = (,..., ) T. Use the diary command in MATLAB to include a copy of your results. ANS: For (a) here is the code: function x = trisolve(a,b,c,f) % % TRISOLVE : tridiagonal solver for nxn system Ax=f where % A = diag(a(:n),-) + diag(b) + diag(c(:n-),) % n = length(b); x = zeros(n,); for i = :n end m = a(i)/b(i-); b(i) = b(i)-m*c(i); f(i) = f(i)-m*f(i-); % forward reduction x(n) = f(n)/b(n); % back substitution for i = n-:-: x(i) = (f(i)-c(i)*x(i+))/b(i); end To check that it works in MATLAB I executed >> a = -*ones(,); c = a; b = 5*ones(,); f = ones(,); f()=; f()=; >> x = trisolve(a,b,c,f);

>> x x = and indeed the answer is correct.

. Consider the discrete finite difference (FD) analog of the continuous eigenproblem d u dx = λu, < x < u() = u() = with d /dx D, the centered O(h ) FD approximation to the second derivative. To this end, choose N >, let h = /N and x i = i h for i =,,..., N. Note we now have N + grid points with x = and x N =. So we seek eigenpairs (λ, v) which satisfy (D v) i = v i v i + v i+ h = λv i for i =,,..., N, v = v N =, or in matrix form, h............... v v. v N v N = λ v v. v N v N (a) Show that (λ k, v k ) is an eigenpair for k =,,..., N where λ k = ( cos kπh)/h and v k is the vector with (v k ) i = sin ikπh for i =,,..., N. Hint: Use trig identities, and note that sin kπh = sin Nkπh =. (b) For N = 8 and N = 6 separately, plot (using MATLAB s subplot) the continuous eigenfunctions found in class, and the discrete eigenvectors from (a) for k =,, N/ and N. Thus each plot should have 4 images. Use a linetype for the continuous eigenfunctions and symbols for the discrete eigenvectors. Label and title your graphs. (c) In a single plot display the first eigenvalues vs. there number, i.e., k =,,..., of the continuous problem along with the N eigenvalues for the discrete case for N = 8, 6 and. For the continuous case plot the eigenvalues using a linetype with a symbol, and in the discrete case just symbols. Label, title, and place a legend on your plot. Discuss the results. ANS: (a) Noting that sin kπh = sin Nkπh =. Fix a k, k =,..., N. For i =,..., N, v k,i v k,i = v k,i+ h = = = = sin (i )kπh sin ikπh + sin (i + )kπh h (sin ikπh cos kπh cos ikπh sin kπh) sin ikπh+(sin ikπh cos kπh+cos ikπh sin kπh) h sin ikπh cos kπh sin ikπh h ( cos kπh) sin ikπh h = λ k sin ikπh. = λ k v k,i. So we have Av k = λ k v k for k =,..., N, thus (λ k, v k ) are e-pairs for k =,..., N.

(b) Here is the code for N = 8: N=8; h=/n; x=:h:; xx=:.:; k=[ N/ N-]; for i=:4 subplot(,,i) plot(xx,sin(k(i)*pi*xx),x,sin(k(i)*pi*x), o ) grid,axis( tight ) title([ sin(,numstr(k(i)), \pix): N=,numstr(N),, k=,numstr(k(i))]); end And the graphs for N = 8 and N = 6: sin(πx): N=8, k= sin(πx): N=8, k=.8.5.6.4..5..4.6.8..4.6.8 sin(4πx): N=8, k=4 sin(7πx): N=8, k=7.5.5.5.5..4.6.8..4.6.8 sin(πx): N=6, k= sin(πx): N=6, k=.8.5.6.4..5..4.6.8..4.6.8 sin(8πx): N=6, k=8 sin(5πx): N=6, k=5.5.5.5.5..4.6.8..4.6.8

(c) Here is the code to generate the plot, and the plot itself: N=[8 6 ]; h=./n; N=N-; plot( :N(),-*(-cos((:N())*pi*h()))/(h()^), p,... :N(),-*(-cos((:N())*pi*h()))/(h()^), +,... :N(),-*(-cos((:N())*pi*h()))/(h()^), *,... :,-(pi*(:)).^, -o, markersize,6, linewidth,) grid,title( Continuous vs. Discrete spectrum of d^/dx^ ) ylabel( eigenvalue ),xlabel( mode number ),legend( N=, N=6, N=8, continuous,) Discussion: From part (b) we see that the eigenvectors of the discrete differentiation matrix are the corresponding eigenfunctions of the continuous problem evaluated at the grid points determined by the specific N. In this sense the discrete problem is clearly a very good approximation to the continuous one. On the other hand, note in the plot above that while for each N the first few discrete eigenvalues are good approximations, this is not the case for the eigenvalues corresponding to the higher modes. Thus one expects these modes in the continuous problems not to be modeled well by the discrete approximation. Note: A Taylor series expansion gives (kπ) λ k = (kπ) + ( cos kπh) h = (kπ) + (kπh) ( ( + (kπh)4 )) h 4 = (kπ) + ( ) (kπh) h (kπh)4 + = (kπ) + (kπ) h ( (kπh) 4 ( ) 4 4 (kπ) 4 = h + O(h 4 ) = O(h ) So we do have the expected accuracy of approximation, but remember there is still a term in the error that depends on the eigenvalue being approximated, (kπ) 4 /, which explains, even for larger N, why we do not see rapid convergence of the discrete eigenvalues to the continuous ones as k N. In fact, for a fixed N and k large, we see divergence in the upper spectrum. )

. Boundary Value Problems and Boundary Layers: Consider the two-point boundary value problem { ɛu + u = x +, < x < u() = u() = where ɛ > is a given parameter. The exact solution is given by u(x) = x + sinh x ɛ + sinh x ɛ sinh ɛ (a) Using your tridiagonal solver compute the solution for ɛ = and N = /h = n for n =, 4, 6, 8. Using the subplot command, plot the exact solution and the computed solution for each N on the same page, i.e. 4 plots on the same page. Also, compute the ratios u v /h for each h = /N. Discuss the results. Include a copy of your code. (b) Repeat the exercise above for ɛ =. Again, discuss the results. What has changed, i.e. what is the effect of a smaller ɛ? ANS: (a) First, here are the computational results with ɛ = : N=4 eps=. N=6 eps=..5.5 N=64 eps=. N=56 eps=..5.5 Note that the computed solution and its linear interpolation does a good job of approximating the true solution for N 8 as is demonstrated in the numerical convergence seen in the error data

N inf_err inf_err/h^ ------------------------------------------ 4.e+.885e- 4.66e-.6e+.99e- 5.977e- 6.4e+.58e-4 5.7e-.56e+ 7.86e-6 5.88e- (b) Now, here are the computational results with ɛ = : Note that the computed N=4 eps=. N=6 eps=..5.5 N=64 eps=. N=56 eps=..5.5 solution does not do a very good job of approximating the true soltuion with N = 4 in this case due to the steep gradients in the solution near the boundary. N inf_err inf_err/h^ ------------------------------------------ 4.e+ 4.54e- 7.67e-.6e+.77e-.757e+ 6.4e+.98e- 4.498e+.56e+ 7.64e-4 4.597e+ Here is the code for ɛ = : N =.^(::8); epsilon = ^(-); hold off xx = :.5:; % compute true solution uu on fine grid xx uu = *xx+-(sinh((-xx)/sqrt(epsilon))+... *sinh(xx/sqrt(epsilon)))/sinh(/sqrt(epsilon)); err=zeros(4,); % compute approx for each N, plot, and store error for k=:length(n)

n = N(k); h = /n; x = (:h:) ; a = -epsilon*ones(n-,)/(h^); c = a; b = *epsilon*ones(n-,)/(h^)+; f = *x(:n)+; v = trisolve(a,b,c,f); v = [ v ] ; subplot(,,k), plot(xx,uu,x,v, *- ), axis([-.5.5.5]), grid title([ N=,numstr(n), eps=,numstr(epsilon)]) u = *x+-(sinh((-x)/sqrt(epsilon))+*sinh(x/sqrt(epsilon)))... /sinh(/sqrt(epsilon)); err(k,) = n; err(k,) = norm(u-v,inf); err(k,) = err(k,)/(h.^); end hold off, format short e disp( N inf_err inf_err/h^ ) disp( ------------------------------------------ ) disp(err) savepdf( hw5_pa.pdf,,)

4. Consider again the BVP in problem, but now using a Chebyshev spectral method. (a) By modifying the m-file cheb.m produce an m-file [D,x] = cheb(n) that produces grid points for the interval [, ] instead of [, ], and an appropriately modified differentiation matrix D. Note that this can be done by applying the linear mapping x (x+)/ to the grid points and then applying the chain rule to compute the modified D. Include a copy of your code. (b) Repeat parts (a) and (b) of problem using a spectral scheme but now with N = n with n =,, 4, 5. Produce a separate plot with four images for each ɛ. In addition, plot the log of the infinity-norm errors for both values of ɛ together on the same plot. Discuss the results in relation to those in problem using a finite difference scheme. ANS: (a) We now recompute the BVP from problem using our spectral method for the interval [, ]. Here are the solution profiles for ɛ =., and the infinity norm errors given N=4 eps=. N=8 eps=..5.5 N=6 eps=. N= eps=..5.5 by N inf_err --------------------------- 4.e+.566e- 8.e+.99e-7.6e+.9984e-5.e+.88e-4

Now with ɛ = we have N=4 eps=. N=8 eps=..5.5 N=6 eps=. N= eps=..5.5 N inf_err --------------------------- 4.e+ 7.84e- 8.e+.877e-.6e+ 5.644e-5.e+.98e-4 Putting the results from both the FD and spectral method together we have Here is the code for cheb followed by the BVP solver: % CHEB compute D = differentiation matrix, x = Chebyshev grid % for the interval [,] from right to left function [D,x] = cheb(n) if N==, D=; x=; return, end x = cos(pi*(:n)/n) ; c = [; ones(n-,); ].*(-).^(:N) ; X = repmat(x,,n+); dx = X-X ; D = (c*(./c) )./(dx+(eye(n+))); % off-diagonal entries D = D - diag(sum(d )); % diagonal entries x = (x+)/; D=*D; % mapping to account for [- ] ->[,]

Error: FD vs. SPECTRAL for solving BVP Infinity norm error 5 5 FD eps =. FD eps =. SPEC eps =. SPEC eps =. 5 5 5 N N =.^(:5); epsilon = ^(-); xx = :.5:; % compute true solution uu on fine grid xx uu = *xx+-(sinh((-xx)/sqrt(epsilon))+ *sinh(xx/sqrt(epsilon)))/sinh(/sqrt(epsilon)); err=zeros(4,); % compute approx for each N, plot, and store error for k=:length(n) n = N(k); [D,x] = cheb(n); D = D^; D = D(:n,:n); f = *x(:n)+; v = [-epsilon*d+eye(n-)]\f; v = [ v ] ; subplot(,,k), plot(xx,uu,x,v, *- ), axis([-.5.5.]), grid title([ N=,numstr(n), eps=,numstr(epsilon)]) u = *x+-(sinh((-x)/sqrt(epsilon))+*sinh(x/sqrt(epsilon)))/sinh(/sqrt(epsilon)); err(k,) = n; err(k,) = norm(u-v,inf); end hold off, format short e disp( N inf_err ) disp( --------------------------- ) disp(err)