global g;
global eps;
global k;
g=9.80665;
eps=1e-8;
k=2;
function [y,x]=met(t,v)
  global g;
  global k;
  x=v(1)/k.*(1-exp(-k*t));
  y=1/k^2*(g*(1-k*t)+k*v(2)-...
  exp(-k*t).*(g+k*v(2)));
endfunction

function [t,x]=domet(tt,vi)
  global eps;
  global k;
  for i=1:100
    t=tt(2)-diff(tt)/diff(met(tt,vi))*met(tt(2),vi);
    tt(1)=tt(2);
    tt(2)=t;
    if abs(diff(tt))<eps,
      break
    end;
  end;
  [y,x]=met(t,vi);   
endfunction

function d=pogresek(v,x0)
	tt=[1,1.5];
	d=[];
	for vi=v
	  [t,x]=domet(tt,[vi,vi]);
	  d=[d,x-x0];
	end;
endfunction 

function v=zadetek(vv,x0)
  global eps;
  for i=1:100
    v=vv(2)-diff(vv)/diff(pogresek(vv,x0))*pogresek(vv(2),x0);
    vv(1)=vv(2);
    vv(2)=v;
    if abs(diff(vv))<eps,
      break
    end;
  end;   
endfunction

v=[10,10];
k=2;
tt=[1,1.5];
x0=4;
[t,x]=domet(tt,v)
T=linspace(0,t);
[Y,X]=met(T,v);
plot(X,Y,X,zeros(size(X)),x,0,'or');

vi=[9,10];
v0=zadetek(vi,x0)
[t,x]=domet(tt,[v0,v0])
T=linspace(0,t);
[Y,X]=met(T,[v0,v0]);
plot(X,Y,X,zeros(size(X)),x,0,'or');

x0=8
vi=[9,10];
v0=zadetek(vi,x0)
[t,x]=domet(tt,[v0,v0])
T=linspace(0,t);
[Y,X]=met(T,[v0,v0]);
plot(X,Y,X,zeros(size(X)),x,0,'or');

x0=3
vi=[9,10];
v0=zadetek(vi,x0)
[t,x]=domet(tt,[v0,v0])
T=linspace(0,t);
[Y,X]=met(T,[v0,v0]);
plot(X,Y,X,zeros(size(X)),x,0,'or');





