UP | HOME

Exercise 26 solutions

Table of Contents


Python

e26.py

# ipython --pylab

from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax = fig.add_subplot(111, projection="3d")
x = arange(-8.0, 8.0, 0.1)
y = arange(-8.0, 8.0, 0.1)
X,Y = meshgrid(x, y)
R = sqrt(X**2 + Y**2) + 0.000001
Z = sin(R)/R
ax.plot_surface(X, Y, Z)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

MATLAB / Octave

e26.m

[X,Y] = meshgrid(-8:0.1:8);
R = sqrt(X.^2 + Y.^2) + eps;
Z = sin(R)./R;
mesh(X,Y,Z)
xlabel('X'); ylabel('Y'); zlabel('Z');

R

e26.R

library(lattice)
g <- expand.grid(x=seq(-8,8,0.1),y=seq(-8,8,0.1))
r <- sqrt((g$x*g$x) + (g$y*g$y)) + 0.00001
g$z <- sin(r)/r
wireframe(z ~ x * y, data=g, shade=TRUE, light.source = c(10,0,10))

Paul Gribble | fall 2014
This work is licensed under a Creative Commons Attribution 4.0 International License
Creative Commons License