1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
function [x2] = assignment4(A,b,x1,error)
[A_row,A_col] = size(A); e=1; x2=x1;
while e>error for i1=1:A_row x2(i1)=b(i1); for i2=1:A_col if i1~=i2 x2(i1)=x2(i1)-x2(i2)*A(i1,i2); end end x2(i1)=x2(i1)/A(i1,i1); end e=x2(1)-x1(1); for i1=2:A_row if x2(i1)-x1(i1)>e e=x2(i1)-x1(i1); end end x1=x2; end end
|