52 lines
677 B
Matlab
52 lines
677 B
Matlab
t=(-1:0.1:1)';
|
|
A=[ones(size(t)) t t.^2]
|
|
b=(20:-1:0)'-t.^3
|
|
|
|
% Ax = b
|
|
% als x1 een kleinste kwadratenopl is dan staat b-Ax1 loodrecht
|
|
% op Ax1.
|
|
|
|
x1 = [10;-10.658;0]
|
|
x2 = [-10;8.28;2]
|
|
|
|
|
|
c = (b - A*x1 )'*(A*x1)
|
|
d = (b - A*x2)'*(A*x2)
|
|
|
|
% c is ongeveer nul
|
|
|
|
%% vraag 2
|
|
|
|
A = [1 1/2 0
|
|
1/2 2 -1/2
|
|
0 -1/2 -3]
|
|
|
|
[V D] = eig(A)
|
|
|
|
[w, m] = max(diag(D))
|
|
|
|
argmax = V(:,m)
|
|
|
|
|
|
%% vraag 3
|
|
|
|
t=-1:4
|
|
B=[t;ones(size(t));cos(pi*t);cos(pi/2*t);t.^2]/10
|
|
|
|
C= zeros(size(B))
|
|
|
|
for k=1:size(B, 1) % k tot #rijen van B
|
|
C(k,:) = 2 * B(k,:)/sqrt(B(k,:)*B(k,:)') % normeren van elke rij maal 2
|
|
end
|
|
|
|
% Zonder for-loop
|
|
|
|
C = diag(1./sqrt(diag(B*B')))*B
|
|
|
|
|
|
% Vraag 4
|
|
|
|
|
|
|
|
|
|
|