summaryrefslogtreecommitdiff
path: root/FSF-2020/calculus/series-and-transformations/Power Series/video2_convergence_Intuition.py
blob: 72356c6848cddc9d8aec9ac9e69e96507c990743 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from manimlib.imports import *
import numpy as np


class convergence(Scene):
    def construct(self):
        originalFormula=TextMobject("$\sum _{ n=0 }^{ \infty  }{ { a }_{ n }{ x }^{ n } }$")
        originalFormula.set_color(RED)
        self.play(Write(originalFormula))
        self.wait(1)
        self.play(ApplyMethod(originalFormula.shift,2.7*UP))
        self.wait(1)

        terms=["$a_{ 0 }$","$a_{ 1 }x$","$a_{ 2 }x^{ 2 }$","$a_{ 3 }x^{ 3 }$","$a_{ 4 }x^{ 4 }$","$a_{ 5 }x^{ 5 }$","$a_{ 6 }x^{ 6 }$","$a_{ 7 }x^{ 7 }$","$a_{ 8 }x^{ 8 }$","$a_{ 9 }x^{ 9 }$","$a_{ 10 }x^{ 10 }$","$a_{ 11 }x^{ 11 }$"]
        termsTogetherString="+".join(terms)
        termsTogether=TextMobject(termsTogetherString+"...")
        termsTogether.scale(0.8)
        termsTogether.shift(2.7*UP)
        self.play(ReplacementTransform(originalFormula,termsTogether))
        self.wait(1)

        termMobjectRect=[0]*12
        termMobject=TextMobject(terms[0])
        termMobject.shift(2.7*UP+6.2*LEFT)
        for i in range(1,13):
            termMobjectOld=termMobject
            termMobjectOld.scale(0.8)
            if(i<12):
                termMobject=TextMobject(terms[i])
                termMobject.next_to(termMobjectOld)
            if(i==1):
                rectDefine=TextMobject("Here","each rectangle","represents the","value of the term")
                rectDefine.set_color_by_tex_to_color_map({"each rectangle":BLUE,"value of the term":YELLOW})
                rectDefine.scale(0.7)
                rectDefine.shift(3.2*DOWN)
                self.play(Write(rectDefine))
                self.wait(1)
            if(i==2):
                ratio=TextMobject("If $\\frac { a_{ n+1 } }{ { a }_{ n } } < 1$")
                ratio.set_color(RED)
                ratio.scale(0.7)
                ratio.move_to(3.2*DOWN)
                inequality=TextMobject("$a_{ n+1 } < a_{ n }$")
                inequality.set_color(RED)
                inequality.scale(0.7)
                inequality.move_to(3.2*DOWN)
                self.play(FadeOut(rectDefine))
                self.play(Write(ratio))
                self.wait(1)
                self.play(ReplacementTransform(ratio,inequality))
                self.wait(1)
            #self.play(ApplyMethod(termMobjectOld.move_to,(2-0.3*i)*DOWN+RIGHT*0.2*i))
            termMobjectRect[i-1]=Rectangle(height=0.1,width=(5-0.4*i))
            termMobjectRect[i-1].move_to((2-0.2*i)*DOWN+RIGHT*0.2*i)
            #rectangles[p] = termMobjectRect
            #p+=1
            self.play(ReplacementTransform(termMobjectOld,termMobjectRect[i-1]))

        uparrow=TextMobject("$\\uparrow$")
        uparrow.set_color(GREEN)
        uparrow.scale(6)
        uparrow.shift(4*RIGHT+0.5*DOWN)
        self.play(ShowCreation(uparrow))
        self.wait(1)

        converges=TextMobject("Converges!")
        converges.set_color(RED)
        converges.scale(0.6)
        converges.next_to(uparrow)
        self.play(FadeIn(converges))
        self.wait(2)

        self.play(FadeOut(converges),FadeOut(uparrow),FadeOut(inequality))
        self.wait(0.5)
        rect=VGroup(termMobjectRect[0],termMobjectRect[1],termMobjectRect[2],termMobjectRect[3],termMobjectRect[4],termMobjectRect[5],termMobjectRect[6],termMobjectRect[7],termMobjectRect[8],termMobjectRect[9],termMobjectRect[10],termMobjectRect[11])    
        self.play(ApplyMethod(rect.scale,0.2))
        for i in range(0,12):
            self.play(ApplyMethod(termMobjectRect[i].shift,i*0.04*DOWN+(11-(3-0.11*i)*i)*LEFT*0.3))
        func=TextMobject("$\\approx$","$f(x)$")
        func.set_color_by_tex_to_color_map({"$f(x)$":RED})
        func.scale(0.8)
        func.shift(DOWN+4.5*RIGHT+0.1*UP)
        self.play(FadeIn(func))

        rightarrow=TextMobject("$\\rightarrow$")
        rightarrow.set_color(GREEN)
        rightarrow.scale(4)
        rightarrow.shift(2*DOWN)
        converges=TextMobject("Hence even the","sum converges!")
        converges.set_color_by_tex_to_color_map({"sum converges!":RED})
        converges.move_to(3*DOWN)
        converges.scale(0.7)
        self.play(Write(rightarrow),FadeIn(converges))
        self.wait(2)