% Input:
% edA: Matrix (exmp(A))
% delta: Double (stepsize)
% u,x0: function handle (support function of free input and initial set)
% epsilonpsi: function handle (support function)
% e_p, e_n: vector
% start: vector (start vector for optimization procedure)
% options: optionsstructure with parameters for optimization ([] is default)

% Output:
% res: function handle (support function)

% Description:
% Generates the support function representation of set Omega for intervall
% [0,delta] for algoSpaceEx

function [res] = calcomega0delta(edA,delta,u,x0,epsilonpsi,e_p, e_n,start,options)
res = @(l) result(edA,delta,u,x0,epsilonpsi,e_p, e_n,start,options,l);
 

% Intersect big Epsilon+ and big Epsilon- for a concrete x (= direction vector l)
function [res] = epsilonintersection(e_p, e_n,x,d,l)
res =0;
for i=1:1:d
    res = res+ min(x*e_p(i),(1-x)*e_n(i))*abs(l(i));
end;


function [value] = result(edA,delta,u,x0,epsilonpsi,e_p, e_n,start,options,l)
% target function for optimization
w = @(x) -((1-x)*x0(l) + x*x0(edA'*l)+x*delta*u(l) +(x^2)*epsilonpsi(l) +epsilonintersection(e_p,e_n,x,size(start,1),l));

[~,value] = fmincon( w ,start,[],[],[],[],0,1,[], options);
value = -value;