Answered step by step
Verified Expert Solution
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
PLEASE USE MATLAB AND DONT COPY SOMEONE ELSES ANSWER!!!
Problem
Consider the linear system where is an matrix with s on the main diagonal, s
directly above and below the main diagonal and s everywhere else. For example,
This is a discretized version of Poisson's equation
which appears very often in physical applications. We will discuss discretizations and differential equations,
including the origin of the matrix later in the class.
Setting up the matrix:
a Construct the matrix in MATLABpythonYou should be able to do this in only a few
lines of code with the help of the diag or npdiag function. In particular, you should figure
out what the commands diagdiag and diag do when is a vector or
array. Save a copy of this matrix in a variable named Aremember in python you need to use
A A
b Now construct the right hand side vector This should be a vector such that the th
entry of is
Save a copy of this vector in a variable named Aremember in python you need to use
Jacobi method:
a The Jacobi method for this problem can be written as where is a
matrix that we discussed in lecture. Note that in this equation means the guess for the
vector and it is an entire vector. It does not mean the th entry of Use the Jacobi method
to solve for Your initialization should be a vector of all ones, and you should use a
tolerance of That is you should stop when max using the abs and
max functions. Save a copy of your final iteration in a column vector named A Save
the total number of iterations required including the initial iteration in a variable named A
b The true solution to the system of equations is the vector whose entry is
defined according to the formula
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 A
GaussSeidel method:
a The GaussSeidel method for this problem can be written as where is a
matrix that we discussed in lecture. Use the GaussSeidel method to solve for Your
initial iteration should be a vector of all ones, and you should use a tolerance of
Save a copy of your final iteration in a column vector named A Save the total number
of iterations required including the initial iteration in a variable named A
b To test the efficacy of the GaussSeidel 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 A
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started