得到的图theta2和答案不一样,不知道为什么,需要再检查!!!!!

"""niku 习题5.8"""
""" 乘除法要用数组  将列表转换为数组"""
import numpy as np
import matplotlib.pyplot as plt
import math  
plt.figure(figsize=(8,4))
""" 求theta1""" 
t =  np.arange(1,12,1)#生成一个数组,不是列表
px = list(np.array([3]*11))
py = list(np.arange(5,-6,-1))
pz = list(np.array([5]*11))
theta1=[0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.]
theta2=[0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.]
theta3=[0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.]
for s in range(0,11):
    a =math.atan2(px[s],py[s])
    theta1[s] = a
#print(theta1) 
  
"""求theta3""" 
for s in range(0,11):
    f = math.acos(((py[s]/math.cos(theta1[s]))**2+(pz[s]-8)**2-162)/162 )    
    theta3[s] = f
#print(theta3)
    
"""求theta2"""
for s in range(0,11):
    q = math.cos(theta1[s])*(pz[s]-8)*(1+math.cos(theta3[s]))+py[s]*math.sin(theta3[s])
    e = 18*(1+math.cos(theta3[s]))*math.cos(theta1[s])
    t = math.acos(q/e)
    theta2[s] = t*180/3.1415
    
for s in range(0,11):
    t = theta1[s]
    theta1[s] = t*180/3.1415

for s in range(0,11):
    t = theta3[s]
    theta3[s] = t*180/3.1415

"""开始画图 画图的时候要用数组"""
t = np.arange(1,12,1)
theta1 = np.array(theta1)
theta2 = np.array(theta2)
theta3 = np.array(theta3)
plt.plot(t,theta1,label="$theta1$",color="red",linewidth=2)
plt.plot(t,theta2,label="$theta2$",color="blue",linewidth=2)
plt.plot(t,theta3,label="$theta3$",color="green",linewidth=2)
plt.ylim(-20,180)
plt.xlim(-1,12)
plt.xlabel("point")
plt.ylabel("theta")
plt.legend(loc="upper left")
plt.grid(True)
plt.show()

  

 

posted on 2018-03-02 09:53  魂淡林  阅读(116)  评论(0编辑  收藏  举报