function [energyDefoGrad, energyTargetPos] = checkSolution( vt, exR, exV, constraintVtIndices, G, kWt)
%
%  vt:2nx1 , it vectorizes all optimized vertex positions into
%            a vector
%  exV:2nx1, note that its size is NOT the size of constraintVtIndices!!! 
%  G: 4mx2n, which maps vt to its vectorized deformation gradient
%

nVts = size(vt,1)/2;
nFcs = size(G,1)/4;
nHandle = size(constraintVtIndices,1);

F = G*vt;

energyAll = norm(F-exR) + kWt*norm(vt(constraintVtIndices)-exV(constraintVtIndices));
fprintf('energyAll is %f\n',energyAll);

energyDefoGrad = norm(F-exR);
fprintf('average defo.grad error is %f\n',energyDefoGrad);

energyTargetPos = kWt*norm(vt(constraintVtIndices)-exV(constraintVtIndices));
fprintf('average handle position error is %f\n',energyTargetPos);

Lambdas = zeros(2*nFcs, 1);
for i=1:nFcs
    curR = [exR(4*i-3) exR(4*i-1);exR(4*i-2) exR(4*i)];
    curF = [F(4*i-3) F(4*i-1);F(4*i-2) F(4*i)];
    
    W = curR'*curF+curF'*curR;
    Lambdas(2*i-1:2*i,:) = eig(W);
end

[sL, sLI] = min(Lambdas);
%sL

if sL<0.0
    fprintf('Smallest eigenvalue of Wi is %f, at the %d th face\n',sL, sLI);
else
    fprintf('All semidefinite constraints are satisfied\n');
end

end

