I am getting error while using gradient(function,vector) 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)
Show older comments
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)
0 Comments
Answers (0)
See Also
Categories
Find more on Numbers and Precision in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!