1 Jacobi and Gauss-Seidel 1. Write the following MATLAB program function [k, xk]
ID: 2984826 • Letter: 1
Question
1 Jacobi and Gauss-Seidel 1. Write the following MATLAB programfunction [k, xk]=GsSd(A, b, x0, n, eps,kmax)
function [k, xk]=Jcb(A, b, x0, n, eps,kmax) Input: A, b, x0 (initial iteration) n (number of unknowns), eps, kmax (number of iterations < kmax) Output: k (number of iterations), xk is such that (kx(k) x(k 1)k < eps) 2. eps = 0.00001 n = 4; d = 2 * ones(1; n); a = -ones(1; n - 1); c = -ones(1; n - 1); b = 0 * ones(1; n); b(1) = 1; b(n) = 1; x0 = rand(1; n) * 10^(-4), where x0 is your initial guess.
The solution of Ax = b with
A = diag(a;-1) + diag(d; 0) + diag(c; 1)
should be
x = ones(1; n).
1 Jacobi and Gauss-Seidel 1. Write the following MATLAB program
function [k, xk]=GsSd(A, b, x0, n, eps,kmax)
function [k, xk]=Jcb(A, b, x0, n, eps,kmax) Input: A, b, x0 (initial iteration) n (number of unknowns), eps, kmax (number of iterations < kmax) Output: k (number of iterations), xk is such that (kx(k) x(k 1)k < eps) 2. eps = 0.00001 n = 4; d = 2 * ones(1; n); a = -ones(1; n - 1); c = -ones(1; n - 1); b = 0 * ones(1; n); b(1) = 1; b(n) = 1; x0 = rand(1; n) * 10^(-4), where x0 is your initial guess.
The solution of Ax = b with
A = diag(a;-1) + diag(d; 0) + diag(c; 1)
should be
x = ones(1; n).
Explanation / Answer
www.physicsforums.com/showthread.php?t=510119 -
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.