function [f,g] = Energy_functional(x)
global Invariant ini_Val Material Constraints ALG phi 
%Initialization
C0=Constraints.C0;
p = ini_Val.p;


if isfield(Constraints,'f0')
    f0 = Constraints.f0;
else
    f0 = 0;
end




[C,C1,C2]=interpolate(Invariant,x);
Aux = auxiliary_calculations(Invariant,p,C0,C,C1,C2,phi);
[tE,dE_dCP] = Curvature_functional(Aux);


fE = pi* x(end-1)^2*f0;
tmp = zeros(size(dE_dCP));
tmp(1,end) = 2*pi*x(end-1)*f0;
dfE_dCP = tmp; 


% SUPPORT BILAYER
if isfield(Material,'a') && isfield(Material,'b') &&  isfield(Material,'h')
    [tU, dU_dCP] = incremental_potential(Aux);
else
    tU = 0 ;
    dU_dCP = 0;
end


tE = tE + tU-fE ;
dE_dCP = dE_dCP + dU_dCP-dfE_dCP; 

g=dE_dCP;
f= tE ;
g=reshape(g,length(x),1);
