Ask Your Question

using @interact

asked 2012-02-29 08:55:20 -0500

Pwnasaurus gravatar image

updated 2012-02-29 09:54:05 -0500

kcrisman gravatar image

I have this code which works just fine and produces an image:

center(x) =sqrt(x) 
spin(x) = 2- 1/4 * x^2 
r(x) = abs(spin(x) - center(x)) 
parametric_plot3d((x, r(x)*sin(u)+center(x), r(x)*cos(u)), (u, 0, 2*pi), (x, 0, 2), mesh=True)

However, I would like to use a @interact to be able to change the functions named center and spin. I tried this (and a few variations)

def _(center =6 -x^2, spin = x):
  r(x) = abs(spin(x) - center(x))
  parametric_plot3d((t, r(t)*sin(u)+center(x=t), r(t)*cos(u)), (u, 0, 2*pi), (t, 0, 2), mesh=True)

and while I don't get an error, I also don't get a picture for some reason. Any suggestions?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2012-02-29 09:08:18 -0500

calc314 gravatar image

You just need to use the show command to force Sage to show the plot. The code below works for me.

def _(center =6 -x^2, spin = x): 
    r(x) = abs(spin(x) - center(x)) 
    p=parametric_plot3d((t, r(t)*sin(u)+center(t), r(t)*cos(u)), (u, 0, 2*pi), (t, 0, 2), mesh=True)
edit flag offensive delete link more


Yup, because all in all an interact is still a definition, and if you don't ask the function definition to output anything, it won't.

kcrisman gravatar imagekcrisman ( 2012-02-29 09:54:38 -0500 )edit

You are awesome

Pwnasaurus gravatar imagePwnasaurus ( 2012-03-01 04:48:47 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2012-02-29 08:55:20 -0500

Seen: 147 times

Last updated: Feb 29 '12