function J=obfunc3(g)
% OBFUNC3
% Obfunc beregner kriterieverdien 
% J=int_0^7 (x'*Qx+u'*P*u) dt
% der
% dot(x)=Ax+Bu, u=Gx, x(t=0)=x0.
% Parametre: global a, b, q, p, x0, h, t, N
% Merk: dette er en mer generell versjon av OBFUNC.M
% Se tilhoerende hovedscript, MAIN_OBFUNC2.M

tf=7;
global a b q p x0 h t N
Ac=a+b*g;
Qc=q+g'*p*g;
[n,m]=size(a);

F=[-Ac' Qc;zeros(n,n) Ac];      % Compute observability gramian for (Ac',Qc)
E=expm(F*tf);
E12=E(1:n,n+1:2*n);
E22=E(n+1:2*n,n+1:2*n);
Wo=E22'*E12;

J=x0'*Wo*x0;


% END OBFUNC3
