Exemple #1
0
    def describe_scalars(self, v, plane):
        axes = plane.get_axes()
        long_v = Vector(2*v.get_end())
        long_minus_v = Vector(-2*v.get_end())
        original_v = v.copy()
        scaling_word = TextMobject("``Scaling''").to_corner(UP+LEFT)
        scaling_word.shift(2*RIGHT)
        scalars = VMobject(*map(TexMobject, [
            "2,", "\\dfrac{1}{3},", "-1.8,", "\\dots"
        ]))
        scalars.arrange_submobjects(RIGHT, buff = 0.4)
        scalars.next_to(scaling_word, DOWN, aligned_edge = LEFT)
        scalars_word = TextMobject("``Scalars''")
        scalars_word.next_to(scalars, DOWN, aligned_edge = LEFT)

        self.remove(plane)
        self.add(axes)
        self.play(
            Write(scaling_word),
            Transform(v, long_v),
            run_time = 1.5
        )
        self.play(Transform(v, long_minus_v, run_time = 3))
        self.play(Write(scalars))
        self.wait()
        self.play(Write(scalars_word))
        self.play(Transform(v, original_v), run_time = 3)
        self.wait(2)
Exemple #2
0
    def construct(self):
        matrix = Matrix([
            [2, 0],
            [-1, 1],
            [-2, 1],
        ])
        matrix.highlight_columns(X_COLOR, Y_COLOR)

        brace = Brace(matrix)
        words = VMobject(
            TextMobject("Span", "of columns"),
            TexMobject("\\Updownarrow"),
            TextMobject("``Column space''")
        )
        words.arrange_submobjects(DOWN, buff = 0.1)
        words.next_to(brace, DOWN)
        words[0][0].highlight(PINK)
        words[2].highlight(TEAL)
        words[0].add_background_rectangle()
        words[2].add_background_rectangle()
        VMobject(matrix, brace, words).center()

        self.add(matrix)
        self.play(
            GrowFromCenter(brace),
            Write(words, run_time = 2)
        )
        self.wait()
Exemple #3
0
    def add_scaling(self, arrows, syms, arrays):
        s_arrows = VMobject(
            TexMobject("2"), Vector([1, 1]).highlight(YELLOW), 
            TexMobject("="), Vector([2, 2]).highlight(WHITE)
        )
        s_arrows.arrange_submobjects(RIGHT)
        s_arrows.scale(0.75)
        s_arrows.next_to(arrows, DOWN)

        s_arrays = VMobject(
            TexMobject("2"), 
            matrix_to_mobject([3, -5]).highlight(YELLOW),
            TextMobject("="),
            matrix_to_mobject(["2(3)", "2(-5)"])
        )
        s_arrays.arrange_submobjects(RIGHT)
        s_arrays.scale(0.75)
        s_arrays.next_to(arrays, DOWN)

        s_syms = TexMobject(["2", "\\vec{\\textbf{v}}"])
        s_syms.split()[-1].highlight(YELLOW)
        s_syms.next_to(syms, DOWN)

        self.play(
            Write(s_arrows), Write(s_arrays), Write(s_syms),
            run_time = 2
        )
        self.wait()
Exemple #4
0
    def add_scaling(self, arrows, syms, arrays):
        s_arrows = VMobject(
            TexMobject("2"), Vector([1, 1]).highlight(YELLOW), 
            TexMobject("="), Vector([2, 2]).highlight(WHITE)
        )
        s_arrows.arrange_submobjects(RIGHT)
        s_arrows.scale(0.75)
        s_arrows.next_to(arrows, DOWN)

        s_arrays = VMobject(
            TexMobject("2"), 
            matrix_to_mobject([3, -5]).highlight(YELLOW),
            TextMobject("="),
            matrix_to_mobject(["2(3)", "2(-5)"])
        )
        s_arrays.arrange_submobjects(RIGHT)
        s_arrays.scale(0.5)
        s_arrays.next_to(arrays, DOWN)

        s_syms = TexMobject(["2", "\\vec{\\textbf{v}}"])
        s_syms.split()[-1].highlight(YELLOW)
        s_syms.next_to(syms, DOWN)

        self.play(
            Write(s_arrows), Write(s_arrays), Write(s_syms),
            run_time = 2
        )
        self.dither()
