我正在盡力弄清楚我的代碼出了什么問題。所以我試圖解決不等式: $$5 \sin (\theta)-\frac{1}{2} \sin \left(\frac{5 \theta}{2}\right) \geq 0$$同情,但我只是不斷地回答我的問題。有人可以幫助我。
這是我的代碼:
import sympy as sp
import numpy as np
import matplotlib.pyplot as plt
from sympy import S
x, y = sp.symbols("x, y", real=True)
theta = sp.symbols("theta")
d = sp.symbols("d", real=True, positive=True)
y = 5 * sp.sin(theta) - d * sp.sin(sp.Rational(5,2) * theta)
y_with_d_a_half = y.subs(d,1/2)
sp.solveset(y >= 0, theta, domain=S.Reals)
當我運行它時,它回傳 $$$\left{\theta \mid \theta \in \mathbb{R} \wedge-d \sin \left(\frac{5 \theta}{2}\right) 5 \sin (\theta) \geq 0\right}$$
uj5u.com熱心網友回復:
當您進行替換時,您創建了一個新運算式并且沒有更改原始運算式 ( y) 并且運算式 fory無法以封閉形式求解。如果你檢查情節,你會看到有根,如果你檢查周期性,你會發現它是周期性的。因此,您可以獲得周期中根的數值,并通過加法或減法4pi獲得所有其他值。
>>> from sympy import S, sign, periodicity, nsolve
>>> eq = y.subs(d, S.Half);eq
5*sin(theta) - sin(5*theta/2)/2
>>> periodicity(eq,theta)
4*pi
>>> [nsolve(eq, 3*i).round(3) for i in range(5)]
[0, 3.044, 6.283, 9.522, 12.566]
這些是零——測驗中間的區域以找到函式為正的位置,例如
>>> sign(eq.subs(theta,1))
1
>>> sign(eq.subs(theta,4))
-1
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/407986.html
標籤:
上一篇:如何設定輸入模式?
下一篇:程式未顯示在二叉搜索樹中插入的值
