极限的性质【下】《用Manim可视化》

通过前面的极限的定义,现在是计算极限的时候了。然而,在此之前,我们需要一些极限的性质,这将使我们的工作变得简单一些。我们先来看看这些。

接下来的例子中f(x)=x^2-1

极限的性质:

6.幂函数的极限

\mathop {\lim }\limits_{x \to a} {\left[ {f\left( x \right)} \right]^n} = {\left[ {\mathop {\lim }\limits_{x \to a} f\left( x \right)} \right]^n},\,\,\,\,{\mbox{where }}n{\mbox{ is any real number}}

 在这个性质n中可以是任何实数(正数、负数、整数、分数、无理数、零等)。

例如,考虑的情况n=2。

对于任意整数n都可以这样做。

接下来我们实现一下该性质:

示例代码:

from manim import *  

class LimitPowerPropertyVisualization(Scene):  
    def construct(self):  
        # 创建坐标轴  
        axes = Axes(  
            x_range=[-1, 4, 1],  
            y_range=[-1, 40, 5],  
            axis_config={"color": BLUE},  
        )  

        # 定义函数 f(x)  
        def f(x):  
            return x**2 - 1  

        # 定义常量 a 和 n  
        a = 2  # 所考察的点  
        n = 3  # 实数 n  

        # 创建图形  
        f_graph = axes.plot(f, color=YELLOW, x_range=[-3, 3])  

        # 计算极限值  
        limit_f_a = f(a)  
        limit_power_a = limit_f_a ** n  

        # 创建幂函数的图形  
        power_graph = axes.plot(lambda x: f(x) ** n, color=GREEN, x_range=[-3, 3])  

        # 创建极限点  
        limit_dot_f = Dot(axes.c2p(a, limit_f_a), color=YELLOW)  
        limit_dot_power = Dot(axes.c2p(a, limit_power_a), color=GREEN)  

        # 创建极限值注释  
        limit_text_f = MathTex(r"\lim_{x \to a} f(x) = ", limit_f_a).next_to(limit_dot_f, RIGHT)  
        limit_text_power = MathTex(r"\lim_{x \to a} \left(f(x)\right)^n = ", limit_power_a).next_to(limit_dot_power, RIGHT)  

        # 添加所有元素  
        self.play(Create(axes), Create(f_graph))  
        self.play(Create(power_graph))  
        self.play(Create(limit_dot_f), Create(limit_dot_power))  
        self.play(Write(limit_text_f), Write(limit_text_power))  

        # 等待展示  
        self.wait(2)  

        # 高亮极限点  
        self.play(limit_dot_f.animate.set_color(ORANGE), limit_dot_power.animate.set_color(ORANGE))  
        self.wait(2)  

        # 淡出所有元素  
        self.play(FadeOut(axes), FadeOut(f_graph), FadeOut(power_graph),  
                  FadeOut(limit_dot_f), FadeOut(limit_dot_power),  
                  FadeOut(limit_text_f), FadeOut(limit_text_power))

代码解释:

  1. 导入库:使用Manim库进行动画生成。
  2. 创建类:定义类LimitPowerPropertyVisualization,继承自Scene,表示一个动画场景。
  3. 构建坐标轴:创建x和y的坐标轴,设置适当的范围。
  4. 定义函数:定义 f(x)=x2−1f(x)=x2−1。
  5. 定义常量:设置考察点 a=1a=1 和实数 n=3n=3。
  6. 绘制图形:绘制函数 f(x)f(x) 和其幂函数 f(x)nf(x)n。
  7. 计算极限值:在点 aa 处计算极限值,并计算其幂。
  8. 创建极限点:在图上标记出函数的极限值和幂函数的极限值。
  9. 添加注释:为极限值添加文本注释,显示各自的极限值。
  10. 动画效果:逐步展示所有图形、极限点和注释,以便观众理解极限的性质。
  11. 高亮显示:在等待一段时间后,将极限点高亮显示,最后淡出所有元素。

 7.函数,

\mathop {\lim }\limits_{x \to a} \left[ {\sqrt[n]{​{f\left( x \right)}}} \right] = \sqrt[n]{​{\mathop {\lim }\limits_{x \to a} f\left( x \right)}}

这只是上一个例子的一个特例

 

通过可视化我们得到下面的图像:

 示例代码:

from manim import *  

