在Python中为系列扩展实现分析集成

问题描述

我非常想在计算器中实现分析集成。在成功尝试之前,我已经使用了数值积分。但是,我似乎无法使我的代码正常工作。 我正在使用scipy.integrate模块,得到的错误代码为TypeError: can't convert expression to float

我的代码是:

from sympy.functions import sin,cos,tan
from sympy.abc import x
from sympy import series
import scipy.integrate as integrate
import scipy.special as special

function1   = str(input("The function that should be expanded: "))
x0          = float(input("Point of developement: "))
n           = 1 + int(input("Grade of polynomial: "))
# input 0 -> n=1 -> konstant  (1 term,konstant)
# input 1 -> n=2 -> lineær    (2 termer,konstant + linear)
# input 2 -> n=3 -> kvadratisk (3 termer,konstant + linear + kvadratisk)
# ...

function2 = series(function1,x,x0,n)
print(function2)

a = float(input("Integrate from: "))
b = float(input("Integrate to: "))

def f(x):
    return function2.removeO()

x = Symbol('x')
result = integrate.quad(lambda x: f(x),a,b)

print("...................")
print("Here is your answer: ")
print(result)

我认为可能是由于代码使用了不同的模块(sympy和scipy),或者我只是需要以某种方式转换表达式。我尝试使用lambdify,但没有成功。

def f(x):
    return function2.removeO()
lam_f = lambdify(x,f(x))
result = integrate.quad(lambda x: lam_f,b)

又遇到另一个TypeError,因为lambdify会将表达式转换为函数。

有人可以帮忙吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...