Hello Help Find Matlab Solution System X B Modify File Gauss Partial Pivoting Gauss Comple Q43877115
Hello, Can you help me to find in MATLAB the solution of thesystem A x= b and then modify my file of gauss partial pivotinginto gauss complete pivoting.
So I’m guessing that I have to use the file of gauss partialpivoting to answer to A x= b but I don’t know what I have to changeto have the right answer.
I have
A =
-2.1000 -0.5000 -0.9000 -1.9000 1.2000 0.1000
0.6000 0 -1.9000 2.4000 -1.7000 0.2000
2.0000 -0.5000 0 -0.2000 0.4000 -0.5000
2.2000 0.1000 -1.2000 0.4000 0.5000 0.7000
3.3800 0.6400 -3.4100 4.0800 -1.8900 1.4600
-0.2300 -0.1900 0.2300 2.6700 -2.7600 -1.1300
-0.6400-0.1400 -1.0500 0.0200 -0.0200 0.2200
b =
-0.8000
-0.8000
0.7000
1.7000
1.4000
-2.3600
-0.4600
I found
x =
0.6183
0
0.3084
-0.3447
0
1.2110
simply with the function x=AB but I can’t compile any goodfunction to find this answer …
And here is the gauss partial pivoting
function x=mygausspivot(A,b)
if size(A,1) ~= size(A,2)
error(‘Matrix is notsquare!)’);
end;
n=size(A,1);
% Matrix triangualisation:
for i=1:n
% Searching for thepivoting line
% disp([ ‘Treatment ofline i=’ num2str(i) ] );
n_max=i;
for m=i:n
if abs(A(n_max,i)) < abs(A(m,i))
n_max=m;
end
end
% disp([ ‘Line with pivoting element n_max=’num2str(n_max) ] );
% exchangement of line iand pivoting line n_max in the matrix A and in the vector b
for l=i:n
tmp=A(i,l);
A(i,l)=A(n_max,l);
A(n_max,l)=tmp;
end
tmp=b(i);
b(i)=b(n_max);
b(n_max)=tmp;
p=A(i,i); % pivotingelement
% verification ofnon-generation of matrix
if p==0
disp(‘Pivoting element is zero (matrix could bedegenerated)!!!’);
% error(‘Pivoting element is zero (matrix degenerated?)’);
end
for k=i:n
A(i,k)=A(i,k)/p;
end
b(i)=b(i)/p;
for j=i+1:n
r=A(j,i);
for k=i:n
A(j,k)=A(j,k)-A(i,k)*r;
end
b(j)=b(j)-b(i)*r;
end
end
% In this point our matrix is, normally, uppertriangular
% (with ones on the diaganonal),
% and we solving the folowing liniarequation:
% 1 a_12 …a_1N x_1 b_1
% 0 1 …a_2N * x_2 = b_2
% 0 0 ……… . .
% 0 0 …1 x_N b_N
% x calculation from triangular matrix:
x=b;
for i=n-1:-1:1
for k=i+1:n
x(i)=x(i)-x(k)*A(i,k);
end
end
% now x containes the solution
end
Thanks
Expert Answer
Answer to Hello, Can you help me to find in MATLAB the solution of the system A x= b and then modify my file of gauss partial pivo…
OR