cauchy_convergence.py
1from manim import *2import numpy as np3 4config.tex_template = TexTemplateLibrary.ctex5config.tex_template.add_to_preamble(r"\setCJKmainfont{STSong}")6 7class CauchyConvergence(Scene):8 def construct(self):9 # 创建标题10 title = Text("柯西收敛原理演示", font="STSong", font_size=48)11 12 self.play(Write(title))13 self.wait(1)14 self.play(FadeOut(title))15 16 # 创建坐标系17 axes = Axes(18 x_range=[0, 10, 1],19 y_range=[0, 1.2, 0.2],20 axis_config={"include_tip": True},21 x_length=10,22 y_length=623 )24 25 x_label = axes.get_x_axis_label("n")26 y_label = axes.get_y_axis_label("a_n")27 28 self.play(Create(axes), Write(x_label), Write(y_label))29 30 # 创建数列点31 def get_points(n_points):32 return [axes.coords_to_point(x, 1/x) for x in range(1, n_points + 1)]33 34 dots = VGroup(*[Dot(point) for point in get_points(10)])35 36 # 显示点37 self.play(Create(dots))38 self.wait(1)39 40 # 演示柯西条件41 # 先创建柯西条件的数学表达式42 cauchy_condition = MathTex(43 r"\forall \varepsilon > 0, \exists N \in \mathbb{N}, ",44 r"\forall n,m > N: |a_n - a_m| < \varepsilon"45 ).scale(0.8)46 # 将表达式移到右上角47 cauchy_condition.to_corner(UR)48 self.play(Write(cauchy_condition))49 50 # 创建说明文字(在循环外创建)51 explanation = Text(52 "N之后任意两项差的绝对值不会超过ε",53 font="STSong",54 color=YELLOW55 ).scale(0.4)56 # 将说明文字固定在上方位置57 explanation.to_edge(UP).shift(DOWN * 2)58 59 # 依次演示不同的ε值60 for i, epsilon in enumerate([0.3, 0.2, 0.1]):61 N = int(1/epsilon) - 162 min_y = 1/(N+5) # N之后某个点的y值63 max_y = 1/N # N处的y值64 reference_y = (max_y + min_y) / 265 66 # 创建两条水平线,确保包含曲线,并延长到整个x轴范围67 upper_line = DashedLine(68 axes.coords_to_point(0, max_y + epsilon/4),69 axes.coords_to_point(10, max_y + epsilon/4),70 color=RED71 )72 lower_line = DashedLine(73 axes.coords_to_point(0, min_y - epsilon/4),74 axes.coords_to_point(10, min_y - epsilon/4),75 color=RED76 )77 78 # 添加竖直的距离标注(移到右侧)79 distance_line = Line(80 axes.coords_to_point(9.5, max_y + epsilon/4),81 axes.coords_to_point(9.5, min_y - epsilon/4),82 color=RED83 )84 epsilon_brace = Brace(distance_line, direction=RIGHT, color=RED)85 epsilon_label = MathTex(r"\varepsilon", color=RED).next_to(epsilon_brace, RIGHT)86 87 epsilon_band = VGroup(88 upper_line, lower_line,89 distance_line, epsilon_brace, epsilon_label90 )91 92 self.play(93 Create(upper_line),94 Create(lower_line),95 Create(distance_line),96 Create(epsilon_brace),97 Write(epsilon_label)98 )99 100 # 创建N的垂直线101 N_line = DashedLine(102 axes.coords_to_point(N, 0),103 axes.coords_to_point(N, 1.2),104 color=GREEN105 )106 # 将N的标注移到下方107 N_text = Text("N", font="STSong", color=GREEN).next_to(108 axes.coords_to_point(N, 0),109 DOWN110 )111 112 # 显示N线113 self.play(114 Create(N_line),115 Write(N_text)116 )117 118 # 在N显示后再显示说明文字119 if i == 0:120 self.play(Write(explanation))121 122 self.wait(1.5)123 124 # 清除当前ε的演示内容125 self.play(126 FadeOut(epsilon_band),127 FadeOut(N_line),128 FadeOut(N_text)129 )130 131 # 显示极限存在的结论132 limit_text = VGroup(133 MathTex(r"\lim_{n \to \infty} a_n"),134 Text("存在", font="STSong", color=WHITE).scale(0.8)135 ).arrange(RIGHT, buff=0.2)136 # 将结论放在定理下方137 limit_text.next_to(cauchy_condition, DOWN, buff=0.5)138 self.play(Write(limit_text))139 self.wait(2)140 141def main():142 import os143 os.system("manim -pql cauchy_convergence.py CauchyConvergence")144 145if __name__ == "__main__":146 main() 讲解
这个视频围绕「柯西收敛原理演示」展开。画面把问题、图像和公式放在同一条理解路径中,让抽象关系先被看见。
开头先建立问题背景和主要对象,让观察从标题、坐标或第一组关系进入。
画面中出现的文字「柯西收敛原理演示」给出视觉入口。随后画面通过对象创建、移动、淡入淡出和高亮,把抽象命题拆成可以跟随的步骤。
随后出现更具体的图像或公式提示,动画会把局部对象和整体结论联系起来。这里可以重点观察变量、曲线、区域或向量如何随镜头推进而变化。
核心公式可以写成:
这类公式可以和画面中的符号一一对应。
观察路径
观察路径可以分三步:先锁定「柯西收敛原理演示」中的核心对象,尤其留意柯西收敛原理、数列收敛、epsilon-N 定义之间的联系;再跟随画面中变量、图像或向量的变化;最后回到公式或结论,判断局部变化如何支撑整体关系。
本页可以从柯西收敛原理、数列收敛、epsilon-N 定义这些概念进入,继续沿相邻问题观察同一类数学结构。