Harder方程(带导数和积分)和条件集

2024-10-02 00:37:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我计划计算b(也是Xo轴上的x),从0到x的曲线(函数)长度等于1

通过了解:https://www.mathsisfun.com/calculus/arc-length.html

(从0到b的积分)∫ (1+((f'(x))^2)^(1/2)dx=1

而且:

(从a到b的积分)∫ f(x)dx=f(b)-f(a)

我们可以通过

1-F(0)+F(b)=0,这里这是一个关于x的方程,因为我说的b是x轴上的x

所以现在我尝试了f(x)=x**3(下面是完整的代码)

F(b)等于这个怪物:https://www.wolframalpha.com/input/?i=integral&assumption=%7B%22C%22%2C+%22integral%22%7D+-%3E+%7B%22Calculator%22%7D&assumption=%7B%22F%22%2C+%22Integral%22%2C+%22integrand%22%7D+-%3E%22%281+%2B+9x%5E4%29%5E%281%2F2%29%22

我从SymPy得到的只是条件集,而不是数字。当然,条件集不能由evalf()求值

我的问题是:

  • 我数学有错吗
  • 我的代码错了吗?如何改进
  • SymPy够计算这个吗
  • 我误解文件了吗

代码:

from __future__ import division
import matplotlib.pyplot as plt
from sympy import *

x, y, z = symbols('x y z', real=True)

function1 = x**3

Antiderivative1 = integrate((1+(diff(function1))**2)**(1/2), x)

b = solveset(Eq(1 + Antiderivative1.subs(x, 0).evalf() - Antiderivative1, 0), x)

print(b)

这就是输出:

ConditionSet(x, Eq(x*hyper((-0.5, 1/4), (5/4,), 9*x**4*exp_polar(I*pi)) - 4.0*gamma(5/4)/gamma(1/4), 0), Complexes)

提前谢谢,抱歉语法错误


Tags: 代码fromhttpsimportcomwww条件eq
1条回答
网友
1楼 · 发布于 2024-10-02 00:37:37

请注意,您应该使用S(1)/2Rational(1, 2)(或sqrt),而不是1/2,这将在Python中为您提供float。有了这个我们就有了

In [16]: integrand = sqrt(1 + ((x**3).diff(x))**2)                                                                                

In [17]: integrand                                                                                                                
Out[17]: 
   __________
  ╱    4     
╲╱  9⋅x  + 1 

In [18]: antiderivative = integrand.integrate(x)                                                                                  

In [19]: antiderivative                                                                                                           
Out[19]: 
          ┌─  ⎛-1/2, 1/4 │    4  ⅈ⋅π⎞
x⋅Γ(1/4)⋅ ├─  ⎜          │ 9⋅x ⋅ℯ   ⎟
         2╵ 1 ⎝   5/4    │          ⎠
─────────────────────────────────────
               4⋅Γ(5/4) 

虽然这与Wolfram Alpha的结果形式不同,但很容易是相同的函数(直到一个加法常数)。从这个结果或者Wolfram Alpha的结果来看,我非常怀疑你是否能找到解析解(使用SymPy或其他方法)

但是你可以找到一个数值解。不幸的是,symphy的lambdify函数中有一个bug,这意味着nsolve不能使用此函数:

In [22]: nsolve(equation, x, 1)                                                                                                   
...
NameError: name 'exp_polar' is not defined

我们可以自己用牛顿步来做:

In [76]: f = equation.lhs                                                                                                         

In [77]: fd = f.diff(x)                                                                                                           

In [78]: newton = lambda xi: (xi - f.subs(x, xi)/fd.subs(x, xi)).evalf()                                                          

In [79]: xj = 1.0                                                                                                                 

In [80]: xj = newton(xj); print(xj)                                                                                               
0.826749667942050

In [81]: xj = newton(xj); print(xj)                                                                                               
0.791950624620750

In [82]: xj = newton(xj); print(xj)                                                                                               
0.790708415511451

In [83]: xj = newton(xj); print(xj)                                                                                               
0.790706893629886

In [84]: xj = newton(xj); print(xj)                                                                                               
0.790706893627605

In [85]: xj = newton(xj); print(xj)                                                                                               
0.790706893627605

相关问题 更多 >

    热门问题