[X,Y] = meshgrid(-3*pi-1:0.005:3*pi+1,-4:0.005:4);
Z = 0.5.*Y.*Y-cos(X)+1;

hold on;
[C,h] = contour(X,Y,Z,[2 2]);

P = zeros(7,2);
P(:,1)=linspace(-3*pi,3*pi,7);
plot(P(:,1),P(:,2),'.','Color','black');


t_null= 0;
b = 0.1; %súrlódás

StepSize=0.1;
NumOfSteps=1000;

EEuler=zeros(NumOfSteps,2);

time=zeros(NumOfSteps,1);
time(1)=t_null;

for a=1:(NumOfSteps-1)
    time(a+1)=time(a)+StepSize;
end

%%%%%%%%%
%
x_null= -10;
y_null= 3.5;

% Ide jon a megoldas
EEuler(1,1)=x_null; %kezdeti értékek
EEuler(1,2)=y_null;

for i=1:(NumOfSteps-1)
EEuler(i+1,1)=EEuler(i,1)+StepSize*EEuler(i,2);
EEuler(i+1,2)=EEuler(i,2)-StepSize*sin(EEuler(i,1))-StepSize*b*EEuler(i,2);
end


plot(EEuler(:,1),EEuler(:,2),'red');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

x_null= -10;
y_null= 2.5;

% Ide jon a megoldas
EEuler(1,1)=x_null;
EEuler(1,2)=y_null;

for i=1:(NumOfSteps-1)
EEuler(i+1,1)=EEuler(i,1)+StepSize*EEuler(i,2);
EEuler(i+1,2)=EEuler(i,2)-StepSize*sin(EEuler(i,1))-StepSize*b*EEuler(i,2);
end

plot(EEuler(:,1),EEuler(:,2),'magenta');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

x_null= -10;
y_null= 2;

% Ide jon a megoldas
EEuler(1,1)=x_null;
EEuler(1,2)=y_null;

for i=1:(NumOfSteps-1)
EEuler(i+1,1)=EEuler(i,1)+StepSize*EEuler(i,2);
EEuler(i+1,2)=EEuler(i,2)-StepSize*sin(EEuler(i,1))-StepSize*b*EEuler(i,2);
end

plot(EEuler(:,1),EEuler(:,2),'blue');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

x_null= -10;
y_null= 1.5;

% Ide jon a megoldas
EEuler(1,1)=x_null;
EEuler(1,2)=y_null;

for i=1:(NumOfSteps-1)
EEuler(i+1,1)=EEuler(i,1)+StepSize*EEuler(i,2);
EEuler(i+1,2)=EEuler(i,2)-StepSize*sin(EEuler(i,1))-StepSize*b*EEuler(i,2);
end

plot(EEuler(:,1),EEuler(:,2),'cyan');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

x_null= 10;
y_null= -3.5;

% Ide jon a megoldas
EEuler(1,1)=x_null;
EEuler(1,2)=y_null;

for i=1:(NumOfSteps-1)
EEuler(i+1,1)=EEuler(i,1)+StepSize*EEuler(i,2);
EEuler(i+1,2)=EEuler(i,2)-StepSize*sin(EEuler(i,1))-StepSize*b*EEuler(i,2);
end

plot(EEuler(:,1),EEuler(:,2),'red');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

x_null= 10;
y_null= -2.5;

% Ide jon a megoldas
EEuler(1,1)=x_null;
EEuler(1,2)=y_null;

for i=1:(NumOfSteps-1)
EEuler(i+1,1)=EEuler(i,1)+StepSize*EEuler(i,2);
EEuler(i+1,2)=EEuler(i,2)-StepSize*sin(EEuler(i,1))-StepSize*b*EEuler(i,2);
end

plot(EEuler(:,1),EEuler(:,2),'magenta');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

x_null= 10;
y_null= -2;

% Ide jon a megoldas
EEuler(1,1)=x_null;
EEuler(1,2)=y_null;

for i=1:(NumOfSteps-1)
EEuler(i+1,1)=EEuler(i,1)+StepSize*EEuler(i,2);
EEuler(i+1,2)=EEuler(i,2)-StepSize*sin(EEuler(i,1))-StepSize*b*EEuler(i,2);
end

plot(EEuler(:,1),EEuler(:,2),'blue');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

x_null= 10;
y_null= -1.5;

% Ide jon a megoldas
EEuler(1,1)=x_null;
EEuler(1,2)=y_null;

for i=1:(NumOfSteps-1)
EEuler(i+1,1)=EEuler(i,1)+StepSize*EEuler(i,2);
EEuler(i+1,2)=EEuler(i,2)-StepSize*sin(EEuler(i,1))-StepSize*b*EEuler(i,2);
end

plot(EEuler(:,1),EEuler(:,2),'cyan');

hold off;
%}

%közelítés instabilhoz rózsaszínben
%{
x_null= -10;
y_null= 2.12:-0.001:2.11;

% Ide jon a megoldas
for j=1:length(y_null)
EEuler(1,1)=x_null;
EEuler(1,2)=y_null(j);

for i=1:(NumOfSteps-1)
EEuler(i+1,1)=EEuler(i,1)+StepSize*EEuler(i,2);
EEuler(i+1,2)=EEuler(i,2)-StepSize*sin(EEuler(i,1))-StepSize*b*EEuler(i,2);
end
plot(EEuler(:,1),EEuler(:,2),'magenta');
end
%}
hold off;