Exemple #5
0
    def show_dependencies(self):
        linalg = TextMobject("Linear Algebra")
        subjects = map(TextMobject, [
            "Computer science",
            "Physics",
            "Electrical engineering",
            "Mechanical engineering",
            "Statistics",
            "\\vdots"
        ])
        prev = subjects[0]
        for subject in subjects[1:]:
            subject.next_to(prev, DOWN, aligned_edge = LEFT)
            prev = subject
        all_subs = VMobject(*subjects)
        linalg.to_edge(LEFT)
        all_subs.next_to(linalg, RIGHT, buff = 2)
        arrows = VMobject(*[
            Arrow(linalg, sub)
            for sub in subjects
        ])

        self.play(Write(linalg, run_time = 1))
        self.dither()
        self.play(
            ShowCreation(arrows, submobject_mode = "lagged_start"),
            FadeIn(all_subs),
            run_time = 2
        )
        self.dither()
        self.linalg = linalg
Exemple #6
0
    def describe_scalars(self, v, plane):
        axes = plane.get_axes()
        long_v = Vector(2*v.get_end())
        long_minus_v = Vector(-2*v.get_end())
        original_v = v.copy()
        scaling_word = TextMobject("``Scaling''").to_corner(UP+LEFT)
        scaling_word.shift(2*RIGHT)
        scalars = VMobject(*map(TexMobject, [
            "2,", "\\dfrac{1}{3},", "-1.8,", "\\dots"
        ]))
        scalars.arrange_submobjects(RIGHT, buff = 0.4)
        scalars.next_to(scaling_word, DOWN, aligned_edge = LEFT)
        scalars_word = TextMobject("``Scalars''")
        scalars_word.next_to(scalars, DOWN, aligned_edge = LEFT)

        self.remove(plane)
        self.add(axes)
        self.play(
            Write(scaling_word),
            Transform(v, long_v),
            run_time = 1.5
        )
        self.play(Transform(v, long_minus_v, run_time = 3))
        self.play(Write(scalars))
        self.dither()
        self.play(Write(scalars_word))
        self.play(Transform(v, original_v), run_time = 3)
        self.dither(2)
Exemple #7
0
    def construct(self):
        matrix = Matrix([
            [2, 0],
            [-1, 1],
            [-2, 1],
        ])
        matrix.highlight_columns(X_COLOR, Y_COLOR)

        brace = Brace(matrix)
        words = VMobject(
            TextMobject("Span", "of columns"),
            TexMobject("\\Updownarrow"),
            TextMobject("``Column space''")
        )
        words.arrange_submobjects(DOWN, buff = 0.1)
        words.next_to(brace, DOWN)
        words[0][0].highlight(PINK)
        words[2].highlight(TEAL)
        words[0].add_background_rectangle()
        words[2].add_background_rectangle()
        VMobject(matrix, brace, words).center()

        self.add(matrix)
        self.play(
            GrowFromCenter(brace),
            Write(words, run_time = 2)
        )
        self.dither()
Exemple #8
0
    def construct(self):
        title = TextMobject("Essence of Linear Algebra")
        title.highlight(BLUE)
        title.to_corner(UP+LEFT)
        h_line = Line(SPACE_WIDTH*LEFT, SPACE_WIDTH*RIGHT)
        h_line.next_to(title, DOWN)
        h_line.to_edge(LEFT, buff = 0)
        chapters = VMobject(*map(TextMobject, [
            "Chapter 1: Vectors, what even are they?",
            "Chapter 2: Linear combinations, span and bases",
            "Chapter 3: Matrices as linear transformations",
            "Chapter 4: Matrix multiplication as composition",
            "Chapter 5: The determinant",
            "Chapter 6: Inverse matrices, column space and null space",
            "Chapter 7: Dot products and cross products",
            "Chapter 8: Change of basis",
            "Chapter 9: Eigenvectors and eigenvalues",
            "Chapter 10: Abstract vector spaces",
        ]))
        chapters.arrange_submobjects(DOWN)
        chapters.scale(0.7)
        chapters.next_to(h_line, DOWN)

        self.play(
            Write(title),
            ShowCreation(h_line)
        )
        for chapter in chapters.split():
            chapter.to_edge(LEFT, buff = 1)
            self.play(FadeIn(chapter))
        self.dither(2)

        entry3 = chapters.split()[2]
        added_words = TextMobject("(Personally, I'm most excited \\\\ to do this one)")
        added_words.scale(0.5)
        added_words.highlight(YELLOW)
        added_words.next_to(h_line, DOWN)
        added_words.to_edge(RIGHT)
        arrow = Arrow(added_words.get_bottom(), entry3)

        self.play(
            ApplyMethod(entry3.highlight, YELLOW),
            ShowCreation(arrow, submobject_mode = "one_at_a_time"),
            Write(added_words),
            run_time = 1
        )
        self.dither()
        removeable = VMobject(added_words, arrow, h_line, title)
        self.play(FadeOut(removeable))
        self.remove(removeable)

        self.series_of_videos(chapters)
