You are on page 1of 1

% This script allows the user to find the divergence and curl

% of a vector field given in symbolic from


% It uses the build-in symbolic derivate function
% called diff() to compute the derivates clear
syms x y z % declare x, y, z to be symbols (variables)

% Prompt the user to enter the symbol vector


% For example the user could enter [y*2 4*x*y y]
disp('Enter the symbolic vector (in the format ');
A = input('[fx(x,y,z) fy(x,y,z) fz(x,y,z)]=... \n > ');

% The divergence of A
% e.g. diff(A(2), z) means the derivative of the
% y-component of vector A with respect to z
divA=diff(A(1),x)+...
diff(A(2),x)+...
diff(A(3),x)+...
% evualuate divergence at point (x,y,z) = (1, -2, 3)
subs(divA,{x,y,z},{1, -2, 3})

% The curl of A
% e.g. diff(A(2),z) means the derivative of the
% y-component of vector A with respect to z
curlA=[diff(A(3),y)-diff(A(2),z),...
-diff(A(3),x)+diff(A(1),z),...
diff(A(2),x)-diff(A(1),y)]
% evaulate curl at point (x,y,z) = (1, -2, 3)
subs(curlA,{x,y,z},{1, -2, 3})

You might also like