class LimitRootPropertyVisualization(Scene):  
    def construct(self):  
        # 创建坐标轴  
        axes = Axes(  
            x_range=[-1, 8, 1],  
            y_range=[-1, 8, 1],  
            axis_config={"color": BLUE},  
        )  

        # 定义函数 f(x)  
        def f(x):  
            return x**2 - 1  

        # 定义常量 a 和 n  
        a = 3  # 所考察的点  
        n = 3  # 实数 n  

        # 创建图形  
        f_graph = axes.plot(f, color=YELLOW, x_range=[1.02, 8])  

        # 计算极限值  
        limit_f_a = f(a)  
        limit_root_a = limit_f_a ** (1/n)  

        # 创建平方根函数的图形  
        root_graph = axes.plot(lambda x: f(x) ** (1/n), color=GREEN, x_range=[1.05,8])  

        # 创建极限点  
        limit_dot_f = Dot(axes.c2p(a, limit_f_a), color=YELLOW)  
        limit_dot_root = Dot(axes.c2p(a, limit_root_a), color=GREEN)  

        # 创建极限值注释  
        limit_text_f = MathTex(r"\lim_{x \to a} f(x) = ", limit_f_a).next_to(limit_dot_f, RIGHT)  
        limit_text_root = MathTex(r"\lim_{x \to a} \sqrt[n]{f(x)} = ", limit_root_a).next_to(limit_dot_root, RIGHT)  

        # 添加所有元素  
        self.play(Create(axes), Create(f_graph))  
        self.play(Create(root_graph))  
        self.play(Create(limit_dot_f), Create(limit_dot_root))  
        self.play(Write(limit_text_f), Write(limit_text_root))  

        # 等待展示  
        self.wait(2)  

        # 高亮极限点  
        self.play(limit_dot_f.animate.set_color(ORANGE), limit_dot_root.animate.set_color(ORANGE))  
        self.wait(2)  

        # 淡出所有元素  
        self.play(FadeOut(axes), FadeOut(f_graph), FadeOut(root_graph),  
                  FadeOut(limit_dot_f), FadeOut(limit_dot_root),  
                  FadeOut(limit_text_f), FadeOut(limit_text_root))

 

计算平方根时,可能对负数进行了指数运算,导致结果为无效(NaN)值。在我们的例子中,函数 f(x)=x2−1 在 x<−1 或 x>1 的情况下返回负值,因此在这些区间内计算平方根时会产生警告。

为了解决这个问题,可以在绘制平方根图形时,限制 x 的范围为能保证 f(x)为非负值的部分。对于函数 f(x):

  • 当 f(x)≥0 时,x 的范围为 [−1,1]。

7.常熟的极限

\mathop {\lim }\limits_{x \to a} c = c,\,\,\,\,c{\mbox{ is any real number}}换句话说,常数的极限就是常数本身。你们应该能够通过画的图形来说服自己f\left( x \right) = c

其中 cc是任意实数。我们将绘制常数函数 f(x)=c 的图形,并展示其极限。 

 示例代码:

from manim import *  

class LimitConstantVisualization(Scene):  
    def construct(self):  
        # 创建坐标轴  
        axes = Axes(  
            x_range=[-3, 3, 1],  
            y_range=[-1, 5, 1],  
            axis_config={"color": BLUE},  
        )  

        # 定义常数 c  
        c = 2  # 任意实数  

        # 创建常数函数图形  
        constant_graph = axes.plot(lambda x: c, color=YELLOW, x_range=[-3, 3])  

        # 定义考察点 a  
        a = 1  

        # 创建极限点  
        limit_dot = Dot(axes.c2p(a, c), color=YELLOW)  

        # 创建极限值注释  
        limit_text = MathTex(r"\lim_{x \to a} c = ", c).next_to(limit_dot, RIGHT)  

        # 添加所有元素  
        self.play(Create(axes), Create(constant_graph))  
        self.play(Create(limit_dot))  
        self.play(Write(limit_text))  

        # 等待展示  
        self.wait(2)  

        # 高亮极限点  
        self.play(limit_dot.animate.set_color(ORANGE))  
        self.wait(2)  

        # 淡出所有元素  
        self.play(FadeOut(axes), FadeOut(constant_graph), FadeOut(limit_dot), FadeOut(limit_text))

