function [prob] = prob5(p)

prob = struct('n',{0},'m',{0},'bl',{0},'bu',{0},'cl',{0},'cu',{0},'obj',{0},'cons',{0},'hess',{0},'x',0,'name',0);
prob.n = 3;
prob.m = 3;
prob.me = 1;

% prob.bl = -Inf*ones(2,1);
% prob.bu = Inf*ones(2,1);
% prob.cl = -Inf*ones(2,1);
% prob.cu = zeros(2,1);
% prob.cu(1)=p^2;
% prob.cu(2)=(p+2)^2;
%prob.dcdp = [2*p;2*(p+2)];
prob.dcdp = [-1;0;0];
prob.name = 'Wright problem';
prob.x = ones(3,1);

prob.obj = (@(x)(objective(x)));
prob.cons = (@(x)(constraint(x,p)));
prob.hess = (@(x,y)(hessian(x,y)));
prob.chess = (@(x)(conhess(x,p)));
end

function [f,g] = objective(x)

f = x(1);
g=zeros(3,1);
g(1) =  1;
end




function [c,J] = constraint(x,p)
    c=zeros(3,1);
    c(1) = x(3) - p;
    c(2)=-(x(1)-2)^2-x(2)^2+x(3)^2;
    c(3) = -(x(1)-4)^2-x(2)^2+(x(3)+2)^2;

    J=zeros(3,3);
    J(1,3) = 1;
    J(2,1) = -2*(x(1)-2);
    J(2,2) = -2*x(2);
    J(2,3) = 2*x(3);
    J(3,1) = -2*(x(1)-4);
    J(3,2) = -2*x(2);
    J(3,3) = 2*(x(3)+2);

end

function [H] = hessian(x,y)
H=zeros(3);
y = y;

H(1,1) = y(2)*2+y(3)*2;
H(2,2) = y(2)*2+y(3)*2;
H(3,3) = -2*y(2)-2*y(3);
end

function HC = conhess(x,p)

HC = zeros(3,3,3);
HC(1,1,2) = -2;
HC(2,2,2) = -2;
HC(3,3,2) = 2;
HC(1,1,3) = -2;
HC(2,2,3) = -2;
HC(3,3,3) = 2;
end
