% Rydd opp
clc
clear
close

% Gram-Schmidt?
gs = 0;

% Matrise fra Forelesning 7 og 11 (Eksempel 5.1.4)
A = [4 -1 6; 2 1 6; 2 -1 8];

% Plotting av egenrommene
hold on
axis equal
I = -3:0.1:3;                   
[X Y] = meshgrid(I);
Z = (Y-2*X)/6;                  % Egenrommet til lambda1=lambda2=2.
surf(X,Y,Z)
plot3(I,I,I,'k','LineWidth',3)  % Egenrom til lambda3=9.

% Plotting av egenvektorer
J = 0:0.2:1;
if gs == 0
    v1 = [1; 2; 0]*J;
    plot3(v1(1,1:6),v1(2,1:6),v1(3,1:6),'k','LineWidth',5,'Color',[1 0 0])
    v2 = [-3; 0; 1]*J;
    plot3(v2(1,1:6),v2(2,1:6),v2(3,1:6),'k','LineWidth',5,'Color',[1 0 0])
    v3 = [1; 1; 1]*J;
    plot3(v3(1,1:6),v3(2,1:6),v3(3,1:6),'k','LineWidth',5,'Color',[1 0 0])
else
    v1 = [1; 2; 0]*J;
    plot3(v1(1,1:6),v1(2,1:6),v1(3,1:6),'k','LineWidth',5,'Color',[1 0 0])
    v2 = (1/5)*[-12; 6; 5]*J;
    plot3(v2(1,1:6),v2(2,1:6),v2(3,1:6),'k','LineWidth',5,'Color',[1 0 0])
    v3 = (1/205)*[70; -35; 210]*J;
    plot3(v3(1,1:6),v3(2,1:6),v3(3,1:6),'k','LineWidth',5,'Color',[1 0 0])
end