%Cost function

function J = costfun(u,dist,par,init,opt) 

%option=odeset('AbsTol',1e-10,'RelTol',1e-6);
[~, x] = ode23(@(t,x) model(t,x,u,dist,par,opt),[0 opt.sim_time],...
    init.vector(1:3));
J = x(end,end);
