Ask Your Question
0

@interact causes working program to err

asked 2013-09-22 19:10:12 +0100

drdrugus gravatar image

updated 2013-09-22 22:58:56 +0100

calc314 gravatar image

The following code segment works well in sagenb.com until the @interact is put in to permit varying variables a and b. Then a long error is thrown, ending with

"self.loc = (float(center[0]), float(center[1]), float(center[2]))
TypeError: 'sage.symbolic.expression.Expression' object does not support
indexing"

The issue is the statement found near the end that says G+=point((x,y), color='red',pointsize=4) If that statement is commented out, then it runs again, although and of course the desired plot is not obtained. Why? What can i do about it?
Clearly you won't let me show you by uploading the file. I am posting what i can.

def Pxy(s,a,b): 
   x=var('q') 
   EQ1=s==(a*(sqrt(1+b^2))*e^(b*q))/b 
   theta=solve([EQ1],q) 
   x=a*cos(theta[0].rhs())*e^(b*theta[0].rhs()) 
   y=a*sin(theta[0].rhs())*e^(b*theta[0].rhs()) 
   return theta,x,y 

def morestuff(a,b): 
   L=[] 
   t=var('t') 
   G=parametric_plot((a*cos(t)*e^(b*t),a*sin(t)*e^(b*t)),(t,0,3*pi),rgbcolor=hue(0.6),figsize=5,axes=True) 
   for i in range(1,20): 
      i=i/2 
      q,x,y=Pxy(7,a,b) 
      L.append([x.n(),y.n(),q[0].rhs().n()]) 
      #create a list of x,y,q pairs. 
      G+=point((x,y), color='red',pointsize=4) 
   G.show(figsize=4) 

@interact 
def putvariables(a = slider(range(1,200), default = 97),b = slider(range(100), default = 38) ): 
   a=a/100 
   b=b/100 
   morestuff(a,b)
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2013-09-22 23:13:47 +0100

calc314 gravatar image

Running morestuff(.97,.38) does not work for me. When I run morestuff, the values of x and y are coming out to be nonreal. So, that is causing the error. Note that morestuff(.3,.1) does work.

edit flag offensive delete link more
0

answered 2013-09-23 09:38:08 +0100

drdrugus gravatar image

Thank you. I will closely look at allowable parameters.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2013-09-22 19:10:12 +0100

Seen: 343 times

Last updated: Sep 23 '13