Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE USE MATLAB AND DONT COPY SOMEONE ELSES ANSWER!!!Problem 3 Consider the linear system A n = , where A n is an n n

PLEASE USE MATLAB AND DONT COPY SOMEONE ELSES ANSWER!!!Problem 3
Consider the linear system An=, where An is an nn matrix with 2's on the main diagonal, -1's
directly above and below the main diagonal and 0's everywhere else. For example,
A5=([2,-1,0,0,0],[-1,2,-1,0,0],[0,-1,2,-1,0],[0,0,-1,2,-1],[0,0,0,-1,2]).
This is a discretized version of Poisson's equation
d2(x)dx2=(x),
which appears very often in physical applications. We will discuss discretizations and differential equations,
including the origin of the matrix An, later in the class.
(1) Setting up the matrix:
(a) Construct the matrix A114 in MATLAB/python.(You should be able to do this in only a few
lines of code with the help of the diag or np.diag function. In particular, you should figure
out what the commands diag(v),diag(v,1) and diag(v,-1) do when v is a vector or 1D
array.) Save a copy of this matrix in a variable named A9(remember, in python you need to use
A9= A *copy().
(b) Now construct the right hand side vector . This should be a 1141 vector such that the j th
entry of is
j=2(1-cos(53115))sin(53j115)
Save a copy of this vector in a variable named A10(remember, in python you need to use
A10=*copy().
(2) Jacobi method:
(a) The Jacobi method for this problem can be written as k=Mk-1+c, where M is a 114114
matrix that we discussed in lecture. (Note that k in this equation means the kth guess for the
vector and it is an entire vector. It does not mean the k th entry of ). Use the Jacobi method
to solve for . Your initialization should be a 1141 vector of all ones, and you should use a
tolerance of 10-5. That is, you should stop when max|k-k-1|10-5 using the abs () and
max() functions. Save a copy of your final iteration in a 1141 column vector named A11. Save
the total number of iterations required (including the initial iteration) in a variable named A12.
(b) The true solution to the system of equations A= is the 1141 vector whose jth entry is
defined according to the formula
j=sin(53j115).
To test the efficacy of the Jacobi method on this problem, find the maximum error in absolute
value between your final iteration and the true solution using the abs() and max() functions.
Save your result in a variable named A13.
(3) Gauss-Seidel method:
(a) The Gauss-Seidel method for this problem can be written as k=Mk-1+c, where M is a
114114 matrix that we discussed in lecture. Use the Gauss-Seidel method to solve for . Your
initial iteration should be a 1141 vector of all ones, and you should use a tolerance of 10-5.
Save a copy of your final iteration in a 1141 column vector named A14. Save the total number
of iterations required (including the initial iteration) in a variable named A15.
(b) To test the efficacy of the Gauss-Seidel method on this problem, find the maximum error in
absolute value between your final iteration and the true solution from the previous part. Save
your result in a variable named A16.
image text in transcribed

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_2

Step: 3

blur-text-image_3

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

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions