I have been trying out the following code to find the gradient of a function at a particular point where the input is a vector and the function returns a scalar.
The following is the function for which I am trying to compute gradient.
%fun.m
function [result] = fun(x, y)
result = x^2 + y^2;
This is how I call gradient.
f = @(x, y)fun(x, y);
grad = gradient(f, [1 2])
But I get the following error
octave:23> gradient(f, [1 2])
error: `y' undefined near line 22 column 22
error: evaluating argument list element number 2
error: called from:
error: at line -1, column -1
error: /usr/share/octave/3.6.2/m/general/gradient.m at line 213, column 11
error: /usr/share/octave/3.6.2/m/general/gradient.m at line 77, column 38
How do I solve this error?