compute value of z=cos(x/y)*cos(y)+(y/10)-(x/5) for all grid points (x,y) in matlab

main.m
% Define grid
[x,y] = meshgrid(-10:0.1:10,-10:0.1:10);

% Compute z
z = cos(x./y).*cos(y)+(y./10)-(x./5);

% Plot the result
surf(x,y,z);
xlabel('x');
ylabel('y');
zlabel('z');
title('z = cos(x/y)*cos(y)+(y/10)-(x/5)');
220 chars
13 lines

This code defines a grid of points (x,y) using meshgrid, computes the value of z using the given expression, and then plots the result using surf. The resulting plot shows the surface defined by z as a function of x and y.

related categories

gistlibby LogSnag