function varargout = jump(t,x,flag)
%gjdsgf
switch flag
    case''
        varargout{1}=Ft(t,x);
    case 'init'
        [varargout{1:3}]=init;
    case 'events'
        [varargout{1:3}]=event(t,x);
    case 'demo'
        [varargout{1:5}]=ode45('jump');
end
%ode45(jump)

function f=Ft(t,x)
global g c k
f(1,1)=x(2);
if x(1)>0
    f(2,1)=-g;
else
    f(2,1)=-g-c*x(1)-k*x(2);
end

function [val, ist, dir]=event(t,x)
%funkc
val=x'; %i to i to interesno
ist=[0,1]; %%%%%%ostanovincya pri izmenenii skorosti%%%%%%%%%%%
dir=[0, -1];


function[tspan, x0, opt] = init
tspan=[0, 30];
x0=[20,0];
opt=odeset('outputFcn','odephas2','events','on');

