级数与函数逼近可视化

正项级数的比较判别法

围绕正项级数的比较判别法,观察比较判别法、正项级数、级数收敛之间的关系与推理路径。

打开原视频

series_comparison.py
1# -*- coding: utf-8 -*-2from manim import *3import numpy as np4 5class SeriesComparisonTest(Scene):6    def construct(self):7        # 设置默认字体8        Text.set_default(font="SimSun")9        10        # 标题11        title = Text("正项级数的比较判别法").scale(0.8)12        title.to_edge(UP, buff=0.5)13        self.play(Write(title))14        self.wait(1)15 16        # 展示两个级数17        series1 = MathTex(r"\sum_{n=1}^{\infty} \frac{1}{n^2}")18        series2 = MathTex(r"\sum_{n=1}^{\infty} \frac{1}{n}")19        20        series_group = VGroup(series1, series2).arrange(DOWN, buff=0.5)21        series_group.next_to(title, DOWN, buff=1)22        23        self.play(Write(series1))24        self.play(Write(series2))25        self.wait(1)26 27        # 创建主坐标系28        axes = Axes(29            x_range=[0, 10, 1],30            y_range=[0, 2, 0.5],31            axis_config={"include_tip": True},32            x_length=8,33            y_length=534        ).scale(0.8)35        axes.shift(DOWN * 0.5)36        37        # 添加坐标轴标签38        x_label = Text("n").scale(0.6)39        y_label = Text("通项").scale(0.6)40        x_label.next_to(axes.x_axis, RIGHT)41        y_label.next_to(axes.y_axis, UP)42        43        axes_group = VGroup(axes, x_label, y_label)44        self.play(Create(axes_group))45 46        # 定义两个数列的通项函数47        def a_n(x):48            return 1/(x**2) if x > 0 else 249            50        def b_n(x):51            return 1/x if x > 0 else 252 53        # 先绘制主坐标系中的曲线54        curve1 = axes.plot(55            a_n,56            color=BLUE,57            x_range=[0.5, 10, 0.01]58        )59        curve2 = axes.plot(60            b_n,61            color=RED,62            x_range=[0.5, 10, 0.01]63        )64 65        # 添加曲线标签66        curve1_label = MathTex(r"a_n = \frac{1}{n^2}", color=BLUE).scale(0.6)67        curve2_label = MathTex(r"b_n = \frac{1}{n}", color=RED).scale(0.6)68        curve1_label.next_to(curve1.point_from_proportion(0.3), UP)69        curve2_label.next_to(curve2.point_from_proportion(0.3), UP)70 71        self.play(72            Create(curve1),73            Create(curve2),74            Write(curve1_label),75            Write(curve2_label)76        )77        self.wait(1)78 79        # 绘制完主图后,添加放大部分80        # 添加局部放大坐标系81        magnified_axes = Axes(82            x_range=[9, 20, 2],  # 放大9到20的部分83            y_range=[0, 0.2, 0.05],  # 调整y轴范围以更好地显示趋势84            axis_config={85                "include_tip": True,86                "numbers_to_exclude": ["all"],87                "tick_size": 0.05,88            },89            x_length=3,90            y_length=3,91            tips=True92        ).scale(0.8)93        magnified_axes.to_corner(UR, buff=0.5)94        95        # 添加放大区域标题96        magnified_title = Text("n>9区域放大图", font="SimSun").scale(0.4)97        magnified_title.next_to(magnified_axes, UP, buff=0.2)98        99        # 添加放大区域的边框100        magnified_box = SurroundingRectangle(101            magnified_axes,102            buff=0.2,103            color=YELLOW,104            stroke_width=2105        )106        107        # 在主坐标系中标记放大区域108        zoom_region = Rectangle(109            width=0.8,110            height=0.4,111            color=YELLOW,112            stroke_width=2113        ).move_to(axes.c2p(9.5, 0.1))  # 放在(9.5, 0.1)位置114        115        # 连接线116        connection_lines = VGroup(117            Line(118                zoom_region.get_corner(UR),119                magnified_box.get_corner(DL),120                color=YELLOW,121                stroke_width=1122            ),123            Line(124                zoom_region.get_corner(DR),125                magnified_box.get_corner(DL),126                color=YELLOW,127                stroke_width=1128            )129        )130        131        # 在放大区域绘制曲线132        magnified_curve1 = magnified_axes.plot(133            a_n,134            color=BLUE,135            x_range=[9, 20, 0.01]136        )137        magnified_curve2 = magnified_axes.plot(138            b_n,139            color=RED,140            x_range=[9, 20, 0.01]141        )142 143        # 显示放大部分的动画144        self.play(145            Create(magnified_axes),146            Write(magnified_title),147            Create(magnified_box)148        )149        self.play(150            Create(zoom_region),151            Create(connection_lines)152        )153        self.play(154            Create(magnified_curve1),155            Create(magnified_curve2)156        )157        self.wait(1)158 159        # 修改比较过程,使用比较判别法160        comparison = VGroup(161            Text("对于任意", font="SimSun").scale(0.6),162            MathTex(r"n \geq 1").scale(0.6),163            Text(",有:", font="SimSun").scale(0.6),164            MathTex(r"\frac{1}{n^2} \leq \frac{1}{n}").scale(0.6),165            Text("即", font="SimSun").scale(0.6),166            MathTex(r"a_n \leq b_n").scale(0.6)167        ).arrange(RIGHT, buff=0.3)168        comparison.next_to(axes, DOWN, buff=0.5)169        170        self.play(Write(comparison))171        self.wait(1)172 173        # 修改结论174        conclusion = VGroup(175            Text("由于:", font="SimSun").scale(0.6),176            MathTex(r"\sum_{n=1}^{\infty} \frac{1}{n}").scale(0.6),177            Text("发散,且", font="SimSun").scale(0.6),178            MathTex(r"0 \leq a_n \leq b_n").scale(0.6),179            Text("所以:", font="SimSun").scale(0.6),180            MathTex(r"\sum_{n=1}^{\infty} \frac{1}{n^2}").scale(0.6),181            Text("收敛", font="SimSun").scale(0.6)182        ).arrange(RIGHT, buff=0.3)183        conclusion.next_to(comparison, DOWN, buff=0.5)184 185def main():186    scene = SeriesComparisonTest()187    scene.render()188 189if __name__ == "__main__":190    main()

讲解

这个视频围绕「正项级数的比较判别法」展开。画面把问题、图像和公式放在同一条理解路径中,让抽象关系先被看见。

开头先建立问题背景和主要对象,让观察从标题、坐标或第一组关系进入。

画面中出现的文字「正项级数的比较判别法」给出视觉入口。随后画面通过对象创建、移动、淡入淡出和高亮,把抽象命题拆成可以跟随的步骤。

随后出现更具体的图像或公式提示,动画会把局部对象和整体结论联系起来。这里可以重点观察变量、曲线、区域或向量如何随镜头推进而变化。

核心公式可以写成:

n=11n2\sum_{n=1}^{\infty} \frac{1}{n^2}

这类公式可以和画面中的符号一一对应。

观察路径

观察路径可以分三步:先锁定「正项级数的比较判别法」中的核心对象,尤其留意比较判别法、正项级数、级数收敛之间的联系;再跟随画面中变量、图像或向量的变化;最后回到公式或结论,判断局部变化如何支撑整体关系。

本页可以从比较判别法、正项级数、级数收敛这些概念进入,继续沿相邻问题观察同一类数学结构。