3

計算でさらに使用される整数値の配列を作成しようとしています。問題は、integrate.quad が (answer, error) を返すことです。フロートではないため、他の計算では使用できません。2 つの数字のセットです。

4

2 に答える 2

10

@BrendanWoodの答えは問題ありません。あなたは受け入れたので、明らかにうまくいきますが、これを処理するための別のpythonイディオムがあります。Python は「複数代入」をサポートしています。つまりx, y = 100, 200、代入x = 100y = 200. ( Python 入門チュートリアルの例については、http://docs.python.org/2/tutorial/introduction.html#first-steps-towards-programmingを参照してください。)

このアイデアをquadで使用するには、次のようにします (ブレンダンの例を変更したもの)。

# Do the integration on f over the interval [0, 10]
value, error = integrate.quad(f, 0, 10)

# Print out the integral result, not the error
print('The result of the integration is %lf' % value)

このコードは読みやすいと思います。

于 2013-07-23T20:20:51.253 に答える
4

integrate.quadは 2 つの値の を返しtupleます (場合によってはさらに多くのデータも返されます)。返されたタプルの 0 番目の要素を参照することで、回答値にアクセスできます。例えば:

# import scipy.integrate
from scipy import integrate

# define the function we wish to integrate
f = lambda x: x**2

# do the integration on f over the interval [0, 10]
results = integrate.quad(f, 0, 10)

# print out the integral result, not the error
print 'the result of the integration is %lf' % results[0]
于 2013-07-23T19:44:16.010 に答える