Question: I'm trying to write a code for gauss elimination with partial pivoting in MATLAB. But I have a problem with consulting the pseudocode. My matrices(a

I'm trying to write a code for gauss elimination with partial pivoting in MATLAB.

But I have a problem with consulting the pseudocode.

My matrices(a and b) are I'm trying to write a code for gauss elimination with partial pivoting .

My n is 3 and tol is 10^-15.

and I get an answer 0, 0, 36.5689 which is wrong.

correct answer is 1,1,1.

please help me with my MATLAB code.

in MATLAB. But I have a problem with consulting the pseudocode. My

function [x] = Gauss(a,b,n,tol) s = zeros(1,n); er = 0; for i = 1:n s(i) = abs(a(i,1)); for j = 2:n if abs(a(i,j)) > s(i) s(i) = abs(a(i,j)); end end [a, b] = Eliminate(a,s,n,b,tol); if er ~= -1 [x] = Substitute(a,n,b); end end end

function [a,b] = Eliminate(a,s,n,b,tol) for k = 1:n-1 [a,b,s] = Pivot(a,b,s,n,k); if abs(a(k,k)/s(k))

function [a,b,s] = Pivot(a,b,s,n,k) p = k; big = abs(a(k,k)/s(k)); for ii = k+1:n dummy = abs(a(ii,k)/s(ii)); if dummy > big big = dummy; p = ii; end end if p ~= k for jj = k:n dummy = a(p,jj); a(p,jj) = a(k,jj); a(k,jj) = dummy; end dummy = b(p); b(p) = b(k); b(k) = dummy; dummy = s(p); s(p) = s(k); s(k) = dummy; end end

function [x] = Substitute(a,n,b) x(n) = b(n)/a(n,n); for i = n-1:1:-1 sum = 0; for j = i+1:n sum = sum + a(i,j)*x(j); end x(n) = (b(n)-sum)/a(n,n); end end

71 2 -1 52 2 |-35 -1 91 71 2 -1 52 2 |-35 -1 91

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!