clear clc -3 -4 -5 -4 -1 -5 -9 -1 -9 00001 miter 100 for end for iter

 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
40
41
42
43
44
45
clear;
clc;
a=[-3 -4 -5;-4 -1 -5;1 5 1]
b=[-9;-1;-9]
e=0.00001;
n=3;
miter=100;
for i=1:n
x(i)=0;
end
for iter=1:miter
big=0;
for i=1:n
sum=0;
if i==1
for j=i+1:n
sum=sum+a(i,j)*x(j);
end
elseif i==n
for j=1:n-1
sum=sum+a(i,j)*x(j);
end
else
for j=1:i-1
sum=sum+a(i,j)*x(j);
end
for j=i+1:n
sum=sum+a(i,j)*x(j);
end
end
temp=(b(i)-sum)/a(i,i);
if abs(temp-x(i))>big
big=abs(temp-x(i));
end
x(i)=temp;
if big < e
niter=iter;
break;
end
end
end
disp('Решение');
x