metode=4; %1=eksplisitt euler, 2=symplektisk euler, 3=implisitt euler, 4=trapesmetoden

n=200;
h=4*pi/n;

x=zeros(n,1);
y=zeros(n,1);

x(1)=1;
y(1)=1;

%eksplisitt euler
if metode==1
    for i=1:n-1
        x(i+1)=x(i)-h*y(i);
        y(i+1)=y(i)+h*x(i);
    end
end

%symplektisk euler
if metode==2
    for i=1:n-1
        x(i+1)=x(i)-h*y(i);
        y(i+1)=y(i)+h*x(i+1);
    end
end

%implisitt euler
if metode==3
    A=[1 h;-h 1];
    v=[x(1);y(1)];
    for i=1:n-1
        v=A\v;
        x(i+1)=v(1);
        y(i+1)=v(2);
    end
end

%trapesmetoden
if metode==4
    A=[1 h;-h 1];    
    for i=1:n-1
        v=[x(i)-h*y(i);y(i)+h*x(i)];
        v=A\v;
        x(i+1)=v(1);
        y(i+1)=v(2);
    end
end

plot(x,y);
