function [F] = sampson_cost_nonlin(x)
%Joshua Stough
%COMP 290-89, Pollefeys
%Assignment 2, Computing F

%The cost being computed here is 
%on p.271, for every point.

global inliers X XP

Fund = reshape(x,3,3);

numerators = Fund*X;
numerators = sum(XP.*numerators);
numerators = numerators.^2;

jj1 = Fund*X;
jj1 = sum(jj1(1:2,:).^2);

jj2 = Fund'*XP;
jj2 = sum(jj2(1:2,:).^2);

denoms = jj1 + jj2;

denoms(denoms == 0) = 1e-15;

F = numerators./denoms;