代码解释:

  1. 导入库:使用Manim库进行动画生成。
  2. 创建类:定义类LimitConstantVisualization,继承自Scene,表示一个动画场景。
  3. 构建坐标轴:创建x和y的坐标轴,设置适当的范围。
  4. 定义常数:设置常数 c=2c=2(可以根据需要更改)。
  5. 绘制常数函数图形:绘制常数函数 f(x)=cf(x)=c 的图形。
  6. 定义考察点:设置考察点 a=1a=1。
  7. 创建极限点:在图上标记出常数函数的极限值。
  8. 添加注释:为极限值添加文本注释,显示极限的结果。
  9. 动画效果:逐步展示所有图形、极限点和注释,以便观众理解极限的性质。
  10. 高亮显示:在等待一段时间后,将极限点高亮显示,最后淡出所有元素。

8.直线函数的极限

.\mathop {\lim }\limits_{x \to a} x = a

 和上一题一样,你应该能够通过画f的图像来说服自己f(x)= x

示例代码:

from manim import *  

class LimitIdentityVisualization(Scene):  
    def construct(self):  
        # 创建坐标轴  
        axes = Axes(  
            x_range=[-3, 3, 1],  
            y_range=[-3, 3, 1],  
            axis_config={"color": BLUE},  
        )  

        # 定义考察点 a  
        a = 1  # 可以根据需要更改  

        # 创建线性函数图形 f(x) = x  
        linear_graph = axes.plot(lambda x: x, color=YELLOW, x_range=[-3, 3])  

        # 创建极限点  
        limit_dot = Dot(axes.c2p(a, a), color=YELLOW)  

        # 创建极限值注释  
        limit_text = MathTex(r"\lim_{x \to a} x = ", a).next_to(limit_dot, RIGHT)  

        # 添加所有元素  
        self.play(Create(axes), Create(linear_graph))  
        self.play(Create(limit_dot))  
        self.play(Write(limit_text))  

        # 等待展示  
        self.wait(2)  

        # 高亮极限点  
        self.play(limit_dot.animate.set_color(ORANGE))  
        self.wait(2)  

        # 淡出所有元素  
        self.play(FadeOut(axes), FadeOut(linear_graph), FadeOut(limit_dot), FadeOut(limit_text))

9.幂函数的极限

\mathop {\lim }\limits_{x \to a} {x^n} = {a^n} 

 

 这是在函数趋近于2是的图像。

 示例代码:

from manim import *  

class LimitPowerFunctionVisualization(Scene):  
    def construct(self):  
        # 创建坐标轴  
        axes = Axes(  
            x_range=[-3, 3, 1],  
            y_range=[-3, 9, 1],  
            axis_config={"color": BLUE},  
        )  

        # 定义考察点 a 和指数 n  
        a = 2  # 可以根据需要更改  
        n = 2  # 可以根据需要更改  

        # 创建幂函数图形 f(x) = x^n  
        power_graph = axes.plot(lambda x: x**n, color=YELLOW, x_range=[-3, 3])  

        # 创建极限点  
        limit_dot = Dot(axes.c2p(a, a**n), color=YELLOW)  

        # 创建极限值注释  
        limit_text = MathTex(r"\lim_{x \to a} x^n = ", a**n).next_to(limit_dot, RIGHT)  

        # 添加所有元素  
        self.play(Create(axes), Create(power_graph))  
        self.play(Create(limit_dot))  
        self.play(Write(limit_text))  

        # 等待展示  
        self.wait(2)  

        # 高亮极限点  
        self.play(limit_dot.animate.set_color(ORANGE))  
        self.wait(2)  

        # 淡出所有元素  
        self.play(FadeOut(axes), FadeOut(power_graph), FadeOut(limit_dot), FadeOut(limit_text))

代码解释:

  1. 导入库:使用Manim库进行动画生成。
  2. 创建类:定义类LimitPowerFunctionVisualization,继承自Scene,表示一个动画场景。
  3. 构建坐标轴:创建x和y的坐标轴,设置适当的范围。
  4. 定义考察点:设置考察点 a=2和指数 n=2(可以根据需要更改)。
  5. 绘制幂函数图形:绘制函数 f(x)=x^n 的图形。
  6. 创建极限点:在图上标记出函数的极限值。
  7. 添加注释:为极限值添加文本注释,显示极限的结果。
  8. 动画效果:逐步展示所有图形、极限点和注释,以便观众理解极限的性质。
  9. 高亮显示:在等待一段时间后,将极限点高亮显示,最后淡出所有元素。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Yasen.M

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值