%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%         1.gyakorlat         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Nemlin. din. rsz-ek alapjai %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%         2016.09.14.         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%clear all;
%close all;

% Paraméterek:
Xinit= -9;                 % x kezdeti értéke       %
Yinit= 2;                  % y kezdeti értéke       %
tinit=0;                   % kezdeti idõ            % EZEKET A PARAMÉTEREKET ÁLLÍTHATJUK
Max_Time= 1500;             % szimuláció ideje       % AZ ÜGYESEK GUI-T IS ÍRHATNAK HOZZÁ
b=2;                     % csillapítás            %
 
x =-10:0.05:10;            % Lehet módosítani, de felesleges
y =-4:0.05:4;              % Lehet módosítani, de felesleges
[X,Y] = meshgrid(x,y);     % hálót készít x,y vektorok alapján (az energiák kiszámításához az adott pontokban)

%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%          Ismétlés          %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%{
figure                                  % új ábra megjelenítése
plot(x,sin(x));                         % bõvíthetõ   'r' = 'red', 'r*'
waitforbuttonpress();
plot3(x,sin(x),cos(x))                  % 3D plot, 3 megegyezõ méretû paraméter
waitforbuttonpress();
figure
subplot(2,2,1:2)
text(0.5,0.5,' mert plotolni jó! subplot(2,2,1:2)',...
    'FontSize',14,'HorizontalAlignment','center')
subplot(2,2,3)
text(.5,.5,'és helpbõl elleshetõ - subplot(2,2,3)',...
    'FontSize',12,'HorizontalAlignment','center')
subplot(2,2,4)
text(.5,.5,'és megérthetõ - subplot(2,2,4)',...
    'FontSize',12,'HorizontalAlignment','center')
% hold on/off, xlabel('valami'), 
%}
% 0.1. feladat: Plotoljatok tetszõleges felosztású mezõket!


% 0.2. meshgrid megértése:
%{
% [X,Y] = meshgrid(1:3,10:14)
% X =
%      1     2     3
%      1     2     3
%      1     2     3
%      1     2     3
%      1     2     3
% Y =
%     10    10    10
%     11    11    11
%     12    12    12
%     13    13    13
%     14    14    14
waitforbuttonpress();
figure 
[X,Y] = meshgrid(-2:.2:2, -2:.2:2);                                
Z = X .* exp(-X.^2 - Y.^2);                                        
surf(X,Y,Z)
%}

% 0.3. contour megértése:
%{
load penny;                 % kép betöltése (P(128*128))
figure;
x = linspace(1,15,128);     % 1 és 15 között lineárisan elosztva generál 128 számot
y = linspace(1,15,128);
contour(x,y,flipud(P),50);  % flipud - matrix elemeinek tükrözése középsõ tengelyre 
                            % (kép fordítva van alapból)
axis square;                % egyenlõ tengelyfelosztás a képen
colormap('Bone');           % próbálhatod: Jet, pink, winter, ....
%}
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%          Feladatok          %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%         1. egyenlet         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

egyenlet_1=@(t, xy) [xy(2); -xy(1)];

energia_rugo=@(X, Y) (X.^2)/2+(Y.^2)/2;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%         2.egyenlet          %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

egyenlet_2=@(t, xy) [xy(2); -b*xy(2)-xy(1)]; 


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%         3.egyenlet          %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%egyenlet_3=; 


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%         4.egyenlet          %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%w=;                                         % Paraméter, tetszõleges

%egyenlet_4=; 



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%         5.egyenlet          %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%egyenlet_5=; 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%         6-10.egyenlet          %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%egyenlet_6=;                                                    

%egyenlet_7=;                                                    
energia_inga= @(X,Y) 0.5*Y.^2-cos(X)+1;

%egyenlet_8=;                                                    


%egyenlet_9=; 

Z =energia_rugo(X,Y); % Energia

%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%             ODE45              %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

[t, xy]=ode45(egyenlet_2, [tinit Max_Time], [Xinit; Yinit]); %diffegyenletet kiszámol

%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%         Kirajzoltatás          %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%      x-y szerint, energia      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
figure;
subplot(2,2,1);                                             % ábrák elhelyezése egy mezõn belül, számolás
                                                            % balról jobbra, fentrõl le
hold on;
energiaszintek=[0, 0.1 0.25, 0.5, 1, 1.4, 2, 2.4, 3, 4];    % ezeken a szinteken számolom ki az energiát
contour(X,Y,Z, energiaszintek);                             % energia szintvonalak ábrázolása
plot(xy(:,1), xy(:,2), 'b');            
xlabel('x');
ylabel('y');
hold off;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%           x-t szerint          %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
subplot(2,2,3);
plot(xy(:,1), t, 'b');
xlabel('x');
ylabel('t');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%           t-y szerint          %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

subplot(2,2,2);
plot(t, xy(:,2), 'b');
xlabel('t');
ylabel('y');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%       x-y-t 3D-s ábrázolás     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

subplot(2,2,4);
plot3(xy(:,1), xy(:,2), t, 'b');
xlabel('x');
ylabel('y');
zlabel('t');
%}
