I need a help to update my theta value for each last two numbers for 5 element in the message:
msg = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
def get_new_theta(msg):
# addition for each last 2 number in 5 elements in the msg
# for example: new_theta=theta+(4+5), new_theta=new_theta+(9+10) and so on...
return new_theta
#initial theta
theta=1
for b in msg:
hwpx = [0,math.cos(4*math.radians(theta)),math.sin(4*math.radians(theta)), 0]
a=b*hwpx
print (a)
This is the expected output:
theta=1
1*[0,math.cos(4*math.radians(1)),math.sin(4*math.radians(1)), 0]
2*same as above
3*same as above
4*same as above
5*same as above
theta=1+(4+5)=10
6*[0,math.cos(4*math.radians(10)),math.sin(4*math.radians(10)), 0]
7*same as above
8*same as above
9*same as above
10*same as above
theta=10+(9+10)=29
Noted that the value of theta will be update for each 5 element. And the new theta will be used to calculated for the next element.
However,when I run this code, loop was not successfully implemented.
msg = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
theta=1
def get_new_theta(msg, theta):
new_theta = [theta]
for a, b in zip(msg[3::5], msg[4::5]):
new_theta.append(new_theta[-1] + a + b)
return new_theta
theta=1
for b in msg:
theta=get_new_theta(msg, theta)
hwpx = [0, math.cos(4*math.radians(theta)), math.sin(4*math.radians(theta)), 0]
a=b*hwpx
print (theta)
I got this error:
hwpx = [0, math.cos(4*math.radians(theta)), math.sin(4*math.radians(theta)), 0]
TypeError: a float is required`
Thank you