summaryrefslogtreecommitdiff
path: root/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Function-and-Polynomial-Spaces/Integral_Properties.py
blob: 97c0e094fb41bae752148c34b1306bd0ed4379f3 (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
from manimlib.imports import *
from scipy import sin 
class Integral_Properties(GraphScene):
    CONFIG = {
        "x_min" : 0,
        "x_max" : 5,
        "y_min" : 0,
        "y_max" : 6,
        "y_tick_frequency" : 1, 
        "x_tick_frequency" : 1, 
        "axes_color":LIGHT_GRAY,
        "x_labeled_nums" : list(range(6)),
        "y_labeled_nums" : list(range(6))
    }   
    def construct(self):
        self.setup_axes(animate=False)
        curve1 = self.get_graph(lambda x : sin(x), x_min=0,x_max=2.5,color=RED)
        curve2 = self.get_graph(lambda x : x, x_min=0,x_max=2.5,color=DARK_BLUE)
        curve3 = self.get_graph(lambda x : sin(x) + x, x_min=0,x_max=2.5,color=GREEN)
        fx = TextMobject(r"$f(x)$").scale(0.5).shift(1*RIGHT+1.8*DOWN)
        gx = TextMobject(r"$g(x)$").scale(0.5).shift(1*RIGHT)
        sum = TextMobject(r"$f(x) + g(x)$").scale(0.5).shift(1.3*RIGHT+0.6*UP)
        area1 = self.get_area(curve1,0,2.5)
        area2 = self.get_area(curve2,0,2.5)
        area3 = self.get_area(curve3,0,2.5)        
        area2.set_fill(color=PURPLE)
        area3.set_fill(color=ORANGE)
        text1=TextMobject(r"$\int_{0}^{2.5}$ f(x) dx = Area under the curve f(x)",color=BLUE_C).scale(0.7).shift(2.7*RIGHT+3*UP)
        text2=TextMobject(r"$\int_{0}^{2.5}$ g(x) dx = Area under the curve g(x)",color=PURPLE_B).scale(0.7).shift(2.7*RIGHT+2.4*UP)
        text3=TextMobject(r"Area under the curve f(x) + g(x) = $\int_{0}^{2.5} (f(x) + g(x)) dx$",color=ORANGE).scale(0.7).shift(2.7*RIGHT+1.8*UP)
        text4=TextMobject(r"\text{$\int_{0}^{2.5}$ (f(x) + g(x)) dx}",r"\text{ = }",r"\text{ $\int_{0}^{2.5}$ f(x) dx }",r"\text{+}",r"\text{$\int_{0}^{2.5}$ g(x) dx}").scale(0.62).shift(2.7*RIGHT+2.7*UP)
        text4[0].set_color(ORANGE)
        text4[2].set_color(BLUE_C)
        text4[4].set_color(PURPLE_B)
        self.play(ShowCreation(curve1), ShowCreation(fx))
        self.wait(1.2)
        self.play(ShowCreation(curve2),ShowCreation(gx))
        self.wait(1.2)
        self.play(ShowCreation(area1))
        self.play(ShowCreation(text1))
        self.wait(1.5)
        self.play(ShowCreation(area2))
        self.play(ShowCreation(text2))
        self.wait(1.5)
        self.play(ShowCreation(curve3),ShowCreation(sum))
        self.play(ShowCreation(area3))
        self.play(ShowCreation(text3))
        self.wait(2)
        self.play(FadeOut(text1),FadeOut(text2),FadeOut(text3))
        self.wait(1)
        self.play(ShowCreation(text4))
        self.wait(3)
        self.play(FadeOut(curve1),FadeOut(curve2),FadeOut(area1),FadeOut(area2))
        self.wait(1.5)
        self.play(FadeOut(text4),FadeOut(area2),FadeOut(curve2),FadeOut(gx),FadeOut(curve3),FadeOut(sum),FadeOut(area3),ShowCreation(curve1),ShowCreation(fx))
        self.wait(1.5)
        self.play(ShowCreation(area1),ShowCreation(text1))
        self.wait(1.5)
        curve4 = self.get_graph(lambda x : 2*sin(x), x_min=0,x_max=2.5,color=RED)
        area4 = self.get_area(curve4,0,2.5)
        area4.set_fill(color=YELLOW)
        fx2 = TextMobject(r"$2f(x)$").scale(0.7).shift(1*RIGHT+1.2*DOWN)
        scalar_mul=TextMobject(r"$\int_{0}^{2.5} ( 2f(x) ) dx$ = 2 $\times$ Area under the curve f(x)",color=YELLOW).scale(0.7).shift(2.7*RIGHT+2.4*UP)
        self.play(ShowCreation(curve4),ShowCreation(fx2))
        self.wait(1)
        self.play(ShowCreation(area4))
        self.wait(2)
        self.play(ShowCreation(scalar_mul))
        self.wait(2)
        text5=TextMobject(r"\text{$\int_{0}^{2.5}$ (2 f(x)) dx}",r"\text{ = }",r"\text{2 $\int_{0}^{2.5}$ f(x) dx }").scale(0.67).shift(2.7*RIGHT+2.7*UP)
        text5[0].set_color(YELLOW)
        text5[2].set_color(BLUE_C)
        self.play(FadeOut(text1),FadeOut(scalar_mul))
        self.wait(1)
        self.play(ShowCreation(text5))
        self.wait(3)