I'm traying to write a code that have r_1 and r_2 are vectors and the other parameters are float. I got this error and i don't know why ! i think the problem in type of n_1 or n_H
import numpy as np
from numpy import *
#import math
r_1=[]
for i in range(3):
v=input("Elemnts1: ")
r_1 = append(r_1,v)
print(r_1)
r_2=[]
for i in range(3):
v=input("Elemnts2: ")
r_2 = append(r_2,v)
print(r_2)
Delta_theta=float(input("Delta_theta="))
t_1=float(input("t_1="))
t_2=float(input("t_2="))
Delta_t= t_2 - t_1
def orbit_determination(r_1,r_2,Delta_theta,Delta_t):
mu=398600.0
m=(mu*(Delta_t)**2)/(2*np.sqrt(np.dot(r_1,r_2))*np.cos(Delta_theta/2))**3
L_1= (r_1+r_2)/4*np.sqrt(np.dot(r_1,r_2))*np.cos(Delta_theta/2)
L= L_1 -(1/2)
n_H=(12/22)+(10/22)*np.sqrt(1+((44*m)/9*(L+(5/6))))
n_1=n_H+0.1
#compute the Semi-parameter from
p=(n_1**2)*np.cross((r_1,r_2)**2)/mu*((Delta_t)**2)
File "orbit_determinition11.py", line 51, in <module>
orbit_determination(r_1,r_2,Delta_theta,Delta_t)
File "orbit_determinition11.py", line 27, in orbit_determination
p=(n_1**2)*np.cross((r_1,r_2)**2)/mu*((Delta_t)**2)
TypeError: unsupported operand type(s) for ** or pow(): 'tuple' and 'int'
When declaring float numbers, you need to use .
, so when you introduce a number in the variables you need to make sure that the format is 2.3
and not 2,3
, otherwise you are declaring a tuple.
maybe you should add p = int(p)
before line 27. I guess it might work.
As Matthias hints to in a comment
So what do you expect
(r_1,r_2)**2
to do?
The problem is on the line
p=(n_1**2)*np.cross((r_1,r_2)**2)/mu*((Delta_t)**2)
specifically
np.cross((r_1,r_2)**2)
As you're calling np.cross
which
Return the cross product of two (arrays of) vectors.
Returns
c: ndarray
Vector cross product(s).
The argument you're passing it is (r_1,r_2)**2
which constructs a tuple of the r_1
and r_2
vectors and attempts to raise it to the power of two (which isn't supported), which is why you're getting
File "orbit_determinition11.py", line 27, in orbit_determination p=(n_1**2)*np.cross((r_1,r_2)**2)/mu*((Delta_t)**2) TypeError: unsupported operand type(s) for ** or pow(): 'tuple' and 'int'
It looks like n_1
, mu
, and Delta_t
are floats - though it's not clear from your code what you're trying to do and what p
is supposed to be:
If p
is a vector, possibly the **2
is a typo:
p=(n_1**2)*np.cross(r_1,r_2)/mu*((Delta_t)**2)
If p
is a float, possibly np.dot
was meant:
p=(n_1**2)*((np.dot(r_1,r_2))**2)/mu*((Delta_t)**2)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.