%function called by costandcontrol.m. Stored in a own file called costfun
function J=costfun(u)
%Gives the cost function to fmincon function in costandcontrol
global H b fmark w A B ypast uopt yrls urls beta P K

J=0.5*u'*H*u+b*u+fmark; %the cost function based on u (not delta u)