function varargout = Ricker_GUI_feladat(varargin)
% RICKER_GUI_FELADAT M-file for Ricker_GUI_feladat.fig
%      RICKER_GUI_FELADAT, by itself, creates a new RICKER_GUI_FELADAT or raises the existing
%      singleton*.
%
%      H = RICKER_GUI_FELADAT returns the handle to a new RICKER_GUI_FELADAT or the handle to
%      the existing singleton*.
%
%      RICKER_GUI_FELADAT('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in RICKER_GUI_FELADAT.M with the given input arguments.
%
%      RICKER_GUI_FELADAT('Property','Value',...) creates a new RICKER_GUI_FELADAT or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Ricker_GUI_feladat_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Ricker_GUI_feladat_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Ricker_GUI_feladat

% Last Modified by GUIDE v2.5 24-Sep-2012 10:57:02

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Ricker_GUI_feladat_OpeningFcn, ...
                   'gui_OutputFcn',  @Ricker_GUI_feladat_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before Ricker_GUI_feladat is made visible.
function Ricker_GUI_feladat_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to Ricker_GUI_feladat (see VARARGIN)

% Choose default command line output for Ricker_GUI_feladat
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

x = 0:0.01:10;
line(x,x,'Color','green','Parent',handles.axes1);

% UIWAIT makes Ricker_GUI_feladat wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = Ricker_GUI_feladat_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;

% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject    handle to slider1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider

%TECHNIKAI: Scrollbar aktualis erteke
A = get(hObject,'Value');
%TECHNIKAI: Kiirja a Scrollbar aktualis erteket
set(handles.text2,'String',A);
%TECHNIKAI: "Letorli a tablat"
cla;

%TECHNIKAI: A "rajztabla" handle-jet megkapja, itt most nem lesz ra szukseg.
%h = get(handles.axes1,'Children');
%A fuggveny

fh = @(x,A) A.*x.*exp(-x);

%Iteraciok szama. Ezt nem kell valtoztatni most.
NumberOfIterations=200;

%Kezdeti ertek.
InitialValue=0.2;
InitialValue2=0.200001;

%A fuggvenyt egy "pont racson" oldjuk meg, ezzel kozelitjuk vonalakkal.
grid_precision=1000;
f_grid = zeros(grid_precision,1);
f_sol = zeros(grid_precision,1);

%Fuggveny kiszamolasa
f_grid=linspace(0,6, grid_precision);
f_sol=fh(f_grid,A);

%Fuggvenyt rajzol
plot(f_grid,f_sol,'black');
hold on;

%TECHNIKAI: Skalazas
arr = get(handles.axes1,'XLim');
a = arr(1);
b = arr(2);
arr = get(handles.axes1,'YLim');
c = arr(1);
d = arr(2);
e =max(b,d);
e =max(b,d);
f =max(a,0);
g =max(c,0);

%Skalazas beallitasa
set(handles.axes1,'XLim',[f e]);
set(handles.axes1,'YLim',[g e]);

%TECHNIKAI: Megvan a vegleges magassag
Line=0:e;

%Vonalat rajzol
plot(Line,Line,'green')
hold on;

%Inicializalas
Population=zeros(NumberOfIterations,1);
Population(1)=InitialValue;

%Megcsinalja az iteraciot
for i=1:(NumberOfIterations-1)
Population(i+1)=A*Population(i)*exp(-Population(i));
end

% Pokhalo diagram
for i=2:NumberOfIterations-1
   plot([Population(i), Population(i)], [Population(i), Population(i+1)], 'r');
   hold on;
   plot([Population(i), Population(i+1)], [Population(i+1), Population(i+1)], 'r');
   hold on;
end

%Inicializalas
Population=zeros(NumberOfIterations,1);
Population(1)=InitialValue2;

%Megcsinalja az iteraciot
for i=1:(NumberOfIterations-1)
Population(i+1)=A*Population(i)*exp(-Population(i));
end
% Pokhalo2 diagram
for i=2:NumberOfIterations-1
   plot([Population(i), Population(i)], [Population(i), Population(i+1)], 'b');
   hold on;
   plot([Population(i), Population(i+1)], [Population(i+1), Population(i+1)], 'b');
   hold on;
end

hold off;


% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to slider1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end
