function [f,j]=fun_ok(x) f = x(:).^2; j = diag(2*x(:)); end