Last active
August 29, 2015 14:02
-
-
Save qlyoung/68b622233eb3849151c9 to your computer and use it in GitHub Desktop.
mat-273 final project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dog(): | |
"""Plot the word DOG using six parametric graphs""" | |
u, v = var('u, v') | |
# D | |
x(u, v) = u | |
y(u, v) = -5 | |
z(u, v) = v | |
D_plane = parametric_plot3d( (x, y, z), (u, -7, 7), (v, -10, 10) ) | |
y(u, v) = -(.1*(u^2)) | |
D_parabola = parametric_plot3d( (x, y, z), (u, -7, 7), (v, -10, 10) ) | |
# O | |
radius = 6 | |
x(u, v) = radius * cos(v) | |
y(u, v) = 7 + radius * sin(v) | |
z(u, v) = u | |
O_cylinder = parametric_plot3d( (x, y, z), (u, -10, 10), (v, 0, 2*pi) ) | |
# G | |
radius = 6 | |
x(u, v) = radius * cos(v) | |
y(u, v) = 20 + (radius * sin(v)) | |
z(u, v) = u | |
G_halfcyl = parametric_plot3d( (x, y, z), (u, -10, 10), (v, pi, 2*pi) ) | |
G_quartercyl = parametric_plot3d( (x, y, z), (u, -10, 10), (v, 0, pi / 2) ) | |
x(u, v) = 0 | |
y(u, v) = u | |
z(u, v) = v | |
G_plane = parametric_plot3d( (x, y, z), (u, 20, 26), (v, -10, 10) ) | |
# plot | |
dogplot = D_plane + D_parabola + O_cylinder + G_halfcyl + G_quartercyl + G_plane | |
print '\nThe plot of dog using six parametric equations is' | |
show(dogplot) | |
def vector_field(): | |
"""Plot a vector field""" | |
x, y = var('x,y') | |
vfield = plot_vector_field((sin(x), cos(y)), (x,-5,5), (y,-5,5), color='blue') | |
print "\n\n2d vector field:" | |
show(vfield) | |
def ice_cream(): | |
""" | |
Plot an 'ice cream cone' as the composite graph of a cone and a sphere and | |
calculate its volume and surface area | |
""" | |
# cone | |
u, v = var('u, v') | |
height = 5 | |
radius = 2 | |
x(u, v) = ((height - u) / height) * radius * cos(v) | |
y(u, v) = ((height - u) / height) * radius * sin(v) | |
z(u, v) = -u | |
# plot of the cone | |
cone = parametric_plot3d( (x, y, z), (u, 0, height), (v, 0, 2*pi), color='brown') | |
# volume of the cone | |
cone_volume = pi * radius^2 * (height / 3) | |
# surface area of the cone | |
x_prime_u = derivative(x, u) | |
y_prime_u = derivative(y, u) | |
z_prime_u = derivative(z, u) | |
x_prime_v = derivative(x, v) | |
y_prime_v = derivative(y, v) | |
z_prime_v = derivative(z, v) | |
i = (y_prime_u * z_prime_v) - (z_prime_u * y_prime_v) | |
j = -(x_prime_u * z_prime_v) - (z_prime_u * x_prime_v) | |
k = (x_prime_u * y_prime_v) - (x_prime_v * y_prime_u) | |
integrand = sqrt(i^2 + j^2 + k^2) | |
cone_surface_area = integrate( integrate(integrand, (v, 0, 2*pi)), (u, 0, 5)) | |
# sphere | |
phi, theta = var('phi, theta') | |
radius = 2 | |
x(phi, theta) = radius * cos(theta) * sin(phi) | |
y(phi, theta) = radius * sin(theta) * sin(phi) | |
z(phi, theta) = .8 + radius * cos(phi) | |
# plot of sphere | |
sphere = parametric_plot3d( (x, y, z), (phi, 0, 2 * pi), (theta, 0, pi), color='gray') | |
# volume of sphere | |
sphere_volume = (4/3) * pi * radius^3 | |
# surface area of sphere | |
sphere_surface_area = 4 * pi * radius^2 | |
# print results | |
print "Plot of an ice cream cone:" | |
show(cone + sphere) | |
print "Volume of cone:" | |
show(cone_volume) | |
print "Surface area of cone:" | |
show(cone_surface_area) | |
print "Volume of sphere:" | |
show(sphere_volume) | |
print "Surface area of sphere:" | |
show(sphere_surface_area) | |
print "Volume of ice cream cone:" | |
show(cone_volume + sphere_volume) | |
print "Surface area of ice cream cone:" | |
show(cone_surface_area + (sphere_surface_area / 2)) | |
def line_integral(): | |
"""Plot a helical space curve and take the line integral of f(x, y, z) = xyz over it""" | |
# curve | |
t = var('t') | |
radius = 3 | |
stretchiness = .5 | |
x(t) = radius * cos(t) | |
y(t) = radius * sin(t) | |
z(t) = stretchiness * t | |
curve = parametric_plot3d( (x, y, z), (t, -10, 10) ) | |
# function | |
function = x*y*z | |
# line integral of function over curve | |
x_prime = derivative(x, t) | |
y_prime = derivative(y, t) | |
z_prime = derivative(z, t) | |
ds = sqrt(x_prime ^ 2 + y_prime ^2 + z_prime ^2) | |
result = integrate(function * ds, t) | |
numeric_result = integrate(function * ds, (t, -10, 10)) | |
# and print the results | |
print '\nThe line integral of the function' | |
show("f(x, y, z) = xyz") | |
print 'over the helical space curve defined by parametric equations' | |
show("x(t) = 3cos(t)") | |
show("y(t) = 3sin(t)") | |
show("z(t) = .5t") | |
print 'which looks like this' | |
show(curve) | |
print 'in the range' | |
show("-10 \leq t \leq 10") | |
print 'is' | |
show(numeric_result) | |
show("=") | |
show(n(numeric_result)) | |
print 'and its general form is' | |
show(result) | |
# MAT-273 Final Project 0WN3D /) | |
print '\n' * 5 + '=' * 40 + "MAT 273 Final Project" + '=' * 40 | |
# -plot the word 'dog' | |
dog() | |
# -create a vector field in sage | |
vector_field() | |
# -plot an 'ice cream cone' | |
# -find the area inside the ice cream cone | |
# -find the surface area of the ice cream cone | |
ice_cream() | |
# -draw a 3D line and find the value of the line integral | |
line_integral() | |
print """ | |
___ _____ ____ | |
/ _ \ | ____| | _ \ | |
| | | | | _| | | | | | |
| |_| |_ | |___ _ | |_| | | |
\__\_(_) |_____(_) |____/ | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment