You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在SymPy的泰勒级数展开结果中隐藏阶项O(x**6)?

Removing the Big-O Term from SymPy Series Expansions

Absolutely, there are a couple of straightforward ways to strip off that big-O term from your SymPy series expansion. Let me walk you through them:

Method 1: Use the removeO() Method

This is the most direct and built-in solution—SymPy has a dedicated method for exactly this use case. Just call removeO() on your series object:

from sympy import cos, series, symbols

x = symbols('x')
# Generate the series expansion
cos_series = series(cos(x), x, n=5)
# Remove the O(x**6) term
clean_expansion = cos_series.removeO()

print(clean_expansion)
# Output: 1 - x**2/2 + x**4/24

The removeO() method automatically drops the asymptotic remainder term, leaving you with just the polynomial part of the expansion.

Method 2: Manually Extract Polynomial Terms

If you want more control over the terms (like picking specific parts of the expansion), you can access the individual components of the series object and combine them without the last O-term:

from sympy import cos, series, symbols, Add

x = symbols('x')
cos_series = series(cos(x), x, n=5)
# The series args include all terms; the last one is the O-term
polynomial_terms = cos_series.args[:-1]
# Combine the terms into a single expression
clean_expansion = Add(*polynomial_terms)

print(clean_expansion)
# Output: 1 - x**2/2 + x**4/24

This approach is useful if you need to manipulate individual terms before combining them, but for most cases, removeO() is the simpler choice.

内容的提问来源于stack exchange,提问作者George

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:50:04