Derivatives: Partial Derivatives - Example

The velocity potential is typically used in fluid mechanics to describe flows that do not experience frictional losses.  Its principal advantage is that the velocity field can be related to the gradient (we will see it shortly) of the velocity potential

3D plot
Before we obtain the partial derivatives, it would be nice what the functions look like.  There are two ways to display the plot of the function (i) a 3D plot with the function along the z axis; or (ii) a contour plot - this is a 2D plot of contours corresponding to the same function value.  In many cases the contour plot is more valuable


Contour

%Derivatives: Partial Derivatives - Velocity Potential
% 3D and Contour plot
%-----------range and function definition--------------
x=0.1:0.1:5;
y=0.1:0.1:5;
phi = inline('(5/2*pi)*log(sqrt(X.*X + Y.*Y)) + X.*X -Y.*Y','X','Y');
%---------------------------------------------------
[X Y] = meshgrid(x,y);

phival=phi(X,Y);
surf(x,y,phival)     % 3D surface plot
xlabel('x'); ylabel('y'); zlabel('\phi (x,y)');

figure;   % contour plot
[c1,h1] = contour(x,y,phival);
clabel(c1);  % label contours
xlabel('x'); ylabel('y');