MATLAB!!!

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

MATLAB!!!

Post by answerhappygod »

MATLAB!!!
Matlab 1
Matlab 1 (89.55 KiB) Viewed 12 times
Matlab 2
Matlab 2 (130.74 KiB) Viewed 12 times
3. Using the Jacobi and Gauss-Seidel Methods: Consider the linear system An​ϕ= ρ, where An​ is an n×n 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−1000​−12−100​0−12−10​00−12−1​000−12​⎦⎤​ This is a discretized version of Poisson's equation dx2d2ϕ(x)​=ρ(x) which appears very often in physical applications. We will discuss discretizations and differential equations, including the origin of the matrix An​, later on in the quarter. Setting up the problem: (a) Construct the matrix A48​. You should be able to do this using the diag function. Save this matrix as A5. (b) Now construct the right hand side vector ρ. Thus will be a 48×1 vector such that the j th entry of ρ is ρj​=2(1−cos(4953π​))sin(4953πj​). Save this vector as A6. Using the Jacobi Method:
(c) The Jacobi method for this problem can be written as ϕk​=Mϕk−1​+c, where M is a 48×48 matrix like in the matrix iteration lecture. (Note that ϕk​ in this equation means the k th 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 48×1 vector of all ones, and you should use a tolerance of 10−5 or 1e−5 in MATLAB. That is, you should stop when ∥ϕk​−ϕk−1​∥<10−5 using the norm() function. Save a copy of your final iteration in a 48×1 column vector named A7. Save the total number of iterations required (including the initial iteration) in a variable named A8. (d) The true solution to the system of equations Aϕ=ρ is the 48×1 vector ϕ whose j th entry is defined according to the formula ϕj​=sin(4953πj​). To test the efficacy of the Jacobi method on this problem, find the error between your final iteration from part (c) and the true solution using the norm() function. Save your result in a variable named A9. (e) Repeat parts (c) and (d) for a tolerance of 10−8. Save a copy of your final iteration in a 48×1 column vector named A10. Save the total number of iterations required (including the initial iteration) in a variable named A11. Find the error between your final iteration and the true solution using the norm() function. Save your result in a variable named A12. Using the Gauss-Seidel Method: (f) The Gauss-Seidel method for this problem can also be written as ϕk​=Mϕk​−1+c, where M is a 48×48 matrix like in the matrix iteration lecture. Use the GaussSeidel method to solve for ϕ. Again, your initialization should be a 48×1 vector of all ones, and you should use a tolerance of 10−5. Save a copy of your final iteration in a 48×1 column vector named A13. Save the total number of iterations required (including the initial iteration) in a variable named A14. (g) To test the efficacy of the Gauss-Seidel method on this problem, find the error between your final iteration from part (f) and the true solution using the norm() function. Save your result in a variable named A15. (h) Repeat parts (f) and ( g) for a tolerance of 10−8. Save a copy of your final iteration in a 48×1 column vector named A16. Save the total number of iterations required (including the initial iteration) in a variable named A17. Find the error between your final iteration and the true solution using the norm() function. Save your result in a variable named A18.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply