I am trying to define the archimedean spiral: when im trying to define the inclination angle (incl) of the tangent vector to the orbit ( i.e: tan(incl)) im getting an error :"'numpy.ufunc' object does not support item assignment".
the same error when I want to calculate cos(incl), and sin(incl).
Any suggestion and help.
My code is:

``````a= 2.     # will turn the spiral
v= 0.23
omega = 0.2
r0 = v/omega
t=np.linspace(0,T,N+1)
r= v*t
#theta = a + r/r0
theta  =  omega*t

x=r* np.cos( omega*t)
y=r* np.sin( omega*t)

dxdr = np.cos(theta) - (r/r0)*np.sin(theta)
dydr = np.sin(theta) + (r/r0)*np.cos(theta)

dydx = (r0*np.sin(theta) + r*np.cos(theta))/r0*np.cos(theta) - r*np.sin(theta)

np.tan[incl]= dydx
incl = np.arctan((dydx))

### Calculate cos(incl) ,sin(incl) :
np.sin[np.incl] = np.tan(np.incl)/np.sqrt(1+ np.tan(np.incl)*2)
np.cos[incl] = 1/np.sqrt(1+ np.tan(incl)*2)
``````

Edited by Reverend Jim: Moved to the programming forum

2
Contributors
1
21
Views
2 Years
Discussion Span
Last Post by Gribouillis

This code runs without error. I'm not sure it's computing what you want

``````import numpy as np
T = 5
N = 50

a= 2.     # will turn the spiral
v= 0.23
omega = 0.2
r0 = v/omega
t=np.linspace(0,T,N+1)
r= v*t
#theta = a + r/r0
theta  =  omega*t

x=r* np.cos( omega*t)
y=r* np.sin( omega*t)

dxdr = np.cos(theta) - (r/r0)*np.sin(theta)
dydr = np.sin(theta) + (r/r0)*np.cos(theta)

dydx = (r0*np.sin(theta) + r*np.cos(theta))/r0*np.cos(theta) - r*np.sin(theta)

#np.tan[incl]= dydx
incl = np.arctan(dydx)

### Calculate cos(incl) ,sin(incl) :
sinincl = np.tan(incl)/np.sqrt(1+ np.tan(incl)*2)
cosincl = 1/np.sqrt(1+ np.tan(incl)*2)
``````

Don't use square brackets when normal brackets are required. Also there is no object `np.incl`. Finally a function call can never appear on the left hand side of an `=` operator (One cannot have `f(x) = 3` for example). This is not true for operators
such as `+= , *= , ==` etc.