Exemple #9
0
    def show_formula(self):
        matrix = self.get_matrix()
        det_text = get_det_text(matrix)
        f_str = "=(a+b)(c+d)-ac-bd-2bc=ad-bc"
        formula = TexMobject(f_str)

        formula.next_to(det_text, RIGHT)
        everyone = VMobject(det_text, matrix, formula)
        everyone.scale_to_fit_width(2 * SPACE_WIDTH - 1)
        everyone.next_to(DOWN, DOWN)
        background_rect = BackgroundRectangle(everyone)
        self.play(ShowCreation(background_rect), Write(everyone))
        self.wait()
Exemple #10
0
    def construct(self):
        title = TextMobject("Essence of Linear Algebra")
        title.highlight(BLUE)
        title.to_corner(UP + LEFT)
        h_line = Line(SPACE_WIDTH * LEFT, SPACE_WIDTH * RIGHT)
        h_line.next_to(title, DOWN)
        h_line.to_edge(LEFT, buff=0)
        chapters = VMobject(*map(TextMobject, [
            "Chapter 1: Vectors, what even are they?",
            "Chapter 2: Linear combinations, span and bases",
            "Chapter 3: Matrices as linear transformations",
            "Chapter 4: Matrix multiplication as composition",
            "Chapter 5: The determinant",
            "Chapter 6: Inverse matrices, column space and null space",
            "Chapter 7: Dot products and cross products",
            "Chapter 8: Change of basis",
            "Chapter 9: Eigenvectors and eigenvalues",
            "Chapter 10: Abstract vector spaces",
        ]))
        chapters.arrange_submobjects(DOWN)
        chapters.scale(0.7)
        chapters.next_to(h_line, DOWN)

        self.play(Write(title), ShowCreation(h_line))
        for chapter in chapters.split():
            chapter.to_edge(LEFT, buff=1)
            self.play(FadeIn(chapter))
        self.wait(2)

        entry3 = chapters.split()[2]
        added_words = TextMobject(
            "(Personally, I'm most excited \\\\ to do this one)")
        added_words.scale(0.5)
        added_words.highlight(YELLOW)
        added_words.next_to(h_line, DOWN)
        added_words.to_edge(RIGHT)
        arrow = Arrow(added_words.get_bottom(), entry3)

        self.play(ApplyMethod(entry3.highlight, YELLOW),
                  ShowCreation(arrow, submobject_mode="one_at_a_time"),
                  Write(added_words),
                  run_time=1)
        self.wait()
        removeable = VMobject(added_words, arrow, h_line, title)
        self.play(FadeOut(removeable))
        self.remove(removeable)

        self.series_of_videos(chapters)
Exemple #11
0
    def show_formula(self):
        matrix = self.get_matrix()
        det_text = get_det_text(matrix)
        f_str = "=(a+b)(c+d)-ac-bd-2bc=ad-bc"
        formula = TexMobject(f_str)

        formula.next_to(det_text, RIGHT)
        everyone = VMobject(det_text, matrix, formula)
        everyone.scale_to_fit_width(2*SPACE_WIDTH - 1)
        everyone.next_to(DOWN, DOWN)
        background_rect = BackgroundRectangle(everyone)
        self.play(
            ShowCreation(background_rect),
            Write(everyone)
        )
        self.dither()
Exemple #12
0
    def construct(self):
        self.setup()
        matrix = Matrix(np.array(self.transposed_matrix).transpose())
        matrix.highlight_columns(X_COLOR, Y_COLOR)
        matrix.next_to(ORIGIN, LEFT).to_edge(UP)
        matrix_background = BackgroundRectangle(matrix)
        self.play(ShowCreation(matrix_background), Write(matrix))
        if self.show_square:
            self.add_unit_square(animate = True)
        self.add_foreground_mobject(matrix_background, matrix)
        self.dither()
        self.apply_transposed_matrix([self.transposed_matrix[0], [0, 1]])
        self.apply_transposed_matrix([[1, 0], self.transposed_matrix[1]])
        self.dither()
        if self.show_square:


            bottom_brace = Brace(self.i_hat, DOWN)
            right_brace = Brace(self.square, RIGHT)
            width = TexMobject(str(self.transposed_matrix[0][0]))
            height = TexMobject(str(self.transposed_matrix[1][1]))
            width.next_to(bottom_brace, DOWN)
            height.next_to(right_brace, RIGHT)
            for mob in bottom_brace, width, right_brace, height:
                mob.add_background_rectangle()
                self.play(Write(mob, run_time = 0.5))
            self.dither()

            width_target, height_target = width.copy(), height.copy()
            det = np.linalg.det(self.transposed_matrix)
            times, eq_det = map(TexMobject, ["\\times", "=%d"%det])
            words = TextMobject("New area $=$")
            equation = VMobject(
                words, width_target, times, height_target, eq_det
            )
            equation.arrange_submobjects(RIGHT, buff = 0.2)
            equation.next_to(self.square, UP, aligned_edge = LEFT)
            equation.shift(0.5*RIGHT)
            background_rect = BackgroundRectangle(equation)

            self.play(
                ShowCreation(background_rect),                
                Transform(width.copy(), width_target),
                Transform(height.copy(), height_target),
                *map(Write, [words, times, eq_det])
            )
            self.dither()
Exemple #13
0
    def construct(self):
        morty = Mortimer()
        morty.scale(0.8)
        morty.to_corner(DOWN+RIGHT)
        morty.shift(0.5*LEFT)
        title = TextMobject("Associativity:")
        title.to_corner(UP+LEFT)

        lhs = TexMobject(list("(AB)C"))
        lp, a, b, rp, c = lhs.split()
        rhs = VMobject(*[m.copy() for m in a, lp, b, c, rp])
        point = VectorizedPoint()
        start = VMobject(*[m.copy() for m in point, a, b, point, c])
        for mob in lhs, rhs, start:
            mob.arrange_submobjects(buff = 0.1)
        a, lp, b, c, rp = rhs.split()
        rhs = VMobject(lp, a, b, rp, c)##Align order to lhs
        eq = TexMobject("=")
        q_marks = TextMobject("???")
        q_marks.submobject_gradient_highlight(TEAL_B, TEAL_D)
        q_marks.next_to(eq, UP)
        lhs.next_to(eq, LEFT)
        rhs.next_to(eq, RIGHT)
        start.move_to(lhs)


        self.add(morty, title)
        self.dither()
        self.play(Blink(morty))
        self.play(Write(start))
        self.dither()
        self.play(Transform(start, lhs))
        self.dither()
        self.play(
            Transform(lhs, rhs, path_arc = -np.pi),
            Write(eq)
        )
        self.play(Write(q_marks))
        self.play(Blink(morty))
        self.play(morty.change_mode, "pondering")

        lp, a, b, rp, c = start.split()
        self.show_full_matrices(morty, a, b, c, title)
