function varargout = MischgefaessFunktion(flag, t, x, u, p)

switch flag 
    case 'init'
        varargout{1} = 2;
        varargout{2} = 1;
        varargout{3} = 1;
        varargout{4} = p.Ts;
        varargout{5} = struct('old', p.xo);
        
    case 'output'
        [tt,xx] = ode23(@fxdot, [0 p.Ts],x.old,[],p,u);
        y = xx(end,:);
        x.old = y;
        varargout{1} = [y(1)];
        varargout{2} = x;
        
    case 'terminate'
        
    otherwise
        error(['Unexpected flag: ' flag])
end

function [xdot]=fxdot(t,x,p,u)
z = u(1)
theta10 = u(2);
thetaSp = x(1);
thetaSpdot = (p.mdot10*(theta10-thetaSp)+z*p.kv*(p.theta20-thetaSp))/p.MSp;
xdot=[thetaSpdot];
return