Stuff
parent
6b3808900a
commit
f902cd3073
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,26 @@
|
|||
function [Q, R] = opgave1(A)
|
||||
[m, n] = size(A);
|
||||
Q = eye(m);
|
||||
R = A;
|
||||
|
||||
for j = 1:n
|
||||
for i = m:-1:j+1
|
||||
X = [R(i - 1, j); R(i, j)];
|
||||
[G, Y] = planerot(X);
|
||||
R(i - 1, j) = Y(1);
|
||||
R(i, j) = Y(2);
|
||||
|
||||
for k = j+1:n
|
||||
Y = G * [R(i - 1, k); R(i, k)];
|
||||
R(i - 1, k) = Y(1);
|
||||
R(i, k) = Y(2);
|
||||
end
|
||||
|
||||
for k = 1:m
|
||||
Y = [Q(k, i - 1), Q(k, i)] * G.';
|
||||
Q(k, i - 1) = Y(1);
|
||||
Q(k, i) = Y(2);
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,9 @@
|
|||
function N = opgave6(A)
|
||||
[m, n] = size(A);
|
||||
|
||||
for i = 1:n
|
||||
col = A(:, i);
|
||||
s = sum(col);
|
||||
N(:, i) = arrayfun(@(x) x / s, col);
|
||||
end
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
function B = opgave7(A, q)
|
||||
[m, n] = size(A);
|
||||
c = 1;
|
||||
B = [];
|
||||
|
||||
for i = 1:n
|
||||
A(:, i)
|
||||
q
|
||||
theta = subspace(A(:, i), q)
|
||||
if theta < pi / 4
|
||||
B(c) = i;
|
||||
c = c + 1;
|
||||
end
|
||||
end
|
||||
end
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,7 @@
|
|||
# Opgave 8
|
||||
|
||||
De convergentie is in beide gevallen lineair.
|
||||
|
||||
# Opgave 9
|
||||
|
||||
728 iteraties nodig. Voor $eps^{20}$ zou je dan $728 * 20$ iteraties nodig hebben.
|
|
@ -0,0 +1,21 @@
|
|||
function [eigen, resid] = opgave10(A, tol)
|
||||
[m, _] = size(A);
|
||||
A = hess(A);
|
||||
|
||||
k = 1;
|
||||
resid(k) = norm(tril(A, -1), 'fro');
|
||||
|
||||
for n = m:-1:2
|
||||
while abs(A(n, n - 1)) > tol
|
||||
kappa = A(n, n);
|
||||
[Q, R] = qr(A - kappa * eye(m));
|
||||
A = R * Q + kappa * eye(m);
|
||||
k = k + 1;
|
||||
resid(k) = norm(tril(A, -1), 'fro');
|
||||
end
|
||||
|
||||
A(n, n - 1) = 0;
|
||||
end
|
||||
|
||||
eigen = diag(A);
|
||||
end
|
|
@ -0,0 +1,21 @@
|
|||
[U, S, V] = svd(Z);
|
||||
|
||||
i = 1;
|
||||
|
||||
for k = 10:10:200
|
||||
Uk = U(:, 1:k);
|
||||
Vk = V(:, 1:k);
|
||||
Sk = S(1:k, 1:k);
|
||||
Zk = Uk * Sk * Vk';
|
||||
%if k == 10
|
||||
%imagesc(Zk)
|
||||
%end
|
||||
images = imagesc(Zk);
|
||||
relDiff(i) = norm(Z - Zk, 'fro') / norm(Z, 'fro');
|
||||
i = i + 1;
|
||||
k
|
||||
end
|
||||
|
||||
montage(images)
|
||||
|
||||
%semilogy(10:10:200, relDiff)
|
|
@ -0,0 +1,13 @@
|
|||
function [Ak, Bk] = testMatrix(k)
|
||||
|
||||
Lk = diag(1:k);
|
||||
|
||||
P1 = orth(rand(k, k));
|
||||
Ak = P1 * Lk * P1';
|
||||
|
||||
P2 = rand(k, k);
|
||||
Bk = P2 * Lk * inv(P2);
|
||||
|
||||
end
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
function [eigen, resid] = qrAlg(A, tol)
|
||||
k = 1;
|
||||
resid(k) = norm(tril(A, -1), 'fro');
|
||||
|
||||
while resid(k) > tol
|
||||
[Q, R] = qr(A);
|
||||
A = R * Q;
|
||||
k = k + 1;
|
||||
resid(k) = norm(tril(A, -1), 'fro');
|
||||
end
|
||||
|
||||
eigen = diag(A);
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
function [] = residplot(resid, p)
|
||||
for k = 1:length(resid)-1
|
||||
y(k) = resid(k)/(resid(k+1)^p);
|
||||
end
|
||||
|
||||
plot(y)
|
||||
end
|
|
@ -0,0 +1,13 @@
|
|||
function [Ak, Bk] = testMatrix(k)
|
||||
|
||||
Lk = diag(1:k);
|
||||
|
||||
P1 = orth(rand(k, k));
|
||||
Ak = P1 * Lk * P1';
|
||||
|
||||
P2 = rand(k, k);
|
||||
Bk = P2 * Lk * inv(P2);
|
||||
|
||||
end
|
||||
|
||||
|
|
@ -1 +1 @@
|
|||
Subproject commit b9148c91208e38281f135e67f75d99e21b4677f7
|
||||
Subproject commit c10d1417155f93eac7eff0899243b919af811d4c
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue