%% Matrix calculus and derivative checking

%% Setup poblano to check gradients
% We'll use the gradientcheck.m function for this purpose.
addpath('~/Dropbox/matlab-extern/poblano_toolbox_1.0/');

%% 
% We'll use a vector function
n = 5;
A = randn(n);
out=gradientcheck(@(x) logdet(x,n),reshape(A'*A,n*n,1))

%% Note that the transpose is important!
A = randn(n);
out=gradientcheck(@(x) logdet(x,n),reshape(A,n*n,1))


%%
A = randn(n);
out = gradientcheck(@(x) fcombine(x, @(x) exp(-x'*A*x), @(x) -exp(-x'*A*x)*(A*x + A'*x)), randn(n,1))