Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MATLAB code for problem 2 clear all close all clc format long % Array that stores different values of n N = [2,10,50,100:100:1000]; % Create

image text in transcribed

image text in transcribed

MATLAB code for problem 2

clear all close all clc format long % Array that stores different values of n N = [2,10,50,100:100:1000]; % Create matrix A and vector b based on the different n values for j = 1:length(N) n = N(j); e1 = ones(n,1); A = spdiags([-e1,2*e1,-e1],[-1,0,1],n,n); b = zeros(n,1); b(n) = 1; end

MATH 455: Numerical Analysis Homework 3 Due: February 21, 2020 Consider a finite sequence {Po, P1, ..., Pn, Pn+1}, where Po=0, Pn+1 = 1, and the intermediate elements satisfy the difference equation P+1, k=1,2,...n. The goal of this problem is to investigate the performance of using Jacobi's method and Gauss-Seidel method to compute P, through Pr. 1. Show that the difference equation is equivalent to the Ax = b system [ 2 -1 -1 2 -1 ... .. -1 -1 2] [PR [1] 2. [MATLAB Problem) Download the MATLAB script "hw3_template.m from Canvas. The for loop creates different sizes of A and b (n=2, 10, 50, etc.). A is set up using sparse storage, i.e. only the non-zero elements are stored. (a) Add two separate while loops inside the for loop to solve the linear system: one using Jacobi's method and one using Gauss-Seidel method. Use a tolerance level of 10-6. Use the zero vector as the initial guess for each method and for each n. You don't have to store the solution. Record in two arrays, e.g. iter-j and iter-gs, the number of iterations when the solution is successfully computed. Your script should take less than 2 minutes to run. (b) Add the following lines after the for loop: figure(1), plot (N, iter-j,'-o',N,iter-gs,'r-o'), grid on xlabel('Size of Problem'), ylabel('# of Iterations') legend('Jacobi', 'Gauss-Seidel') This plots the number of iterations versus the size of problem for both methods. Your graph should be similar to the one shown on the next page. Size of Problem 3. It was shown in class that both the Jacobi's method and Gauss-Seidel method can be written as Xi+1 = (I + M-N+...+(M-N)') M-'b+(M-?N)i+ xo, where xo is the initial guess, M is the diagonal (Jacobi's method) or lower triangular (Gauss- Seidel method) part of A , and N = M - A. The scheme converges from any Xo if and only if all eigenvalues of M-IN=I - M-1A have a magnitude that is strictly less than 1, i.e. P (I-M A)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Successful Keyword Searching Initiating Research On Popular Topics Using Electronic Databases

Authors: Randall MacDonald, Susan MacDonald

1st Edition

0313306761, 978-0313306761

More Books

Students also viewed these Databases questions

Question

Persuading Your Audience Strategies for

Answered: 1 week ago