we consider the function f(x,y,z)=2*x*y-z^2 compute the gradient of f at point (x,y,z)=(3,-1,1) in matlab

To compute the gradient of function f(x,y,z)=2*x*y-z^2 at point (x,y,z)=(3,-1,1) in MATLAB, we can use MATLAB's gradient function as follows:

main.m
syms x y z % Declare symbolic variables
f = 2*x*y - z^2; % Define the function
gradf = [diff(f,x); diff(f,y); diff(f,z)]; % Compute the gradient
gradf_evaluated = subs(gradf, [x y z], [3 -1 1]); % Evaluate the gradient at (3,-1,1)
231 chars
5 lines

The output of gradf_evaluated will be [6; -2; -2].

related categories

gistlibby LogSnag