% Optimazatio example with respect to zeta 
% change Tsample for appreciate the symbolic derivative
% and look off vs on with the jacobian option
% use mycost and mymodel 
tau=1
k=1
w0=1
ki=1
zeta=.3
q=1
Tsample=.1

%print(['-s',gcb],'-djpeg',strrep([gcb,'.jpg'],'/','-'));
sim('mymod');
subplot(2,1,1)
n=prod(size(out));
stairs([0:n-1]*Tsample,out,'LineWidth',2)
xlabel('time')
ylabel('J')
subplot(2,1,2)
n=prod(size(dout));
stairs([0:n-1]*Tsample,dout,'LineWidth',2)
xlabel('time')
ylabel('dJ/dzeta')



[zeta_opt,fval,exitflag,output]=fsolve(@myfcost,[.01],optimset('Jacobian','off')) % change off vs on 
sprintf('%0.8g',zeta_opt)

figure();
sim('mymod');
subplot(2,1,1)
n=prod(size(out));
stairs([0:n-1]*Tsample,out,'LineWidth',2)
xlabel('time')
ylabel('J')
subplot(2,1,2)
n=prod(size(dout));
stairs([0:n-1]*Tsample,dout,'LineWidth',2)
xlabel('time')
ylabel('dJ/dzeta')