Exemple #14
0
    def construct(self):
        self.setup()
        matrix = Matrix(np.array(self.transposed_matrix).transpose())
        matrix.highlight_columns(X_COLOR, Y_COLOR)
        matrix.next_to(ORIGIN, LEFT).to_edge(UP)
        matrix_background = BackgroundRectangle(matrix)
        self.play(ShowCreation(matrix_background), Write(matrix))
        if self.show_square:
            self.add_unit_square(animate=True)
        self.add_foreground_mobject(matrix_background, matrix)
        self.wait()
        self.apply_transposed_matrix([self.transposed_matrix[0], [0, 1]])
        self.apply_transposed_matrix([[1, 0], self.transposed_matrix[1]])
        self.wait()
        if self.show_square:

            bottom_brace = Brace(self.i_hat, DOWN)
            right_brace = Brace(self.square, RIGHT)
            width = TexMobject(str(self.transposed_matrix[0][0]))
            height = TexMobject(str(self.transposed_matrix[1][1]))
            width.next_to(bottom_brace, DOWN)
            height.next_to(right_brace, RIGHT)
            for mob in bottom_brace, width, right_brace, height:
                mob.add_background_rectangle()
                self.play(Write(mob, run_time=0.5))
            self.wait()

            width_target, height_target = width.copy(), height.copy()
            det = np.linalg.det(self.transposed_matrix)
            times, eq_det = map(TexMobject, ["\\times", "=%d" % det])
            words = TextMobject("New area $=$")
            equation = VMobject(words, width_target, times, height_target,
                                eq_det)
            equation.arrange_submobjects(RIGHT, buff=0.2)
            equation.next_to(self.square, UP, aligned_edge=LEFT)
            equation.shift(0.5 * RIGHT)
            background_rect = BackgroundRectangle(equation)

            self.play(ShowCreation(background_rect),
                      Transform(width.copy(), width_target),
                      Transform(height.copy(), height_target),
                      *map(Write, [words, times, eq_det]))
            self.wait()
Exemple #15
0
    def construct(self):
        morty = Mortimer()
        morty.scale(0.8)
        morty.to_corner(DOWN + RIGHT)
        morty.shift(0.5 * LEFT)
        title = TextMobject("Associativity:")
        title.to_corner(UP + LEFT)

        lhs = TexMobject(list("(AB)C"))
        lp, a, b, rp, c = lhs.split()
        rhs = VMobject(*[m.copy() for m in a, lp, b, c, rp])
        point = VectorizedPoint()
        start = VMobject(*[m.copy() for m in point, a, b, point, c])
        for mob in lhs, rhs, start:
            mob.arrange_submobjects(buff=0.1)
        a, lp, b, c, rp = rhs.split()
        rhs = VMobject(lp, a, b, rp, c)  ##Align order to lhs
        eq = TexMobject("=")
        q_marks = TextMobject("???")
        q_marks.submobject_gradient_highlight(TEAL_B, TEAL_D)
        q_marks.next_to(eq, UP)
        lhs.next_to(eq, LEFT)
        rhs.next_to(eq, RIGHT)
        start.move_to(lhs)

        self.add(morty, title)
        self.wait()
        self.play(Blink(morty))
        self.play(Write(start))
        self.wait()
        self.play(Transform(start, lhs))
        self.wait()
        self.play(Transform(lhs, rhs, path_arc=-np.pi), Write(eq))
        self.play(Write(q_marks))
        self.play(Blink(morty))
        self.play(morty.change_mode, "pondering")

        lp, a, b, rp, c = start.split()
        self.show_full_matrices(morty, a, b, c, title)
Exemple #16
0
    def show_dependencies(self):
        linalg = TextMobject("Linear Algebra")
        subjects = map(TextMobject, [
            "Computer science", "Physics", "Electrical engineering",
            "Mechanical engineering", "Statistics", "\\vdots"
        ])
        prev = subjects[0]
        for subject in subjects[1:]:
            subject.next_to(prev, DOWN, aligned_edge=LEFT)
            prev = subject
        all_subs = VMobject(*subjects)
        linalg.to_edge(LEFT)
        all_subs.next_to(linalg, RIGHT, buff=2)
        arrows = VMobject(*[Arrow(linalg, sub) for sub in subjects])

        self.play(Write(linalg, run_time=1))
        self.wait()
        self.play(ShowCreation(arrows, submobject_mode="lagged_start"),
                  FadeIn(all_subs),
                  run_time=2)
        self.wait()
        self.linalg = linalg
