mirror of
https://github.com/3b1b/manim.git
synced 2025-08-01 17:29:06 +08:00
End of EoLA
This commit is contained in:
@ -1643,6 +1643,8 @@ class IntroducePolynomialSpace(Scene):
|
|||||||
|
|
||||||
def show_example_coordinates(self):
|
def show_example_coordinates(self):
|
||||||
coords = Matrix(["5", "3", "1", "0", "0", "\\vdots"])
|
coords = Matrix(["5", "3", "1", "0", "0", "\\vdots"])
|
||||||
|
for i, color in enumerate([X_COLOR, Y_COLOR, Z_COLOR]):
|
||||||
|
coords[i].highlight(color)
|
||||||
self.poly1.generate_target()
|
self.poly1.generate_target()
|
||||||
equals = TexMobject("=").next_to(coords, LEFT)
|
equals = TexMobject("=").next_to(coords, LEFT)
|
||||||
self.poly1.target.next_to(equals, LEFT)
|
self.poly1.target.next_to(equals, LEFT)
|
||||||
@ -1714,34 +1716,32 @@ class IntroducePolynomialSpace(Scene):
|
|||||||
rate_func = there_and_back
|
rate_func = there_and_back
|
||||||
)
|
)
|
||||||
self.remove(*self.get_mobjects_from_last_animation())
|
self.remove(*self.get_mobjects_from_last_animation())
|
||||||
|
self.add(self.poly2)
|
||||||
self.dither()
|
self.dither()
|
||||||
self.play(*map(FadeOut, [self.poly2, coords, equals]))
|
self.play(*map(FadeOut, [self.poly2, coords, equals]))
|
||||||
|
|
||||||
def derivative_as_matrix(self):
|
def derivative_as_matrix(self):
|
||||||
matrix = Matrix([
|
matrix = Matrix([
|
||||||
["?"]*4 + ["\\cdots"]
|
[
|
||||||
for x in range(4)
|
str(j) if j == i+1 else "0"
|
||||||
|
for j in range(4)
|
||||||
|
] + ["\\cdots"]
|
||||||
|
for i in range(4)
|
||||||
] + [
|
] + [
|
||||||
["\\vdots"]*4 + ["\\ddots"]
|
["\\vdots"]*4 + ["\\ddots"]
|
||||||
])
|
])
|
||||||
matrix.shift(2*LEFT)
|
matrix.shift(2*LEFT)
|
||||||
matrix.get_entries().gradient_highlight(GREEN, YELLOW, MAROON_B)
|
diag_entries = VGroup(*[
|
||||||
mob_matrix = matrix.get_mob_matrix()
|
matrix.get_mob_matrix()[i, i+1]
|
||||||
|
for i in range(3)
|
||||||
|
])
|
||||||
##Horrible
|
##Horrible
|
||||||
last_col = VGroup(*mob_matrix[:,-1])
|
last_col = VGroup(*matrix.get_mob_matrix()[:,-1])
|
||||||
last_col_top = last_col.get_top()
|
last_col_top = last_col.get_top()
|
||||||
last_col.arrange_submobjects(DOWN, buff = 0.83)
|
last_col.arrange_submobjects(DOWN, buff = 0.83)
|
||||||
last_col.move_to(last_col_top, aligned_edge = UP+RIGHT)
|
last_col.move_to(last_col_top, aligned_edge = UP+RIGHT)
|
||||||
##End horrible
|
##End horrible
|
||||||
colors = [X_COLOR, Y_COLOR, Z_COLOR, MAROON_B, YELLOW]
|
matrix.highlight_columns(X_COLOR, Y_COLOR, Z_COLOR, MAROON_B)
|
||||||
for i, j in it.product(*[range(4)]*2):
|
|
||||||
entry = mob_matrix[i, j]
|
|
||||||
if j == i+1:
|
|
||||||
entry.target = TexMobject(str(j))
|
|
||||||
else:
|
|
||||||
entry.target = TexMobject("0")
|
|
||||||
entry.target.scale(0.8).move_to(entry)
|
|
||||||
entry.target.highlight(colors[j])
|
|
||||||
|
|
||||||
deriv = TexMobject("\\dfrac{d}{dx}")
|
deriv = TexMobject("\\dfrac{d}{dx}")
|
||||||
equals = TexMobject("=")
|
equals = TexMobject("=")
|
||||||
@ -1751,84 +1751,139 @@ class IntroducePolynomialSpace(Scene):
|
|||||||
self.play(FadeIn(deriv), FadeIn(equals))
|
self.play(FadeIn(deriv), FadeIn(equals))
|
||||||
self.play(Write(matrix))
|
self.play(Write(matrix))
|
||||||
self.dither()
|
self.dither()
|
||||||
|
diag_entries.save_state()
|
||||||
basis_derivatives = [
|
diag_entries.generate_target()
|
||||||
"0",
|
diag_entries.target.scale_in_place(1.2)
|
||||||
"1",
|
diag_entries.target.highlight(YELLOW)
|
||||||
"2x",
|
for anim in MoveToTarget(diag_entries), diag_entries.restore:
|
||||||
"3x^2",
|
|
||||||
]
|
|
||||||
arrays = [
|
|
||||||
["0", "0", "0", "0", "\\vdots"],
|
|
||||||
["1", "0", "0", "0", "\\vdots"],
|
|
||||||
["0", "2", "0", "0", "\\vdots"],
|
|
||||||
["0", "0", "3", "0", "\\vdots"],
|
|
||||||
]
|
|
||||||
qunits = zip(
|
|
||||||
it.count(),
|
|
||||||
self.basis,
|
|
||||||
self.basis_functions,
|
|
||||||
basis_derivatives,
|
|
||||||
arrays
|
|
||||||
)
|
|
||||||
for j, basis, basis_func, basis_deriv_tex, arr in qunits:
|
|
||||||
matrix.save_state()
|
|
||||||
matrix.generate_target()
|
|
||||||
matrix.target.scale(0.35)
|
|
||||||
matrix.target.to_corner(UP+LEFT)
|
|
||||||
|
|
||||||
func, func_equals = basis_func
|
|
||||||
deriv_copy = deriv.copy()
|
|
||||||
movers = [func, equals, deriv_copy, basis, func_equals]
|
|
||||||
for mob in movers:
|
|
||||||
mob.generate_target()
|
|
||||||
mob.save_state()
|
|
||||||
lp, rp = TexMobject("()")
|
|
||||||
basis_deriv = TexMobject(basis_deriv_tex)
|
|
||||||
new_equals = TexMobject("=")
|
|
||||||
coords = Matrix(arr)
|
|
||||||
coords.highlight(basis.get_color())
|
|
||||||
basis_deriv.highlight(basis.get_color())
|
|
||||||
group = VGroup(
|
|
||||||
func.target, equals.target, deriv_copy.target,
|
|
||||||
lp, basis.target, rp, func_equals.target,
|
|
||||||
basis_deriv, new_equals, coords
|
|
||||||
)
|
|
||||||
group.arrange_submobjects()
|
|
||||||
group.next_to(deriv)
|
|
||||||
|
|
||||||
self.play(*it.chain(
|
|
||||||
map(MoveToTarget, [
|
|
||||||
matrix, func, equals,
|
|
||||||
deriv_copy, basis, func_equals
|
|
||||||
]),
|
|
||||||
map(Write, [lp, rp])
|
|
||||||
))
|
|
||||||
self.dither()
|
|
||||||
self.play(*map(Write, [basis_deriv, new_equals, coords]))
|
|
||||||
self.dither()
|
|
||||||
self.play(*it.chain(
|
|
||||||
[mob.restore for mob in movers+[matrix]],
|
|
||||||
map(FadeOut, [lp, rp, basis_deriv, new_equals]),
|
|
||||||
[coords.to_edge, RIGHT, 4]
|
|
||||||
))
|
|
||||||
|
|
||||||
column = VGroup(*[
|
|
||||||
mob_matrix[i,j]
|
|
||||||
for i in range(4)
|
|
||||||
])
|
|
||||||
column_target = VGroup(*[
|
|
||||||
mob.target
|
|
||||||
for mob in column
|
|
||||||
])
|
|
||||||
entries = VGroup(*coords.get_entries()[:4])
|
|
||||||
self.play(
|
self.play(
|
||||||
Transform(entries, column_target),
|
anim,
|
||||||
FadeOut(coords.get_brackets()),
|
submobject_mode = "lagged_start",
|
||||||
FadeOut(coords.get_entries()[-1]),
|
run_time = 1.5,
|
||||||
Transform(column, column_target)
|
|
||||||
)
|
)
|
||||||
self.remove(coords)
|
self.dither()
|
||||||
|
matrix.generate_target()
|
||||||
|
matrix.target.to_corner(DOWN+LEFT).shift(0.25*UP)
|
||||||
|
deriv.generate_target()
|
||||||
|
deriv.target.next_to(
|
||||||
|
matrix.target, UP,
|
||||||
|
buff = MED_BUFF,
|
||||||
|
aligned_edge = LEFT
|
||||||
|
)
|
||||||
|
deriv.target.shift(0.25*RIGHT)
|
||||||
|
self.play(
|
||||||
|
FadeOut(equals),
|
||||||
|
*map(MoveToTarget, [matrix, deriv])
|
||||||
|
)
|
||||||
|
|
||||||
|
poly = TexMobject(
|
||||||
|
"(", "1", "x^3", "+",
|
||||||
|
"5", "x^2", "+",
|
||||||
|
"4", "x", "+",
|
||||||
|
"5", ")"
|
||||||
|
)
|
||||||
|
coefs = VGroup(*np.array(poly)[[10, 7, 4, 1]])
|
||||||
|
VGroup(*poly[1:3]).highlight(MAROON_B)
|
||||||
|
VGroup(*poly[4:6]).highlight(Z_COLOR)
|
||||||
|
VGroup(*poly[7:9]).highlight(Y_COLOR)
|
||||||
|
VGroup(*poly[10:11]).highlight(X_COLOR)
|
||||||
|
poly.next_to(deriv)
|
||||||
|
self.play(FadeIn(poly))
|
||||||
|
|
||||||
|
array = Matrix(list(coefs.copy()) + [TexMobject("\\vdots")])
|
||||||
|
array.next_to(matrix, RIGHT)
|
||||||
|
self.play(Write(array.get_brackets()))
|
||||||
|
to_remove = []
|
||||||
|
for coef, entry in zip(coefs, array.get_entries()):
|
||||||
|
self.play(Transform(coef.copy(), entry))
|
||||||
|
to_remove += self.get_mobjects_from_last_animation()
|
||||||
|
self.play(Write(array.get_entries()[-1]))
|
||||||
|
to_remove += self.get_mobjects_from_last_animation()
|
||||||
|
self.remove(*to_remove)
|
||||||
|
self.add(array)
|
||||||
|
|
||||||
|
eq1, eq2 = TexMobject("="), TexMobject("=")
|
||||||
|
eq1.next_to(poly)
|
||||||
|
eq2.next_to(array)
|
||||||
|
|
||||||
|
poly_result = TexMobject(
|
||||||
|
"3", "x^2", "+",
|
||||||
|
"10", "x", "+",
|
||||||
|
"4"
|
||||||
|
)
|
||||||
|
poly_result.next_to(eq1)
|
||||||
|
brace = Brace(poly_result, buff = 0)
|
||||||
|
|
||||||
|
self.play(*map(Write, [eq1, eq2, brace]))
|
||||||
|
|
||||||
|
result_coefs = VGroup(*np.array(poly_result)[[6, 3, 0]])
|
||||||
|
VGroup(*poly_result[0:2]).highlight(MAROON_B)
|
||||||
|
VGroup(*poly_result[3:5]).highlight(Z_COLOR)
|
||||||
|
VGroup(*poly_result[6:]).highlight(Y_COLOR)
|
||||||
|
result_terms = [
|
||||||
|
VGroup(*poly_result[6:]),
|
||||||
|
VGroup(*poly_result[3:6]),
|
||||||
|
VGroup(*poly_result[0:3]),
|
||||||
|
]
|
||||||
|
relevant_entries = VGroup(*array.get_entries()[1:4])
|
||||||
|
dots = [TexMobject("\\cdot") for x in range(3)]
|
||||||
|
result_entries = []
|
||||||
|
for entry, diag_entry, dot in zip(relevant_entries, diag_entries, dots):
|
||||||
|
entry.generate_target()
|
||||||
|
diag_entry.generate_target()
|
||||||
|
group = VGroup(diag_entry.target, dot, entry.target)
|
||||||
|
group.arrange_submobjects()
|
||||||
|
result_entries.append(group)
|
||||||
|
result_array = Matrix(
|
||||||
|
result_entries + [
|
||||||
|
TexMobject("0"),
|
||||||
|
TexMobject("\\vdots")
|
||||||
|
]
|
||||||
|
)
|
||||||
|
result_array.next_to(eq2)
|
||||||
|
|
||||||
|
rects = [
|
||||||
|
Rectangle(
|
||||||
|
color = YELLOW
|
||||||
|
).replace(
|
||||||
|
VGroup(*matrix.get_mob_matrix()[i,:]),
|
||||||
|
stretch = True
|
||||||
|
).stretch_in_place(1.1, 0).stretch_in_place(1.3, 1)
|
||||||
|
for i in range(3)
|
||||||
|
]
|
||||||
|
vert_rect = Rectangle(color = YELLOW)
|
||||||
|
vert_rect.replace(array.get_entries(), stretch = True)
|
||||||
|
vert_rect.stretch_in_place(1.1, 1)
|
||||||
|
vert_rect.stretch_in_place(1.5, 0)
|
||||||
|
tuples = zip(
|
||||||
|
relevant_entries,
|
||||||
|
diag_entries,
|
||||||
|
result_entries,
|
||||||
|
rects,
|
||||||
|
result_terms,
|
||||||
|
coefs[1:]
|
||||||
|
)
|
||||||
|
self.play(Write(result_array.get_brackets()))
|
||||||
|
for entry, diag_entry, result_entry, rect, result_term, coef in tuples:
|
||||||
|
self.play(FadeIn(rect), FadeIn(vert_rect))
|
||||||
|
self.dither()
|
||||||
|
self.play(
|
||||||
|
entry.scale_in_place, 1.2,
|
||||||
|
diag_entry.scale_in_place, 1.2,
|
||||||
|
)
|
||||||
|
diag_entry_target, dot, entry_target = result_entry
|
||||||
|
self.play(
|
||||||
|
Transform(entry.copy(), entry_target),
|
||||||
|
Transform(diag_entry.copy(), diag_entry_target),
|
||||||
|
entry.scale_in_place, 1/1.2,
|
||||||
|
diag_entry.scale_in_place, 1/1.2,
|
||||||
|
Write(dot)
|
||||||
|
)
|
||||||
|
self.dither()
|
||||||
|
self.play(Transform(coef.copy(), VGroup(result_term)))
|
||||||
|
self.dither()
|
||||||
|
self.play(FadeOut(rect), FadeOut(vert_rect))
|
||||||
|
self.play(*map(Write, result_array.get_entries()[3:]))
|
||||||
self.dither()
|
self.dither()
|
||||||
|
|
||||||
class MatrixVectorMultiplicationAndDerivative(TeacherStudentsScene):
|
class MatrixVectorMultiplicationAndDerivative(TeacherStudentsScene):
|
||||||
@ -2046,20 +2101,21 @@ class ShowVectorSpaces(Scene):
|
|||||||
return arrays
|
return arrays
|
||||||
|
|
||||||
def get_functions(self):
|
def get_functions(self):
|
||||||
|
axes = Axes()
|
||||||
|
axes.scale(0.3)
|
||||||
functions = VGroup(*[
|
functions = VGroup(*[
|
||||||
TexMobject(poly)
|
FunctionGraph(func, x_min = -4, x_max = 4)
|
||||||
for poly in [
|
for func in [
|
||||||
"x^2+3x+5",
|
lambda x : x**3 - 9*x,
|
||||||
"4x^7-5x^2",
|
lambda x : x**3 - 4*x,
|
||||||
"x^{100}+2x^{99}+3x^{98}",
|
lambda x : x**2 - 1,
|
||||||
"3x-7",
|
|
||||||
"x^{1{,}000{,}000{,}000}+1",
|
|
||||||
"\\vdots",
|
|
||||||
]
|
]
|
||||||
])
|
])
|
||||||
functions.arrange_submobjects(DOWN, buff = MED_BUFF)
|
functions.stretch_to_fit_width(SPACE_WIDTH/2.)
|
||||||
|
functions.stretch_to_fit_height(6)
|
||||||
functions.gradient_highlight(YELLOW, MAROON_B)
|
functions.gradient_highlight(YELLOW, MAROON_B)
|
||||||
return functions
|
functions.center()
|
||||||
|
return VGroup(axes, functions)
|
||||||
|
|
||||||
class ToolsOfLinearAlgebra(Scene):
|
class ToolsOfLinearAlgebra(Scene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
|
@ -253,14 +253,18 @@ class Mobject(object):
|
|||||||
self.to_edge(vect, **kwargs)
|
self.to_edge(vect, **kwargs)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def stretch_in_place(self, factor, dim):
|
||||||
|
self.do_in_place(self.stretch, factor, dim)
|
||||||
|
return self
|
||||||
|
|
||||||
def stretch_to_fit(self, length, dim, stretch = True):
|
def stretch_to_fit(self, length, dim, stretch = True):
|
||||||
old_length = self.length_over_dim(dim)
|
old_length = self.length_over_dim(dim)
|
||||||
if old_length == 0:
|
if old_length == 0:
|
||||||
return self
|
return self
|
||||||
if stretch:
|
if stretch:
|
||||||
self.do_in_place(self.stretch, length/old_length, dim)
|
self.stretch_in_place(length/old_length, dim)
|
||||||
else:
|
else:
|
||||||
self.do_in_place(self.scale, length/old_length)
|
self.scale_in_place(length/old_length)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def stretch_to_fit_width(self, width):
|
def stretch_to_fit_width(self, width):
|
||||||
@ -497,9 +501,6 @@ class Mobject(object):
|
|||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return iter(self.split())
|
return iter(self.split())
|
||||||
|
|
||||||
def __len__(self):
|
|
||||||
return len(self.split())
|
|
||||||
|
|
||||||
def split(self):
|
def split(self):
|
||||||
result = [self] if len(self.points) > 0 else []
|
result = [self] if len(self.points) > 0 else []
|
||||||
return result + self.submobjects
|
return result + self.submobjects
|
||||||
|
Reference in New Issue
Block a user