I am getting error while using gradient(f​unction,ve​ctor) the error is: Error using zeros||| Error in gradient (line 64) g = zeros(size(f),class(f)); % case of singleton dimension

1 view (last 30 days)
f_str = input('enter the function: ','s');
f = inline(f_str);
n = nargin(f); %%provides no. of arguments
X_char = argnames(f)
X = sym('X', [n,1]) %%declare matrix X of dimension nx1 as sym
i = 1; while (i<=n)
X(i,1) = X_char(i,1)
i = i+1;
end
X = X(:) %% convert X from column matrix to column vector
gradient(f,X)

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!