Exemple #17
0
    def construct(self):
        m1_mob, m2_mob, comp_matrix = self.get_matrices()
        self.add(m1_mob, m2_mob, m1_mob.label, m2_mob.label, comp_matrix)
        result = self.get_result()

        col1, col2 = [
            VMobject(*m1_mob.split()[1].get_mob_matrix()[:,i])
            for i in 0, 1
        ]
        col1.target_color = X_COLOR
        col2.target_color = Y_COLOR
        for col in col1, col2:
            circle = Circle()
            circle.stretch_to_fit_height(m1_mob.get_height())
            circle.stretch_to_fit_width(m1_mob.get_width()/2.5)
            circle.highlight(col.target_color)
            circle.move_to(col)
            col.circle = circle

        triplets = [
            (col1, "i", X_COLOR),
            (col2, "j", Y_COLOR),
        ]
        for i, (col, char, color) in enumerate(triplets):
            self.add(col)
            start_state = self.get_mobjects()
            question = TextMobject(
                "Where does $\\hat{\\%smath}$ go?"%char 
            )
            question.split()[-4].highlight(color)
            question.split()[-5].highlight(color)
            question.scale(1.2)
            question.shift(DOWN)
            first = TextMobject("First here")
            first.highlight(color)
            first.shift(DOWN+LEFT)
            first_arrow = Arrow(
                first, col.circle.get_bottom(), color = color
            )
            second = TextMobject("Then to whatever this is")
            second.highlight(color)
            second.to_edge(RIGHT).shift(DOWN)

            m2_copy = m2_mob.copy()
            m2_target = m2_mob.copy()
            m2_target.next_to(m2_mob, DOWN, buff = 1)
            col_vect = Matrix(col.copy().split())
            col_vect.highlight(color)
            col_vect.next_to(m2_target, RIGHT, buff = 0.1)
            second_arrow = Arrow(second, col_vect, color = color)

            new_m2_copy = m2_mob.copy().split()[1]
            intermediate = VMobject(
                TexMobject("="),
                col_vect.copy().get_entries().split()[0],
                Matrix(new_m2_copy.get_mob_matrix()[:,0]),
                TexMobject("+"),
                col_vect.copy().get_entries().split()[1],
                Matrix(new_m2_copy.get_mob_matrix()[:,1]),
                TexMobject("=")
            )
            intermediate.arrange_submobjects(buff = 0.1)
            intermediate.next_to(col_vect, RIGHT)

            product = Matrix(result[:,i])
            product.next_to(intermediate, RIGHT)

            comp_col = VMobject(*comp_matrix.split()[1].get_mob_matrix()[:,i])

            self.play(Write(question, run_time = 1 ))
            self.dither()
            self.play(
                Transform(question, first),
                ShowCreation(first_arrow),
                ShowCreation(col.circle),
                ApplyMethod(col.highlight, col.target_color)
            )
            self.dither()
            self.play(
                Transform(m2_copy, m2_target, run_time = 2),
                ApplyMethod(col.copy().move_to, col_vect, run_time = 2),
                Write(col_vect.get_brackets()),
                Transform(first_arrow, second_arrow),
                Transform(question, second),
            )
            self.dither()
            self.play(*map(FadeOut, [question, first_arrow]))
            self.play(Write(intermediate))
            self.dither()
            self.play(Write(product))
            self.dither()
            product_entries = product.get_entries()
            self.play(
                ApplyMethod(comp_col.highlight, BLACK),
                ApplyMethod(product_entries.move_to, comp_col)
            )
            self.dither()

            start_state.append(product_entries)
            self.play(*[
                FadeOut(mob)
                for mob in self.get_mobjects()
                if mob not in start_state
            ] + [
                Animation(product_entries)
            ])
            self.dither()
Exemple #18
0
    def construct(self):
        vect = Matrix(["x", "y"])
        vect.get_entries().highlight(YELLOW)

        rot_matrix = Matrix([[0, -1], [1, 0]])
        rot_matrix.highlight(TEAL)
        shear_matrix = Matrix([[1, 1], [0, 1]])
        shear_matrix.highlight(PINK)
        l_paren, r_paren = map(TexMobject, ["\\Big(", "\\Big)"])
        for p in l_paren, r_paren:
            p.scale_to_fit_height(1.4 * vect.get_height())
        long_way = VMobject(shear_matrix, l_paren, rot_matrix, vect, r_paren)
        long_way.arrange_submobjects(buff=0.1)
        long_way.to_edge(LEFT).shift(UP)

        equals = TexMobject("=").next_to(long_way, RIGHT)

        comp_matrix = Matrix([[1, -1], [1, 0]])
        comp_matrix.highlight_columns(X_COLOR, Y_COLOR)
        vect_copy = vect.copy()
        short_way = VMobject(comp_matrix, vect_copy)
        short_way.arrange_submobjects(buff=0.1)
        short_way.next_to(equals, RIGHT)

        pairs = [
            (rot_matrix, "Rotation"),
            (shear_matrix, "Shear"),
            (comp_matrix, "Composition"),
        ]
        for matrix, word in pairs:
            brace = Brace(matrix)
            text = TextMobject(word).next_to(brace, DOWN)
            brace.highlight(matrix.get_color())
            text.highlight(matrix.get_color())
            matrix.add(brace, text)
        comp_matrix.split()[-1].submobject_gradient_highlight(TEAL, PINK)

        self.add(vect)
        groups = [
            [rot_matrix],
            [l_paren, r_paren, shear_matrix],
            [equals, comp_matrix, vect_copy],
        ]
        for group in groups:
            self.play(*map(Write, group))
            self.wait()
        self.play(*map(FadeOut, [l_paren, r_paren, vect, vect_copy]))
        comp_matrix.add(equals)
        matrices = VMobject(shear_matrix, rot_matrix, comp_matrix)
        self.play(
            ApplyMethod(matrices.arrange_submobjects,
                        buff=0.1,
                        aligned_edge=UP))
        self.wait()

        arrow = Arrow(rot_matrix.get_right(), shear_matrix.get_left())
        arrow.shift((rot_matrix.get_top()[1] + 0.2) * UP)
        words = TextMobject("Read right to left")
        words.submobjects.reverse()
        words.next_to(arrow, UP)
        functions = TexMobject("f(g(x))")
        functions.next_to(words, UP)

        self.play(ShowCreation(arrow))
        self.play(Write(words))
        self.wait()
        self.play(Write(functions))
        self.wait()
Exemple #19
0
    def construct(self):
        m1_mob, m2_mob, comp_matrix = self.get_matrices()
        self.add(m1_mob, m2_mob, m1_mob.label, m2_mob.label, comp_matrix)
        result = self.get_result()

        col1, col2 = [
            VMobject(*m1_mob.split()[1].get_mob_matrix()[:, i]) for i in 0, 1
        ]
        col1.target_color = X_COLOR
        col2.target_color = Y_COLOR
        for col in col1, col2:
            circle = Circle()
            circle.stretch_to_fit_height(m1_mob.get_height())
            circle.stretch_to_fit_width(m1_mob.get_width() / 2.5)
            circle.highlight(col.target_color)
            circle.move_to(col)
            col.circle = circle

        triplets = [
            (col1, "i", X_COLOR),
            (col2, "j", Y_COLOR),
        ]
        for i, (col, char, color) in enumerate(triplets):
            self.add(col)
            start_state = self.get_mobjects()
            question = TextMobject("Where does $\\hat{\\%smath}$ go?" % char)
            question.split()[-4].highlight(color)
            question.split()[-5].highlight(color)
            question.scale(1.2)
            question.shift(DOWN)
            first = TextMobject("First here")
            first.highlight(color)
            first.shift(DOWN + LEFT)
            first_arrow = Arrow(first, col.circle.get_bottom(), color=color)
            second = TextMobject("Then to whatever this is")
            second.highlight(color)
            second.to_edge(RIGHT).shift(DOWN)

            m2_copy = m2_mob.copy()
            m2_target = m2_mob.copy()
            m2_target.next_to(m2_mob, DOWN, buff=1)
            col_vect = Matrix(col.copy().split())
            col_vect.highlight(color)
            col_vect.next_to(m2_target, RIGHT, buff=0.1)
            second_arrow = Arrow(second, col_vect, color=color)

            new_m2_copy = m2_mob.copy().split()[1]
            intermediate = VMobject(TexMobject("="),
                                    col_vect.copy().get_entries().split()[0],
                                    Matrix(new_m2_copy.get_mob_matrix()[:, 0]),
                                    TexMobject("+"),
                                    col_vect.copy().get_entries().split()[1],
                                    Matrix(new_m2_copy.get_mob_matrix()[:, 1]),
                                    TexMobject("="))
            intermediate.arrange_submobjects(buff=0.1)
            intermediate.next_to(col_vect, RIGHT)

            product = Matrix(result[:, i])
            product.next_to(intermediate, RIGHT)

            comp_col = VMobject(*comp_matrix.split()[1].get_mob_matrix()[:, i])

            self.play(Write(question, run_time=1))
            self.wait()
            self.play(Transform(question, first), ShowCreation(first_arrow),
                      ShowCreation(col.circle),
                      ApplyMethod(col.highlight, col.target_color))
            self.wait()
            self.play(
                Transform(m2_copy, m2_target, run_time=2),
                ApplyMethod(col.copy().move_to, col_vect, run_time=2),
                Write(col_vect.get_brackets()),
                Transform(first_arrow, second_arrow),
                Transform(question, second),
            )
            self.wait()
            self.play(*map(FadeOut, [question, first_arrow]))
            self.play(Write(intermediate))
            self.wait()
            self.play(Write(product))
            self.wait()
            product_entries = product.get_entries()
            self.play(ApplyMethod(comp_col.highlight, BLACK),
                      ApplyMethod(product_entries.move_to, comp_col))
            self.wait()

            start_state.append(product_entries)
            self.play(*[
                FadeOut(mob)
                for mob in self.get_mobjects() if mob not in start_state
            ] + [Animation(product_entries)])
            self.wait()
Exemple #20
0
    def construct(self):
        vect = Matrix(["x", "y"])
        vect.get_entries().highlight(YELLOW)

        rot_matrix = Matrix([[0, -1], [1, 0]])
        rot_matrix.highlight(TEAL)
        shear_matrix = Matrix([[1, 1], [0, 1]])
        shear_matrix.highlight(PINK)
        l_paren, r_paren = map(TexMobject, ["\\Big(", "\\Big)"])
        for p in l_paren, r_paren:
            p.scale_to_fit_height(1.4*vect.get_height())
        long_way = VMobject(
            shear_matrix, l_paren, rot_matrix, vect, r_paren
        )
        long_way.arrange_submobjects(buff = 0.1)
        long_way.to_edge(LEFT).shift(UP)

        equals = TexMobject("=").next_to(long_way, RIGHT)

        comp_matrix = Matrix([[1, -1], [1, 0]])
        comp_matrix.highlight_columns(X_COLOR, Y_COLOR)
        vect_copy = vect.copy()
        short_way = VMobject(comp_matrix, vect_copy)
        short_way.arrange_submobjects(buff = 0.1)
        short_way.next_to(equals, RIGHT)

        pairs = [
            (rot_matrix, "Rotation"), 
            (shear_matrix, "Shear"),
            (comp_matrix, "Composition"),
        ]
        for matrix, word in pairs:
            brace = Brace(matrix)
            text = TextMobject(word).next_to(brace, DOWN)
            brace.highlight(matrix.get_color())
            text.highlight(matrix.get_color())
            matrix.add(brace, text)
        comp_matrix.split()[-1].submobject_gradient_highlight(TEAL, PINK)

        self.add(vect)
        groups = [
            [rot_matrix], 
            [l_paren, r_paren, shear_matrix],
            [equals, comp_matrix, vect_copy],
        ]
        for group in groups:
            self.play(*map(Write, group))
            self.dither()
        self.play(*map(FadeOut, [l_paren, r_paren, vect, vect_copy]))
        comp_matrix.add(equals)
        matrices = VMobject(shear_matrix, rot_matrix, comp_matrix)
        self.play(ApplyMethod(
            matrices.arrange_submobjects, buff = 0.1,
            aligned_edge = UP
        ))
        self.dither()

        arrow = Arrow(rot_matrix.get_right(), shear_matrix.get_left())
        arrow.shift((rot_matrix.get_top()[1]+0.2)*UP)
        words = TextMobject("Read right to left")
        words.submobjects.reverse()
        words.next_to(arrow, UP)
        functions = TexMobject("f(g(x))")
        functions.next_to(words, UP)

        self.play(ShowCreation(arrow))
        self.play(Write(words))
        self.dither()
        self.play(Write(functions))
        self.dither()