在Python中积分多项式并设置积分下限


要积分多项式,请使用Python中的`polynomial.polyint()`方法。该方法返回沿指定轴从lbnd积分m次的系数c。在每次迭代中,结果序列将乘以scl,并添加积分常数k。缩放因子用于线性变量变化。参数c是系数数组,沿每个轴从低到高排序,例如:[1,2,3]表示多项式1 + 2*x + 3*x**2,而[[1,2],[1,2]]表示1 + 1*x + 2*y + 2*x*y(如果axis=0是x,axis=1是y)。

该方法返回积分的系数数组。第一个参数c是一维多项式系数数组,从低到高排序。第二个参数m是积分阶数,必须为正数。(默认值:1)。

第三个参数k是积分常数。第一个积分在零处的值为列表中的第一个值,第二个积分在零处的值为第二个值,依此类推。如果k == [](默认值),则所有常数都设置为零。如果m == 1,则可以提供单个标量而不是列表。第四个参数lbnd是积分的下限。(默认值:0)

第五个参数是scl。每次积分后,结果将在添加积分常数之前乘以scl。(默认值:1)。第六个参数是axis。它是积分所取的轴。(默认值:0)。

步骤

首先,导入所需的库:

import numpy as np
from numpy.polynomial import polynomial as P

创建一个多项式系数数组:

c = np.array([1,2,3])

显示系数数组:

print("Our coefficient Array...\n",c)

检查维度:

print("\nDimensions of our Array...\n",c.ndim)

获取数据类型:

print("\nDatatype of our Array object...\n",c.dtype)

获取形状:

print("\nShape of our Array object...\n",c.shape)

要积分多项式,请使用Python中的`polynomial.polyint()`方法。该方法返回沿指定轴从lbnd积分m次的系数c。在每次迭代中,结果序列将乘以scl,并添加积分常数k。缩放因子用于线性变量变化。参数c是系数数组,沿每个轴从低到高排序,例如:[1,2,3]表示多项式1 + 2*x + 3*x**2,而[[1,2],[1,2]]表示1 + 1*x + 2*y + 2*x*y(如果axis=0是x,axis=1是y)。

print("\nResult...\n",P.polyint(c, lbnd = -2))

示例

import numpy as np
from numpy.polynomial import polynomial as P

# Create an array of polynomial coefficients
c = np.array([1,2,3])

# Display the coefficient array
print("Our coefficient Array...\n",c)

# Check the Dimensions
print("\nDimensions of our Array...\n",c.ndim)

# Get the Datatype
print("\nDatatype of our Array object...\n",c.dtype)

# Get the Shape
print("\nShape of our Array object...\n",c.shape)

# To Integrate a polynomial, use the polynomial.polyint() method in Python
print("\nResult...\n",P.polyint(c, lbnd = -2))

输出

Our coefficient Array...
[1 2 3]

Dimensions of our Array...
1

Datatype of our Array object...
int64

Shape of our Array object...
(3,)

Result...
[6. 1. 1. 1.]

更新于:2022年2月28日

112 次浏览

启动你的职业生涯

完成课程获得认证

开始学习
广告
© . All rights reserved.