Question

Write a program for solving the system Ar-b by using Gauss-Seidel iterative method discussed in class that uses a computer me

PLEASE USE MATLAB. The code is basically given to you with the algorithm above.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

MATLAB Script (run it as a script, NOT from command window):

close all
clear
clc

n = 2;
a = [16 3; 7 -11];
b = [11 13];
x = [1 1];
N = 1000;
TOL = 1e-6;
[delta, x, k] = gauss_siedel(n,a,b,x,N,TOL)

function [delta, x, k] = gauss_siedel(n,a,b,x,N,TOL)
% n - size of system
% a - matrix
% b - vector [b(1) to b(n)]
% x - initial guess [x(1) to x(n)]
% N - max number of iterations
% TOL - tolerance
  
k = 0; delta = 10;
while k < N && delta > TOL
delta = 0.0;
norm = 0.0;
k = k + 1;
for i = 1:n
xnew = b(i) - sum(a(i,1:i-1).*x(1:i-1)) - sum(a(i,i+1:n).*x(i+1:n));
xnew = xnew / a(i,i);
norm = max(norm, abs(xnew));
delta = max(delta, abs(xnew - x(i)));
x(i) = xnew;
end
delta = delta/norm;
end
end

Output:

delta =
1.4813e-07
x =
0.8122 -0.6650
k =
9

Add a comment
Know the answer?
Add Answer to:
PLEASE USE MATLAB. The code is basically given to you with the algorithm above. Write a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. [12 marks] In the following parts of this question, write a MATLAB code to solve a linear syst...

    1. [12 marks] In the following parts of this question, write a MATLAB code to solve a linear system A b (A is a square nonsingular matrix) using Jacobi and Gauss-Seidel algorithms. Do not use the built-in Matlab functions for solving linear systems (a) Write a Matlab function called Jacobi that consumes a square n x n matrix A, and an n x 1 vector b, and uses the Jacobi technique to solve the system Ax-b, starting with the zero...

  • in MATLAB 3. Write a function called gauss_seidel that inputs an n x n matrix, A,...

    in MATLAB 3. Write a function called gauss_seidel that inputs an n x n matrix, A, a column vector, b, an initial guess xo), an error tolerance e, and a maximum number of iterations, and output an approximate solution obtained using the Gauss-Seidel method, the error and the number of iterations. The header should look like (x, err, N] = gauss_seidel (A, b, x0, tol, Nmax). Use the method to find approximate solutions to the linear system -2 1 0...

  • matlab 1. Given the system of equations 9 + x2 +x3 +x4 = 75 xi +8x2 x3x54 X1+X1 +7X3 + X4 = 43 xi+x2 +x6x434 Write a...

    matlab 1. Given the system of equations 9 + x2 +x3 +x4 = 75 xi +8x2 x3x54 X1+X1 +7X3 + X4 = 43 xi+x2 +x6x434 Write a code to find the solution of linear equations using a) Gauss elimination method b) Gauss-Seidel iterative method c) Jacobi's iterative method d) Compare the number of iterations required for b) and c) to the exact solution Assume an initial guess of the solution as (X1, X2, X3, X4) = (0,0,0,0).

  • Complete Textbook problem 9.18 using Matlab (you can use a 10^-6 as your tolerance) a. Format...

    Complete Textbook problem 9.18 using Matlab (you can use a 10^-6 as your tolerance) a. Format your function such that [x] = lastname_firstname_GaussPivot(A, b). Submit your original M-file. Develop, debug, and test a program in either a high-level language or macro language of your choice to solve a system of equations with Gauss elimination with partial pivoting. Base the program on the pseudocode from Fig. 9.6. Test the program using the following system (which has an answer of x_1 =...

  • This is Matlab Problem and I'll attach problem1 and its answer for reference. We were unable...

    This is Matlab Problem and I'll attach problem1 and its answer for reference. We were unable to transcribe this imageNewton's Method We have already seen the bisection method, which is an iterative root-finding method. The Newton Rhapson method (Newton's method) is another iterative root-finding method. The method is geometrically motivated and uses the derivative to find roots. It has the advantage that it is very fast (generally faster than bisection) and works on problems with double (repeated) roots, where the...

  • 1" (20%) (Linear systems) Given a linear system C1 +33 2 One can convert it into an iterative for...

    Relevant Information: 1" (20%) (Linear systems) Given a linear system C1 +33 2 One can convert it into an iterative formula x(n+1) TX(m) + c where X(n) = (a (n),X(n), a (n))t įs the approximated solution at the nth iteration, T3x3 is the iterative matrix and caxi is the vector associated with the correspondent iterative method. (a) (5 %) Compute the associated matrix T and vector c associated with Jacobi method. (b) (5 %) Compute (T) and determine if Jacobi...

  • I am new to Matlab so details would be appreciated! Use Matlab or any other Language...

    I am new to Matlab so details would be appreciated! Use Matlab or any other Language /Tool to implement the project work Algorithm for Gauss-Seidel Method to solve the linear (n x n) system Ax = b in matrix form is given by x(0) = initial vector x(4+1) = D-1 (b – Lx(k+1) – Ux(k)), k = 0, 1, 2, ...... where A = L+D+U. Here L, D, U are respectively lower, diag- onal and upper matrices constructed from A....

  • Question 1 (10 marks) For a linear system Ax- b with 1 0 -1 A-1 2-1 2 -1 3 b=14 18 and compute by...

    Please do question 5 for me. Thanks Question 1 (10 marks) For a linear system Ax- b with 1 0 -1 A-1 2-1 2 -1 3 b=14 18 and compute by hand the first four iterations with the Jacobi method, using x()0 Hint: for the ease of calculation, keep to rational fractions rather than decimals Question 2 For the same linear system as in Question 1, compute by hand the first three iterations (10 marks) with the Gauss Seidel method,...

  • just 1,2,4 Problem 1 Consider the linear system of equations Ax = b, where x €...

    just 1,2,4 Problem 1 Consider the linear system of equations Ax = b, where x € R4X1, and A= 120 b = and h= 0.1. [2+d -1 0 0 1 1 -1 2+d -1 0 h2 0 -1 2 + 1 Lo 0 -1 2+d] 1. Is the above matrix diagonally dominant? Why 2. Use hand calculations to solve the linear system Ax = b with d=1 with the following methods: (a) Gaussian elimination. (b) LU decomposition. Use MATLAB (L,...

  • Question 1 (10 marks) For a linear system Ax b with 1 0-1 A-1 2-1 2-13 and b4 18 compute by hand ...

    Question 1 (10 marks) For a linear system Ax b with 1 0-1 A-1 2-1 2-13 and b4 18 compute by hand the first four iterations with the Jacobi method, usg0 Hint: for the ease of calculation, keep to rational fractions rather than decimals. (10 marks) Question 2 For the same linear svstem as in Question 1. compute by hand the first three iterations with the Gauss Seidel method, us0 Hint: for the ease of calculation, keep to rational fractions...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT