SLICES.OMS
Script File:
# Description:
# Plots slices of the function f(x, y, z) = x^2 + y^2 - z.
#
clear
# define function to plot
function f(x, y, z) begin
return x^2 + y^2 - z
end
# Number of points in x and y grids
N = 21
# x ranges from -2 to 2
x = 4 * (seq(N) - 1) / real(N - 1) - 2
# y ranges from -2 to 2
y = x'
# x on 2 - dimensional grid
X = fillcols(x, N)
# y on 2 - dimensional grid
Y = fillrows(y, N)
#
# put title in viewport 0
gtitle("X^2 + Y^2 - Z")
# define viewport 1
gaddview(0., .15, 1., .7)
# contour levels
level = seq(5) - 1.5
color = { "black", "red", "blue", "green", "black" }
# set colors
gcolor(color)
gxtitle("X")
gytitle("Y")
gztitle("Z")
for z = 0 to 4 begin
# plot the contour
contour(f(X, Y, z), level, x, y, z, "surface")
end
grotate(30, 0, 70)
Output:
|