I have a piece of code that looks something like this:
x=zeros(N_x,1);
y=zeros(N_y,1);
sym(x);
sym(y);
H=a differentiable scalar function of vectors y and x;
H_x=simplify(jacobian(H,x));
H_y=simplify(jacobian(H,y));
f_x=matlabFunction(H_x);
f_y=matlabFunction(H_y);
for i=many values of x and y
x=N_x*1 vector with some values for x
y=N_y*1 vector with some values for y
derivatives_x(:,i)=f_x(x,y);
derivatives_y(:,i)=f_y(x,y);
end
Now my problem is that depending on the functional form of H, f_x and f_y could be a function of only x or only y or a function of neither. In that case the final two lines of my code cannot be executed. Is there any way to work around this problem? Suppose that f_x is a function of x only than I would be very happy if f_x would look like:
f_x(x,y)=g(x)+0*y
but I do not know how to get to something like that. Does anybody have any suggestions? Many thanks in advance.
With kind regards,
Floris
