How to feed value to jacobian() function in my case?
6 views (last 30 days)
Show older comments
I need to calculate the gradient of a user-defined object function named fcn. I choose to use jacobian() function to calculate the symbolic gradient.
take subset of parameter vector b as input, like
%******************************
% Parameterized Moments
%******************************
function fm = fcn(b)
global T T_z T_e zt et
teta =0;
zt =b(1:T_z); % Line-7 %
et =b(1+T_z:T_z+T_e);
dify =zeros(T,T);
b are pre-calculated parameters. so I write the jacobian() in the following way to call fcn
v = [zt,et]';
dfb = jacobian(fcn,v);
but Matlab told me that
Error using fcn (line 7)
Not enough input arguments.
I'm not sure if this is due to the way I write jacobian or how I define the fcn? How can I fix the error? Thank you.
2 Comments
Answers (1)
Walter Roberson
on 17 Nov 2016
When you call
jacobian(fcn,v)
then v must evaluate to a vector of symbolic variable names, and fcn must evaluate to a symbolic expression or symbolic function.
When fcn is a function, using it in a syntax such as
jacobian(fcn,v)
causes the function to be invoked with no arguments, exactly equivalent to
jacobian(fcn(),v)
Your fcn function does not like being called with no arguments.
To calculate the jacobian with that fcn, it appears to me you would need to use something like
global T_z T_e zt et
nT = T_z + T_e;
B = sym('B', [1, nT]);
temp = fcn(B); %zt and et are not defined until fcn is run
v = [zt,et]';
dfb = jacobian(temp, v);
10 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!