I would like to find the derivative of this function:
function [f] = f4(x)
f=0.5*(x(1)^2+10*x(2)^2);
end
I'm using symbols to find the jacobian:
x = sym('x', [2 1]);
f=0.5*(x(1)^2+10*x(2)^2);
grad=jacobian(f,x)
which returns
grad = [ x1, 10*x2]
Then I change it manually to look like this so I can use feval
:
grad = [ x(1,1), 10*x(2,1)];
I find that using feval
is faster than using subs
. I would like to find the derivative of any function that I can evaluate using feval
and avoid doing anything manually.