跳到内容
🛠️ToolsShed

Euler's Number Calculator

使用泰勒级数近似、连续复利和正态分布探索欧拉数e。

欧拉数 (e)

e = 2.718281828459045

关于此工具

欧拉数(e ≈ 2.71828)是微积分、统计学、金融和物理学中最重要的数学常数。它表示自然对数的底数,并描述连续增长和衰减。这个计算器通过泰勒级数近似、连续复利和正态分布来帮助您探索e的行为。泰勒级数展示了数学家如何将这个无穷常数计算到任意精度。

通过调整泰勒级数项数,观察近似值如何收敛到e的真实值。连续复利模拟器展示了当利息无限复利时欧拉数如何出现——这是金融数学的核心概念。正态分布查看器显示著名的钟形曲线,其数学公式依赖于e,在统计学和数据科学中至关重要。

这个工具适合学习微积分和统计学的学生、使用数学库的开发人员,以及任何对基本常数如何塑造现实世界现象感到好奇的人。每个可视化都实时更新,让您可以尝试不同的参数并建立对指数增长、概率分布以及支撑日常金融和科学计算的深层数学的直观理解。

常见问题

代码实现

import math
from decimal import Decimal, getcontext

# 1. Taylor series approximation of e
def euler_taylor(n_terms: int) -> float:
    """Approximate e using n terms of Taylor series: sum(1/k!) for k=0..n"""
    total = 0.0
    factorial = 1
    for k in range(n_terms):
        if k > 0:
            factorial *= k
        total += 1 / factorial
    return total

# 2. High-precision e using Python's decimal module
def euler_high_precision(decimal_places: int) -> Decimal:
    getcontext().prec = decimal_places + 10  # extra guard digits
    e = Decimal(0)
    factorial = Decimal(1)
    for k in range(200):  # 200 terms is enough for 100+ decimal places
        if k > 0:
            factorial *= k
        term = Decimal(1) / factorial
        e += term
        if term < Decimal(10) ** -(decimal_places + 5):
            break
    return +e  # re-apply precision

# 3. Common formulas involving e
def compound_continuous(principal: float, rate: float, years: float) -> float:
    """A = P × e^(r×t) — continuous compounding formula"""
    return principal * math.exp(rate * years)

def normal_pdf(x: float, mu: float = 0, sigma: float = 1) -> float:
    """Normal distribution PDF: f(x) = (1/σ√2π) × e^(-(x-µ)²/2σ²)"""
    return (1 / (sigma * math.sqrt(2 * math.pi))) * math.exp(-((x - mu)**2) / (2 * sigma**2))

# Examples
print(f"e (Python math):     {math.e}")
print(f"e (5 terms):         {euler_taylor(5):.8f}")
print(f"e (20 terms):        {euler_taylor(20):.15f}")

# Euler's identity: e^(iπ) + 1 = 0
e_to_ipi = math.exp(complex(0, math.pi))
print(f"\ne^(iπ) = {e_to_ipi.real:.10f} + {e_to_ipi.imag:.0f}i")
print(f"e^(iπ) + 1 = {e_to_ipi.real + 1:.2e}  (≈ 0, Euler's identity)")

# Continuous compounding
amount = compound_continuous(1000, 0.05, 10)
print(f"\n$1000 at 5% for 10 years (continuous): ${amount:.2f}")

# Normal distribution at x=0
print(f"Normal PDF at x=0: {normal_pdf(0):.6f}")

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.