9
数値積分を使用して定積分の評価を近似する簡単なプログラムを書きました。しかし、タイトルに誤りがあるのはなぜですか?あなたが私を助けることができたら私はまだ感謝するだろう:)私は行方不明であることを信じられないほど明白な何かであるかもしれないので、私は1年半でPythonに触れていないことを覚えておいてください:)コード:Python TypeError:^: 'float'と 'int'のためのサポートされていないオペランドタイプ
ここでimport math
def f(x):
f=math.sqrt(1+(6*x+4)^2)
return f
lbound=int(input("Input lower bound for the integral"))
ubound=int(input("Input upper bound for the integral"))
n=int(input("Input number of intervals"))
dx=((ubound-lbound)/n)
integral=0
for i in range(1,n):
integral=integral+dx*f(i*dx)
print (integral)
は、コードを実行しようとしたとき、完全なエラーレポートIDLEは私を与えるです:
Traceback (most recent call last):
File "C:\Users\******\Desktop\integrals.py", line 13, in <module>
integral=integral+dx*f(n*dx)
File "C:\Users\******\Desktop\integrals.py", line 3, in f
f=math.sqrt(1+(6*x+4)^2)
TypeError: unsupported operand type(s) for ^: 'float' and 'int'
ありがとう、私はそれが愚かなものになるとは思わなかった!だから、とにかく^演算子は、Pythonで何ですか? –
@Aris Pap: '^'は 'float'に適用できないXOR演算子です。 – eph