2017-01-20 8 views
-2

友人をフロートだ、私は、Pythonに新たなんだとお互いに3つの曲線をプロットしようとしているが、私は理解することはできませんいくつかの問題を抱えて:Pythonの例外TypeError:予想レンジ()整数エンド引数は、

私は別のベクトルでボールの軌道を解決しよう:

の1-異なるxは 、3-異なる角度が

 import numpy as np 
import math as m 
import matplotlib.pylab as pl 


def ball(x, theta, v0, y0): 
    v0= v0/3.6 
    g = 9.81 
    theta = m.radians(theta) 
    return x * m.tan(theta) + y0\ 
       - 1./(2.0 * v0 ** 2.0) * g * x**2.0/(m.cos(theta)**2) 

x = np.linspace(0, 10, 100) 

#part1 
theta = 60 
y0 = 1.0  
v0= 15.0 
y = ball(x, theta, v0, y0) 
pl.plot(x, y) 


#part2 
theta = 60 
y0 = 1.0 
for v0 in range(10.0, 60.0, 10.0): 
    y2 = ball(x, theta, v0, y0) 
    pl.plot(x, y) 

#part3 
y0 = 1.0 
for theta in range(0.0, 112.5, 22.5): 
    y3 = ball(x, theta, v0, y0) 
    pl.plot(x, y) 

pl.plot(x, y, "r*") 
pl.plot(x, y2, "bo") 
pl.plot(x, y3, "y^") 
pl.xlabel("X") 
pl.ylabel("Y") 
pl.legend(["x,y","x,y","x,y"]) 
pl.show() 

値 2 - 異なる速度値を値に何が起こっているか私を助けてください?

+1

は何がエラーメッセージに関する不明ですか?浮動小数点数を 'range()'関数に渡しています。代わりに整数で渡してください。 –

+0

私の問題は私がフローティングを使うべきだということでした、今私はそれを使用する方法を知っています、 – Hitch

答えて

1

range関数は浮動小数点数を引数として受け入れないため、に整数を使用する必要があります。その代わりにできることは、range関数の各部分を10倍に増やし、ループ内で10倍に減らすことです。たとえば:range()上のPython 2.7ドキュメントから

for i in range(int(0.0*10), int(112.5*10), int(22.5*10)): 
    realI = i/10.0 
    #now realI is the float you had wanted originally. 
+0

ありがとう、それは私が見つけることを試みたものです。 – Hitch

+0

問題はありません!将来の人々がそれを見つけることができるように答えとしてマークする必要があります! – chukrum47

0

範囲(値、終了値、ステップを開始)

あなたは、フローティングタイプ番号を使用することはできませんが、整数を使用します。

0

This is a versatile function to create lists containing arithmetic progressions. It is most often used in for loops. The arguments must be plain integers. If the step argument is omitted, it defaults to 1. If the start argument is omitted, it defaults to 0. The full form returns a list of plain integers [start, start + step, start + 2 * step, ...]. If step is positive, the last element is the largest start + i * step less than stop; if step is negative, the last element is the smallest start + i * step greater than stop. step must not be zero (or else ValueError is raised).

関連する問題