You are on page 1of 1

2.

Input
% create size variables and error message % along with Mat containing A and b A = input ('desired coefficient matrix='); b = input ('desired right hand side vector='); [r,c] = size(A); if r~=c, error('Matrix A must be square'); end nb = c+1; Aug = [A b]; % forward elimination for i = 1:c-1 for j = i+1:c factor = Aug(j,i)/Aug(i,i); Aug(j,i:nb) = Aug(j,i:nb)-factor*Aug(i,i:nb); end end % back substitution x = zeros(c,1); x(c) = Aug(c,nb)/Aug(c,c); for i = c-1:-1:1 x(i) = (Aug(i,nb)-Aug(i,i+1:c)*x(i+1:c))/Aug(i,i); end disp (x)

Output >> gauss_naive desired coefficient matrix=[2,6,10;3,14,28;1,3,3] desired right hand side vector=[0;-8;2] 2 1 -1 3. Input -- same as #2 Output --gauss_naive desired coefficient matrix=[((10^-4)^2) 1; 1 1] desired right hand side vector=[1;0] -1.0000 1.0000 Output-- gauss_naive desired coefficient matrix=[((10^-8)^2) 1; 1 1] desired right hand side vector=[1;0] -2.2204 1.0000