Homework 4.pdf Fxit PhantomPOF GANIZE COMMENT VIEW FORM PROTECT SHARE HELP Fit P
ID: 3890760 • Letter: H
Question
Homework 4.pdf Fxit PhantomPOF GANIZE COMMENT VIEW FORM PROTECT SHARE HELP Fit Page a 161.20% . Fit WidthRotate Left Fit VisibleRotate Right Insert , Edt Edt Typewriter Note T StrikeoutRotae Text Objed Delte Quick OcR Suspect PDF underline pages*C&Extract; San . Results. Sign View Edit Comment Page Organization Convert Protedt -1 1 7x3 For both 'a, and .b, use the initial guess [00]r write a MATLAB function, called MyJacob, to solve the equation Ax = b using the Jacobi Method. The function should take the following inputs: [x,n] MyJacobi (A,b, x0, tol) 2. function .A-matrix of coefficients .b-solution vector (column vector) · x0-initial guess vector (column) .tol-desired tolerance level (e.g. 1 x 10-6 The output 'x should be the variables vector The output 'n' should be the number of iterations required to solve. . When your code is complete, use your program to check the solution to Problem 1, and include a printout (or screenshot) of the returned variables ('x and 'n'). Also include a printed copy of your function m-file. Hints .Refer to Example 4.3 in the Dunn textbook for inspiration. You do not need to program in all of the checks for proper function input and formatting (although you are more than welcome to). . You can use Equation 4.41 for a convenient equation to calculate 'xExplanation / Answer
function [x_1,n] = jacobi(a,b,x0,tol)
n = length(b);
x = zeros(n,1);
x_y = zeros(n,1);
for j = 1 : n
x(j) = ((b(j) - a(j,[1:j-1,j+1:n]) * x0([1:j-1,j+1:n])) / a(j,j)); % the first iteration
end
x_1 = x';
l = 1;
while norm(x_1-x0,1) > tol
for j = 1 : n
x_y(j) = ((b(j) - a(j,[1:j-1,j+1:n]) * x_1([1:j-1,j+1:n])) / a(j,j));
end
x0 = x_1;
x_1 = x_y';
l = l + 1;
end
l
x = x_1';
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.