- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在做一个涉及整改的程序。唯一可以进行复杂集成的模块是 Scipy 及其 scipy.integrate.quad()
命令。但是,在我的代码中,我需要有一个代表函数本身的变量,因为在校正过程中最终会使用更多不同的函数,这些函数是使用前面的等式导出的。我所看到的关于该命令的每个来源都涉及 lambda 或创建输出方程式的定义。您手动输入方程式。所以,我的问题是,有没有办法在不这样做的情况下集成它?这是我的代码:
import scipy
import sympy
from scipy.integrate import quad
def rectify(smallestterm, nextsmallestterm, poly, coef, exp):
test = rectification(coef,exp)
a = quad(test, smallestterm, nextsmallestterm)
print(a)
a = a[0]
dist = a/2
return dist
def test(x):
return rectification(coef, exp)
def rectification(coef, exp):
u = Poly(lint(coef,exp)) #Generated Equation
b = u.all_coeffs()
poly = b
c = len(poly) - 1
exponents = []
while c + 1 > 0:
exponents.append(c)
c = c - 1
poly = function(poly,exponents) #Generated Equation in a form that can actually be used and identified as a function.
return sqrt(1+(pow(diff(poly),2)))
其中 coef
是多项式的主系数列表,exp
是多项式的主指数列表。本质上,它们都将间接组合在另一个定义中,function(coef, exp)
(未显示其代码)输出多项式(变量“poly
”) .
即
函数([2,4,5],[1,6,0])
输出
4*x**6 + 2*x + 5
此代码(在函数代码上方)不起作用,因为它不允许我使用变量“a”来表示整个函数,因为它仅将“a”识别为函数本身。 因此,lambda 不适用于我的情况。我不能简单地做类似的事情:
import scipy
import sympy
from scipy.integrate import quad
poly = 2*x**5 + 5*x**4 - 4*x**2 + 10 #Some complicated polynomial
d = diff(poly) #differential of polynomial
a = sqrt(1+(pow(d,2)))
e = quad(a, 1, 5)
e = e[1]/2
return e
如果您需要查看我的完整代码以了解此代码中的任何其他功能,请提出要求,我很乐意提供!
最佳答案
据我了解,您的代码使用 SymPy 生成符号表达式。这些不是 Python 意义上的函数,因为它们不能被调用。所以它们不能直接用作quad
的第一个参数。 SymPy 提供 lambdify
将表达式包装到函数中的方法:
quad(lambdify(x, expr), 0, 1)
这里的expr
可以是任意带有变量x
的符号表达式,例如expr = 4*x**6 + 2*x + 5
。
关于python - scipy.integrate.quad() 不使用 lambda,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41528681/
我无法理解 .quad函数在汇编中起作用。 从我在线阅读的内容来看,它为当前部分中的每个表达式生成一个 64 位二进制补码值。我明白什么是二进制补码以及该部分引用的行 .quad被称为。 何时何地 .
我是 python 的新手,正在尝试对函数进行数值积分。一切似乎都有效,但我得到的结果与我在 Mathematica 中得到的结果有很大不同(我知道这是正确的)。有人可以帮我弄清楚发生了什么吗? 代码
我有一个高度和宽度,我正在尝试用它们生成一个四边形。当我这样做时: vector vertices; vector indices; Point2D topLeft = Point2(0, heigh
我想要一个矩形立方体。一堵墙的脸朝反面所以我看不到粉红色。这是立方体好的一面: 在立方体的背面,墙的背面是灰色的: 这是代码: glBegin(GL_QUADS); //floor g
我正在尝试编写一些代码,将纹理渲染到一个简单的正方形上,但在让它工作时遇到了很多麻烦。我下载了一些用于纹理映射的示例源代码 here并编译它,它似乎可以很好地将纹理映射到他们的圆柱体上。然后,我添加了
Matlab 中似乎有一个错误 quad使用求积公式计算积分的函数。运行 quad(@(x) (2/sqrt(2*pi))*(x.^2).*exp(-x.^2/2), 0, 10) 回馈 1.0000
我目前正在使用Freebase转储进行项目开发,我将断言插入每个有序的LevelDB中。我的目标是能够给定名称,例如Bob Dylan,以检索与其名称链接的所有类型。 例如,“鲍勃·迪伦”对应于“音乐
import math from scipy.integrate import quad def integrand(x): return 1/math.log(x) for i in ran
我正在尝试使用 Jena 读取 N-Quads 文件,但我得到的只是一个空模型。我试图读取的文件取自 N-Quads documentation 中的示例: .(我将其保存为名为 file.n
我正在尝试使用 Jena 读取 N-Quads 文件,但我得到的只是一个空模型。我试图读取的文件取自 N-Quads documentation 中的示例: .(我将其保存为名为 file.n
我刚开始学习 OpenGL,遇到了一个有趣的错误(这可能是我的不当行为造成的) 但是,我似乎无法弄清楚为什么我的脸在默认情况下被绘制在两侧,而不是一个。下面是一些描述问题的截图 当我继续启用 GL_C
这是有问题的代码: glColor3f(1,1,1); for(int x=0;x 最佳答案 你只有三个 glVertex2f 调用,而你应该有四个(在 GL_QUADS 内)。你有四个 glTexC
你好,我在 C++ 中使用 glut 和 opengl,我有家,我想在其中绘制蓝色 QUADS 我的问题是,当我将 QUADS 绘制为蓝色时,我的所有感觉颜色都是蓝色的,所以我如何才能仅将 QUADS
我正在使用 visual c++ 2012 和 opengl,但无法绘制四边形,我没有遇到任何错误。是因为我没有更新方法吗?这是我的代码: #define WIN32_LEAN_AND_MEAN #i
我已经使用 OpenTK 和 OpenGL 为游戏设置了一个快速的 2D 渲染系统。我已经使用以下方法设置了透明度: GL.Enable(EnableCaps.Blend); GL.BlendFunc
我有一个随机数量的顶点列表,我想获得 2 个四边形三角形的索引。每四个顶点应构成 2 个三角形。例如: 0,1,2, 0,2,3, 4,5,6, 4,6,7, 8,9,10, 8,10,11 我确
题目地址:https://leetcode.com/problems/construct-quad-tree/description/ 题目描述 Wewant to use quad trees
我以 N-Quads、.nq 文件的形式从 Nature 下载了一堆数据。这些包含 RDF 图,对吗?如何访问这些数据,以及如何将 RDF 图形转换为更可用的格式(最好是 R/C++/Python 的
我有一个线框着色器,可以在左侧立方体上显示三角形,并希望对其进行更新,使其仅显示四边形,例如在右侧立方体上。 这是代码: Shader "Custom/Wireframe" { Propert
我正在 PyOpenGL 中制作一个游戏,其中一个对象(例如长方体)应该面向相机。为此,我必须旋转特定对象。我怎样才能做到这一点? glRotatef() 旋转整个世界,但不是单个对象,所以我不能使用
我是一名优秀的程序员,十分优秀!