Skip to content

Commit 52d960f

Browse files
authored
Add files via upload
1 parent 8ab1e3a commit 52d960f

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

Pràctica 3/exempleSOR.m

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
A = readmatrix('matriu-A.dat.txt');
2+
n = sqrt(length(A));
3+
A= reshape(A,n,n);
4+
5+
6+
D = diag(diag(A));
7+
L = tril(A,-1);
8+
U = triu(A,+1);
9+
10+
%find() per trobar max i min.
11+
for i=1:2000
12+
omega(i)= 0.001*i;
13+
Bomega= inv(D+omega(i)*L)*((1-omega(i))*D-omega(i)*U);
14+
rho = max(abs(eig(Bomega)));
15+
scatter(omega(i),rho,'b','filled');
16+
hold on;
17+
end
18+
hold off;

Pràctica 3/gaussS.m

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
function [x,rho,res,iter] = gaussS(A,b,x0,nmax,prec)
32
format long
43
%A = input('Enter the A matrix in brackets this way [x; x; x; x;] ')
@@ -24,8 +23,8 @@
2423
end
2524
D = diag(diag(A));
2625
L = tril(A,-1);
27-
B =(D+w.*L)*((1-w).*D-w.*U);
28-
c = w.*inv(L+D)*b;
26+
B =eye(n) - (inv(L+D)*A);
27+
c = inv(L+D)*b;
2928
x = x0;
3029
rho = max(abs(eig(B)))
3130
if(rho >= 1)

Pràctica 3/iterativemethods.m

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@
7373
end
7474
D = diag(diag(A));
7575
L = tril(A,-1);
76-
B =(D+w.*L)*((1-w).*D-w.*U);
77-
c = w.*inv(L+D)*b;
76+
B =eye(n) - (inv(L+D)*A);
77+
c = inv(L+D)*b;
7878
x = x0;
7979
rho = max(abs(eig(B)))
8080
if(rho >= 1)
@@ -124,8 +124,8 @@
124124
end
125125
D = diag(diag(A));
126126
L = tril(A,-1);
127-
B = eye(n) - (inv(D)*A);
128-
c = inv(D)*b;
127+
B =(D+w.*L)*((1-w).*D-w.*U);
128+
c = w.*inv(L+D)*b;
129129
suma = 0;
130130
x = x0;
131131
rho = max(abs(eig(B)))

0 commit comments

Comments
 (0)