数学分析基础可视化

柯西不等式可视化证明

围绕柯西不等式可视化证明,观察柯西不等式、向量几何、代数证明之间的关系与推理路径。

打开原视频

cauchy_inequality.py
1from manim import *2import numpy as np3 4class CauchyInequalityIntro(Scene):5    def construct(self):6        title = Text("柯西不等式的多种形式", font="SimHei")7        subtitle = Text("Cauchy-Schwarz Inequality", font="Arial").scale(0.8)8        9        title.to_edge(UP)10        subtitle.next_to(title, DOWN)11        12        self.play(Write(title))13        self.play(FadeIn(subtitle))14        self.wait(2)15        16        self.clear()17        self.introduce_cauchy()18    19    def introduce_cauchy(self):20        title = Text("柯西不等式是什么?", font="SimHei").to_edge(UP)21        self.play(Write(title))22        23        description = Text(24            "柯西不等式是数学中最重要的不等式之一,\n有多种等价形式,广泛应用于各个数学分支。", 25            font="SimHei"26        ).scale(0.7)27        description.next_to(title, DOWN, buff=1)28        29        self.play(Write(description))30        self.wait(2)31        32        forms = VGroup(33            Text("• 代数形式", font="SimHei"),34            Text("• 向量形式", font="SimHei"),35            Text("• 积分形式", font="SimHei"),36            Text("• 概率形式", font="SimHei")37        ).arrange(DOWN, aligned_edge=LEFT).scale(0.7)38        forms.next_to(description, DOWN, buff=0.5)39        40        for form in forms:41            self.play(Write(form), run_time=0.5)42        43        self.wait(2)44        self.clear()45 46 47class AlgebraicForm(Scene):48    def construct(self):49        title = Text("代数形式", font="SimHei").to_edge(UP)50        self.play(Write(title))51        52        # 基本形式的公式53        formula = MathTex(54            r"\left(\sum_{i=1}^{n} a_i b_i\right)^2 \leq \left(\sum_{i=1}^{n} a_i^2\right) \left(\sum_{i=1}^{n} b_i^2\right)"55        )56        self.play(Write(formula))57        self.wait(2)58        59        # 演示特例 n=260        self.play(formula.animate.to_edge(UP, buff=1.5))61        example = Text("特例:n=2的情况", font="SimHei").scale(0.7)62        example.next_to(formula, DOWN, buff=0.5)63        self.play(Write(example))64        65        simple_form = MathTex(66            r"(a_1 b_1 + a_2 b_2)^2 \leq (a_1^2 + a_2^2)(b_1^2 + b_2^2)"67        )68        simple_form.next_to(example, DOWN, buff=0.5)69        self.play(Write(simple_form))70        self.wait(2)71        72        # 展开证明思路73        expansion = Text("这可以通过展开左侧,并比较与右侧的差值来证明", font="SimHei").scale(0.7)74        expansion.next_to(simple_form, DOWN, buff=0.5)75        self.play(Write(expansion))76        77        expanded = MathTex(78            r"(a_1 b_1)^2 + 2(a_1 b_1)(a_2 b_2) + (a_2 b_2)^2"79        )80        expanded.next_to(expansion, DOWN, buff=0.5)81        self.play(Write(expanded))82        83        right_side = MathTex(84            r"(a_1^2 + a_2^2)(b_1^2 + b_2^2) = a_1^2 b_1^2 + a_1^2 b_2^2 + a_2^2 b_1^2 + a_2^2 b_2^2"85        )86        right_side.next_to(expanded, DOWN, buff=0.5)87        self.play(Write(right_side))88        89        difference = MathTex(90            r"\text{差值} = (a_1 b_2 - a_2 b_1)^2 \geq 0"91        )92        difference.next_to(right_side, DOWN, buff=0.5)93        self.play(Write(difference))94        self.wait(2)95        96        self.clear()97 98 99class VectorForm(Scene):100    def construct(self):101        title = Text("向量形式", font="SimHei").to_edge(UP)102        self.play(Write(title))103        104        formula = MathTex(r"|\vec{a} \cdot \vec{b}| \leq |\vec{a}||\vec{b}|")105        self.play(Write(formula))106        self.wait(2)107        108        # 几何解释109        self.play(formula.animate.to_edge(UP, buff=1.5))110        111        explanation = Text("几何解释:两个向量的点积等于它们长度的乘积乘以夹角的余弦", font="SimHei").scale(0.7)112        explanation.next_to(formula, DOWN, buff=0.5)113        self.play(Write(explanation))114        115        formula2 = MathTex(r"\vec{a} \cdot \vec{b} = |\vec{a}||\vec{b}|\cos\theta")116        formula2.next_to(explanation, DOWN, buff=0.5)117        self.play(Write(formula2))118        self.wait(1)119        120        implication = MathTex(r"|\cos\theta| \leq 1 \Rightarrow |\vec{a} \cdot \vec{b}| \leq |\vec{a}||\vec{b}|")121        implication.next_to(formula2, DOWN, buff=0.5)122        self.play(Write(implication))123        self.wait(1)124        125        # 几何可视化126        plane = NumberPlane(127            x_range=[-3, 3, 1],128            y_range=[-3, 3, 1],129            background_line_style={130                "stroke_opacity": 0.6131            }132        ).scale(0.8)133        plane.next_to(implication, DOWN, buff=0.5)134        self.play(Create(plane))135        136        vector_a = Vector([2, 1], color=BLUE)137        vector_b = Vector([1, 2], color=RED)138        139        vector_a_label = MathTex(r"\vec{a}", color=BLUE).next_to(vector_a.get_end(), RIGHT)140        vector_b_label = MathTex(r"\vec{b}", color=RED).next_to(vector_b.get_end(), RIGHT)141        142        self.play(GrowArrow(vector_a), Write(vector_a_label))143        self.play(GrowArrow(vector_b), Write(vector_b_label))144        145        self.wait(2)146        self.clear()147 148 149class IntegralForm(Scene):150    def construct(self):151        title = Text("积分形式", font="SimHei").to_edge(UP)152        self.play(Write(title))153        154        formula = MathTex(155            r"\left(\int_a^b f(x)g(x)dx\right)^2 \leq \int_a^b f^2(x)dx \int_a^b g^2(x)dx"156        )157        self.play(Write(formula))158        self.wait(2)159        160        explanation = Text("这是连续情况下的柯西不等式", font="SimHei").scale(0.7)161        explanation.next_to(formula, DOWN, buff=0.5)162        self.play(Write(explanation))163        164        continuous = Text(165            "可以理解为:函数在L²空间中的内积满足柯西-施瓦茨不等式", 166            font="SimHei"167        ).scale(0.7)168        continuous.next_to(explanation, DOWN, buff=0.5)169        self.play(Write(continuous))170        171        inner_product = MathTex(172            r"\langle f, g \rangle = \int_a^b f(x)g(x)dx"173        )174        inner_product.next_to(continuous, DOWN, buff=0.5)175        self.play(Write(inner_product))176        177        norm_def = MathTex(178            r"\|f\| = \sqrt{\int_a^b f^2(x)dx}"179        )180        norm_def.next_to(inner_product, DOWN, buff=0.5)181        self.play(Write(norm_def))182        183        cauchy = MathTex(184            r"|\langle f, g \rangle| \leq \|f\| \cdot \|g\|"185        )186        cauchy.next_to(norm_def, DOWN, buff=0.5)187        self.play(Write(cauchy))188        189        self.wait(2)190        self.clear()191 192 193class ProbabilisticForm(Scene):194    def construct(self):195        title = Text("概率形式", font="SimHei").to_edge(UP)196        self.play(Write(title))197        198        formula = MathTex(199            r"(E[XY])^2 \leq E[X^2] \cdot E[Y^2]"200        )201        self.play(Write(formula))202        self.wait(2)203        204        explanation = Text(205            "对随机变量X和Y,它们协方差的平方不超过各自方差的乘积", 206            font="SimHei"207        ).scale(0.7)208        explanation.next_to(formula, DOWN, buff=0.5)209        self.play(Write(explanation))210        211        covariance = MathTex(212            r"\text{Cov}(X, Y) = E[XY] - E[X]E[Y]"213        )214        covariance.next_to(explanation, DOWN, buff=0.5)215        self.play(Write(covariance))216        217        variance = MathTex(218            r"\text{Var}(X) = E[X^2] - (E[X])^2"219        )220        variance.next_to(covariance, DOWN, buff=0.5)221        self.play(Write(variance))222        223        correlation = MathTex(224            r"\rho_{X,Y} = \frac{\text{Cov}(X, Y)}{\sqrt{\text{Var}(X) \cdot \text{Var}(Y)}}"225        )226        correlation.next_to(variance, DOWN, buff=0.5)227        self.play(Write(correlation))228        229        bound = MathTex(230            r"|\rho_{X,Y}| \leq 1"231        )232        bound.next_to(correlation, DOWN, buff=0.5)233        self.play(Write(bound))234        235        self.wait(2)236        self.clear()237 238 239class ApplicationsScene(Scene):240    def construct(self):241        title = Text("柯西不等式的应用", font="SimHei").to_edge(UP)242        self.play(Write(title))243        244        applications = VGroup(245            Text("• 线性代数:最小二乘法", font="SimHei"),246            Text("• 分析学:Hölder不等式和Minkowski不等式", font="SimHei"),247            Text("• 几何学:三角形不等式", font="SimHei"),248            Text("• 优化理论:凸优化和拉格朗日乘子法", font="SimHei"),249            Text("• 信息论:信息处理不等式", font="SimHei"),250            Text("• 机器学习:核方法和支持向量机", font="SimHei")251        ).arrange(DOWN, aligned_edge=LEFT).scale(0.7)252        253        applications.next_to(title, DOWN, buff=0.5)254        255        for app in applications:256            self.play(Write(app), run_time=0.5)257        258        self.wait(2)259        260        conclusion = Text(261            "柯西不等式是连接多个数学分支的基础工具", 262            font="SimHei"263        ).scale(0.8)264        conclusion.next_to(applications, DOWN, buff=0.5)265        self.play(Write(conclusion))266        267        self.wait(2)268 269 270class CauchySummary(Scene):271    def construct(self):272        title = Text("柯西不等式总结", font="SimHei").to_edge(UP)273        self.play(Write(title))274        275        summary = VGroup(276            Text("• 代数形式:求和的平方 ≤ 平方的求和", font="SimHei"),277            Text("• 向量形式:点积 ≤ 长度的积", font="SimHei"),278            Text("• 积分形式:积分的平方 ≤ 平方的积分", font="SimHei"),279            Text("• 概率形式:期望的平方 ≤ 平方的期望", font="SimHei")280        ).arrange(DOWN, aligned_edge=LEFT).scale(0.7)281        282        summary.next_to(title, DOWN, buff=0.5)283        284        for point in summary:285            self.play(Write(point), run_time=0.7)286        287        self.wait(1)288        289        essence = Text(290            "本质:不同形式下内积空间中的柯西-施瓦茨不等式", 291            font="SimHei"292        ).scale(0.8)293        essence.next_to(summary, DOWN, buff=0.5)294        self.play(Write(essence))295        296        self.wait(2)297        298        thanks = Text("谢谢观看!", font="SimHei").scale(1.2)299        thanks.to_edge(DOWN, buff=1)300        self.play(Write(thanks))301        302        self.wait(2)303 304 305# 主场景用于展示所有内容306class CauchyInequalityAnimation(Scene):307    def construct(self):308        # 介绍309        intro = CauchyInequalityIntro()310        intro.construct()311        312        # 代数形式313        algebraic = AlgebraicForm()314        algebraic.construct()315        316        # 向量形式317        vector = VectorForm()318        vector.construct()319        320        # 积分形式321        integral = IntegralForm()322        integral.construct()323        324        # 概率形式325        probabilistic = ProbabilisticForm()326        probabilistic.construct()327        328        # 应用329        applications = ApplicationsScene()330        applications.construct()331        332        # 总结333        summary = CauchySummary()334        summary.construct()335 336 337class CauchyInequalityVisual(Scene):338    def construct(self):339        # 标题简短呈现340        title = Text("柯西不等式可视化证明", font="PingFang SC").scale(1.2)341        self.play(Write(title))342        self.wait(1)343        self.play(FadeOut(title))344        345        # 直接显示向量形式,不再显示代数形式346        vector = MathTex(347            r"|\vec{a} \cdot \vec{b}| \leq |\vec{a}||\vec{b}|"348        ).scale(0.9)349        350        self.play(Write(vector))351        self.wait(1)352        353        # 向量可视化部分354        self.play(vector.animate.to_edge(UP, buff=0.5))355        subtitle = Text("向量形式的几何证明", font="PingFang SC").scale(0.6)356        subtitle.next_to(vector, DOWN, buff=0.2)357        self.play(Write(subtitle))358        359        # 创建坐标平面 - 缩小一点360        plane = NumberPlane(361            x_range=[-3, 3, 1],362            y_range=[-2, 2, 1],363            background_line_style={"stroke_opacity": 0.4},364            axis_config={"include_numbers": False}365        ).scale(0.7)366        367        self.play(Create(plane))368        369        # 创建两个向量 - 调整向量b的初始位置以显示更合理的夹角370        vec_a = Vector([2, 0], color=BLUE)  # 沿x轴的向量371        vec_b = Vector([1.5, 1], color=RED)  # 45度左右的向量372        373        vec_a_label = MathTex(r"\vec{a}", color=BLUE).scale(0.7).next_to(vec_a.get_end(), RIGHT)374        vec_b_label = MathTex(r"\vec{b}", color=RED).scale(0.7).next_to(vec_b.get_end(), UP+RIGHT)375        376        self.play(GrowArrow(vec_a), Write(vec_a_label))377        self.play(GrowArrow(vec_b), Write(vec_b_label))378        379        # 点积的几何意义380        dot_product_def = MathTex(r"\vec{a} \cdot \vec{b} = |\vec{a}||\vec{b}|\cos\theta").scale(0.6)381        dot_product_def.to_corner(UL).shift(DOWN*1.5 + RIGHT*0.5)382        self.play(Write(dot_product_def))383        384        # 显示夹角385        angle = Angle(vec_a, vec_b, radius=0.5, color=GREEN)386        angle_label = MathTex(r"\theta", color=GREEN).scale(0.6).move_to(387            angle.point_from_proportion(0.5) + 0.3 * normalize(angle.point_from_proportion(0.5))388        )389        self.play(Create(angle), Write(angle_label))390        391        # 计算向量b在向量a上的投影392        dot_product = np.dot(vec_a.get_end()[:2], vec_b.get_end()[:2])393        a_squared = np.dot(vec_a.get_end()[:2], vec_a.get_end()[:2])394        projection_scalar = dot_product / a_squared395        projection_vector = projection_scalar * np.array([vec_a.get_end()[0], vec_a.get_end()[1], 0])396        397        # 绘制投影向量398        proj_vec = Vector(projection_vector, color=YELLOW)399        proj_vec_label = MathTex(r"\text{proj}_{\vec{a}}\vec{b}", color=YELLOW).scale(0.6)400        proj_vec_label.next_to(proj_vec.get_end(), DOWN)401        402        # 绘制从向量b到投影的虚线403        projection_line = DashedLine(404            vec_b.get_end(), 405            projection_vector,406            color=YELLOW, 407            dash_length=0.1408        )409        410        # 显示投影411        self.play(GrowArrow(proj_vec))412        self.play(Write(proj_vec_label), Create(projection_line))413        414        # 投影证明 - 更紧凑的布局415        proof_step1 = Text("几何证明", font="PingFang SC").scale(0.5)416        proof_step1.next_to(dot_product_def, DOWN, buff=0.3)417        self.play(Write(proof_step1))418        419        # 投影公式420        projection_formula = MathTex(421            r"\text{proj}_{\vec{a}}\vec{b} = \frac{\vec{a} \cdot \vec{b}}{|\vec{a}|^2}\vec{a}"422        ).scale(0.5)423        projection_formula.next_to(proof_step1, DOWN, buff=0.2)424        425        self.play(Write(projection_formula))426        427        # 柯西-施瓦茨不等式的核心428        projection_length = MathTex(429            r"|\text{proj}_{\vec{a}}\vec{b}| = \frac{|\vec{a} \cdot \vec{b}|}{|\vec{a}|} \leq |\vec{b}|"430        ).scale(0.5)431        projection_length.next_to(projection_formula, DOWN, buff=0.2)432        433        self.play(Write(projection_length))434        435        # 最终公式436        final_formula = MathTex(437            r"|\vec{a} \cdot \vec{b}| \leq |\vec{a}||\vec{b}|"438        ).scale(0.6)439        final_formula.next_to(projection_length, DOWN, buff=0.3)440        441        self.play(Write(final_formula))442        443        # 几何论证:向量a与b的夹角变化444        explanation = Text("平行时取等号,垂直时取最小值", font="PingFang SC").scale(0.5)445        explanation.next_to(final_formula, DOWN, buff=0.2).shift(RIGHT*0.5)  # 右移0.5单位446        self.play(Write(explanation))447        448        # 演示不同夹角下的情况 - 使用新的角度范围449        angles = [0, PI/3, PI/2, 2*PI/3]  # 0°, 60°, 90°, 120°450        angle_names = ["0°", "60°", "90°", "120°"]451        original_end_b = vec_b.get_end()452        453        for i, angle_val in enumerate(angles):454            if i > 0:  # 跳过第一个,因为已经画好了455                # 旋转向量b456                new_end = [2 * np.cos(angle_val), 2 * np.sin(angle_val), 0]  # 使用固定长度和指定角度457                new_vec_b = Vector(new_end, color=RED)458                new_angle = Angle(vec_a, new_vec_b, radius=0.5, color=GREEN)459                new_angle_label = MathTex(r"\theta = " + angle_names[i], color=GREEN).scale(0.5)460                new_angle_label.next_to(new_angle, RIGHT, buff=0.2)461                462                # 计算新的投影463                new_dot_product = np.dot(vec_a.get_end()[:2], new_end[:2])464                new_projection_scalar = new_dot_product / a_squared465                new_projection_vector = new_projection_scalar * np.array([vec_a.get_end()[0], vec_a.get_end()[1], 0])466                467                # 创建新的投影向量468                new_proj_vec = Vector(new_projection_vector, color=YELLOW)469                new_proj_vec_label = MathTex(r"\text{proj}_{\vec{a}}\vec{b}", color=YELLOW).scale(0.6)470                new_proj_vec_label.next_to(new_proj_vec.get_end(), DOWN)471                472                # 绘制新的从向量b到投影的虚线473                new_projection_line = DashedLine(474                    new_end, 475                    new_projection_vector,476                    color=YELLOW, 477                    dash_length=0.1478                )479                480                # 更新b向量、角度和投影481                self.play(482                    ReplacementTransform(vec_b, new_vec_b),483                    ReplacementTransform(angle, new_angle),484                    ReplacementTransform(angle_label, new_angle_label),485                    ReplacementTransform(proj_vec, new_proj_vec),486                    ReplacementTransform(proj_vec_label, new_proj_vec_label),487                    ReplacementTransform(projection_line, new_projection_line)488                )489                490                # 更新引用491                vec_b = new_vec_b492                angle = new_angle493                angle_label = new_angle_label494                proj_vec = new_proj_vec495                proj_vec_label = new_proj_vec_label496                projection_line = new_projection_line497                498                # 等待一小段时间让观众观察499                self.wait(0.8)500        501        self.wait(1)502        503        # 最终强调:投影长度不超过向量长度504        key_point = Text("几何本质:投影长度永远不超过原向量长度", font="PingFang SC").scale(0.6)505        key_point.to_edge(DOWN, buff=0.5)506        self.play(Write(key_point))507        self.wait(1.5)508        self.play(FadeOut(key_point))509        510        # 在几何证明结束后,清空所有内容511        self.play(512            *[FadeOut(mob) for mob in self.mobjects]513        )514        self.wait(0.5)515        516        # 直接开始代数证明部分517        title = Text("柯西不等式的代数证明", font="PingFang SC").scale(0.8).to_edge(UP, buff=0.3)518        self.play(Write(title))519        520        # 代数形式521        algebraic_form = MathTex(522            r"\left(\sum_{i=1}^{n} a_i b_i\right)^2 \leq \left(\sum_{i=1}^{n} a_i^2\right) \left(\sum_{i=1}^{n} b_i^2\right)"523        ).scale(0.7)524        algebraic_form.next_to(title, DOWN, buff=0.3)525        526        self.play(Write(algebraic_form))527        528        # 简化为n=2的特殊情况529        special_case = Text("以n=2的特殊情况为例", font="PingFang SC").scale(0.6)530        special_case.next_to(algebraic_form, DOWN, buff=0.3)531        self.play(Write(special_case))532        533        # n=2的代数形式534        simple_form = MathTex(535            r"(a_1 b_1 + a_2 b_2)^2 \leq (a_1^2 + a_2^2)(b_1^2 + b_2^2)"536        ).scale(0.7)537        simple_form.next_to(special_case, DOWN, buff=0.2)538        self.play(Write(simple_form))539        540        # 从向量形式理解代数形式541        connection_title = Text("从向量形式理解代数形式", font="PingFang SC").scale(0.6)542        connection_title.next_to(simple_form, DOWN, buff=0.4)543        self.play(Write(connection_title))544        545        # 左侧列:向量表示546        left_side = VGroup()547        548        vector_def = VGroup(549            MathTex(r"\vec{a} = (a_1, a_2)").scale(0.6),550            MathTex(r"\vec{b} = (b_1, b_2)").scale(0.6)551        ).arrange(DOWN, buff=0.2)552        left_side.add(vector_def)553        554        dot_product = MathTex(555            r"\vec{a} \cdot \vec{b} = a_1b_1 + a_2b_2"556        ).scale(0.6)557        left_side.add(dot_product)558        559        # 修改:分两行显示向量长度,而不是放在一个MathTex中560        vector_length_a = MathTex(r"|\vec{a}| = \sqrt{a_1^2 + a_2^2}").scale(0.6)561        vector_length_b = MathTex(r"|\vec{b}| = \sqrt{b_1^2 + b_2^2}").scale(0.6)562        vector_lengths = VGroup(vector_length_a, vector_length_b).arrange(DOWN, buff=0.1)563        left_side.add(vector_lengths)564        565        left_side.arrange(DOWN, aligned_edge=LEFT, buff=0.3)566        left_side.next_to(connection_title, DOWN, buff=0.3).to_edge(LEFT, buff=0.5)567        568        # 右侧列:转换过程569        right_side = VGroup()570        571        vector_ineq = MathTex(572            r"|\vec{a} \cdot \vec{b}| \leq |\vec{a}||\vec{b}|"573        ).scale(0.6)574        right_side.add(vector_ineq)575        576        substitution = MathTex(577            r"|a_1b_1 + a_2b_2| \leq \sqrt{a_1^2 + a_2^2} \cdot \sqrt{b_1^2 + b_2^2}"578        ).scale(0.6)579        right_side.add(substitution)580        581        squared = MathTex(582            r"(a_1b_1 + a_2b_2)^2 \leq (a_1^2 + a_2^2)(b_1^2 + b_2^2)"583        ).scale(0.6)584        right_side.add(squared)585        586        right_side.arrange(DOWN, aligned_edge=LEFT, buff=0.3)587        right_side.next_to(left_side, RIGHT, buff=0.8).align_to(left_side, UP)588        589        # 显示左侧列590        for item in left_side:591            self.play(Write(item), run_time=0.7)592        593        # 显示右侧列594        for item in right_side:595            self.play(Write(item), run_time=0.7)596        597        self.wait(1)598        599        # 修改说明框的大小,并将其放置在页面底部600        explanation = Text("这表明向量形式与代数形式是完全等价的", font="PingFang SC").scale(0.6)601        602        # 先创建文本,然后基于文本的尺寸设置框的大小603        explanation_box = Rectangle(604            height=explanation.height + 0.3,  # 添加少量边距605            width=explanation.width + 0.5,    # 添加少量边距606            color=YELLOW, 607            fill_opacity=0.1608        )609        610        # 将结论框放置在页面底部611        explanation_group = VGroup(explanation_box, explanation)612        explanation_box.move_to(explanation.get_center())613        explanation_group.to_edge(DOWN, buff=0.5)614        615        self.play(616            Create(explanation_box),617            Write(explanation)618        )619        620        self.wait(2)621        622        # 清场,过渡到总结623        self.play(*[FadeOut(mob) for mob in self.mobjects])624        self.wait(0.5)625        626        # 最终总结:不同形式本质相同627        final_title = Text("柯西不等式的不同形式", font="PingFang SC").scale(0.8).to_edge(UP, buff=0.3)628        self.play(Write(final_title))629        630        # 展示不同形式 - 改为两列布局631        forms_text = [632            "代数形式:",633            "向量形式:",634            "积分形式:",635            "概率形式:"636        ]637        638        forms_math = [639            r"\left(\sum_{i=1}^{n} a_i b_i\right)^2 \leq \left(\sum_{i=1}^{n} a_i^2\right) \left(\sum_{i=1}^{n} b_i^2\right)",640            r"|\vec{a} \cdot \vec{b}| \leq |\vec{a}||\vec{b}|",641            r"\left(\int_a^b f(x)g(x)dx\right)^2 \leq \int_a^b f^2(x)dx \int_a^b g^2(x)dx",642            r"(E[XY])^2 \leq E[X^2] \cdot E[Y^2]"643        ]644        645        equal_conditions_text = [646            "取等条件:",647            "取等条件:",648            "取等条件:",649            "取等条件:"650        ]651        652        equal_conditions_math = [653            r"a_i = \lambda b_i, \forall i \in \{1,2,...,n\}",654            r"\vec{a} \parallel \vec{b}",655            r"f(x) = \lambda g(x)",656            r"X = \lambda Y"657        ]658        659        # 创建左右两列660        left_forms = VGroup()661        right_forms = VGroup()662        663        # 每列包含两个形式664        for i in range(4):665            # 创建文本标题666            text = Text(forms_text[i], font="PingFang SC").scale(0.6)667            668            # 创建公式669            if i == 1:  # 向量形式(简单)670                formula = MathTex(forms_math[i]).scale(0.7)671            else:  # 其他形式672                formula = MathTex(forms_math[i]).scale(0.65)673            674            # 创建取等条件 - 分为中文文本和数学公式675            cond_text = Text(equal_conditions_text[i], font="PingFang SC").scale(0.5).set_color(GREEN)676            cond_math = MathTex(equal_conditions_math[i]).scale(0.5).set_color(GREEN)677            678            # 将文本和公式水平排列679            cond_group = VGroup(cond_text, cond_math).arrange(RIGHT, buff=0.1, aligned_edge=DOWN)680            681            # 垂直排列标题、公式和取等条件682            item_group = VGroup(683                text,684                formula,685                cond_group686            ).arrange(DOWN, buff=0.15, aligned_edge=LEFT)687            688            # 将形式分配到左右两列689            if i < 2:690                left_forms.add(item_group)691            else:692                right_forms.add(item_group)693        694        # 垂直排列每列中的内容695        left_forms.arrange(DOWN, buff=0.4, aligned_edge=LEFT)696        right_forms.arrange(DOWN, buff=0.4, aligned_edge=LEFT)697        698        # 水平排列两列699        both_columns = VGroup(left_forms, right_forms).arrange(RIGHT, buff=0.5, aligned_edge=UP)700        both_columns.next_to(final_title, DOWN, buff=0.4)701        702        # 显示所有形式703        self.play(Write(both_columns), run_time=2.0)704        705        # 修改最后的蓝色框706        essence_title = Text("本质:内积空间中的柯西-施瓦茨不等式", font="PingFang SC").scale(0.65)707        general_form = MathTex(708            r"|\langle u, v \rangle|^2 \leq \langle u, u \rangle \cdot \langle v, v \rangle"709        ).scale(0.7)710        711        # 分离中文和数学公式712        final_condition_text = Text("取等条件:", font="PingFang SC").scale(0.55).set_color(GREEN)713        final_condition_math = MathTex(714            r"u = \lambda v"715        ).scale(0.55).set_color(GREEN)716        final_condition_extra = Text("(线性相关)", font="PingFang SC").scale(0.55).set_color(GREEN)717        718        # 水平排列文本和公式719        final_condition_group = VGroup(720            final_condition_text, 721            final_condition_math, 722            final_condition_extra723        ).arrange(RIGHT, buff=0.1, aligned_edge=DOWN)724        725        # 垂直排列标题、一般形式和取等条件726        essence_group = VGroup(727            essence_title, 728            general_form, 729            final_condition_group730        ).arrange(DOWN, buff=0.2)731        732        # 根据内容自动调整框框大小733        essence_box = Rectangle(734            height=essence_group.height + 0.4,735            width=essence_group.width + 0.6,736            color=BLUE, 737            fill_opacity=0.1738        )739        740        # 创建组合并移动到页面底部741        essence_box_group = VGroup(essence_box, essence_group)742        essence_box.move_to(essence_group.get_center())743        essence_box_group.to_edge(DOWN, buff=0.3)744        745        self.play(746            Create(essence_box),747            Write(essence_group)748        )749        750        self.wait(3)

讲解

这个视频围绕「柯西不等式可视化证明」展开。画面把问题、图像和公式放在同一条理解路径中,让抽象关系先被看见。

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

画面中出现的文字「柯西不等式的多种形式」给出视觉入口。随后画面通过对象创建、移动、淡入淡出和高亮,把抽象命题拆成可以跟随的步骤。

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

核心公式可以写成:

abab|\vec{a} \cdot \vec{b}| \leq |\vec{a}||\vec{b}|

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

观察路径

观察路径可以分三步:先锁定「柯西不等式可视化证明」中的核心对象,尤其留意柯西不等式、向量几何、代数证明之间的联系;再跟随画面中变量、图像或向量的变化;最后回到公式或结论,判断局部变化如何支撑整体关系。

本页可以从柯西不等式、向量几何、代数证明这些概念进入,继续沿相邻问题观察同一类数学结构。