Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

RefreshOnDerivativeDefinition in eoc7

Grant Sandersondea0d4a948c4
diff --git a/animation/simple_animations.py b/animation/simple_animations.py
index 76c134cb7..8bb7084dc 100644
--- a/animation/simple_animations.py
+++ b/animation/simple_animations.py
@@ -178,6 +178,26 @@ class SmoothedVectorizedHomotopy(Homotopy):
submob.make_smooth()
+class ApplyWave(Homotopy):
+ CONFIG = {
+ "direction" : DOWN,
+ "amplitude" : 0.2,
+ "run_time" : 1,
+ }
+ def __init__(self, mobject, **kwargs):
+ digest_config(self, kwargs, locals())
+ left_x = mobject.get_left()[0]
+ right_x = mobject.get_right()[0]
+ vect = self.amplitude*self.direction
+ def homotopy(x, y, z, t):
+ start_point = np.array([x, y, z])
+ alpha = (x-left_x)/(right_x-left_x)
+ power = np.exp(2*(alpha-0.5))
+ nudge = there_and_back(t**power)
+ return np.array([x, y, z]) + nudge*vect
+ Homotopy.__init__(self, homotopy, mobject, **kwargs)
+
+
class PhaseFlow(Animation):
CONFIG = {
"virtual_time" : 1,
diff --git a/eoc/chapter4.py b/eoc/chapter4.py
index 4892559ea..dcfcc18cf 100644
--- a/eoc/chapter4.py
+++ b/eoc/chapter4.py
@@ -25,2227 +25,1113 @@ from camera import Camera
from mobject.svg_mobject import *
from mobject.tex_mobject import *
-
from topics.common_scenes import OpeningQuote, PatreonThanks
-from eoc.graph_scene import *
-SINE_COLOR = BLUE
-X_SQUARED_COLOR = GREEN
-SUM_COLOR = YELLOW
-PRODUCT_COLOR = YELLOW
+from eoc.graph_scene import *
-class Chapter3OpeningQuote(OpeningQuote):
+class ExpFootnoteOpeningQuote(OpeningQuote):
CONFIG = {
"quote" : [
- "Using the chain rule is like peeling an onion: ",
- "you have to deal with each layer at a time, and ",
- "if it is too big you will start crying."
+ "Who has not been amazed to learn that the function",
+ "$y = e^x$,", "like a phoenix rising again from its own",
+ "ashes, is its own derivative?",
],
- "author" : "(Anonymous professor)"
+ "highlighted_quote_terms" : {
+ "$y = e^x$" : MAROON_B
+ },
+ "author" : "Francois le Lionnais"
}
-class TransitionFromLastVideo(TeacherStudentsScene):
+class LastVideo(TeacherStudentsScene):
def construct(self):
- simple_rules = VGroup(*map(TexMobject, [
- "\\frac{d(x^3)}{dx} = 3x^2",
- "\\frac{d(\\sin(x))}{dx} = \\cos(x)",
- "\\frac{d(e^x)}{dx} = e^x",
- ]))
-
- combination_rules = VGroup(*[
- TexMobject("\\frac{d}{dx}\\left(%s\\right)"%tex)
- for tex in [
- "\\sin(x) + x^2",
- "\\sin(x)(x^2)",
- "\\sin(x^2)",
- ]
- ])
- for rules in simple_rules, combination_rules:
- rules.arrange_submobjects(buff = LARGE_BUFF)
- rules.next_to(self.get_teacher(), UP, buff = MED_LARGE_BUFF)
- rules.to_edge(LEFT)
-
series = VideoSeries()
series.to_edge(UP)
last_video = series[2]
last_video.save_state()
this_video = series[3]
- brace = Brace(last_video)
- #Simple rules
+ known_formulas = VGroup(*map(TexMobject, [
+ "\\frac{d(x^n)}{dx} = nx^{n-1}",
+ "\\frac{d(\\sin(x))}{dx} = \\cos(x)",
+ ]))
+ known_formulas.arrange_submobjects(
+ DOWN, buff = MED_LARGE_BUFF,
+ )
+ known_formulas.scale_to_fit_height(2.5)
+ exp_question = TexMobject("2^x", ", 7^x", ", e^x", " ???")
+
+ last_video_brace = Brace(last_video)
+ known_formulas.next_to(last_video_brace, DOWN)
+ last_video_brace.save_state()
+ last_video_brace.shift(3*LEFT)
+ last_video_brace.set_fill(opacity = 0)
+
self.add(series)
self.play(
- FadeIn(brace),
- last_video.highlight, YELLOW
+ last_video_brace.restore,
+ last_video.highlight, YELLOW,
+ self.get_teacher().change_mode, "raise_right_hand",
+ )
+ self.play(Write(known_formulas))
+ self.dither()
+ self.student_says(
+ exp_question, student_index = -1,
+ added_anims = [self.get_teacher().change_mode, "pondering"]
)
- for rule in simple_rules:
- self.play(
- Write(rule, run_time = 2),
- self.get_teacher().change_mode, "raise_right_hand",
- *[
- ApplyMethod(pi.change_mode, "pondering")
- for pi in self.get_students()
- ]
- )
- self.dither()
self.dither(2)
- self.play(simple_rules.replace, last_video)
+ self.play(known_formulas.replace, last_video)
+ self.play(last_video_brace.next_to, this_video, DOWN)
self.play(
- last_video.restore,
- Animation(simple_rules),
- brace.next_to, this_video, DOWN,
+ last_video.restore,
this_video.highlight, YELLOW
)
-
- #Combination rules
- self.play(
- Write(combination_rules),
- *[
- ApplyMethod(pi.change_mode, "confused")
- for pi in self.get_students()
- ]
+ self.play(
+ exp_question.next_to, last_video_brace, DOWN,
+ FadeOut(self.get_students()[-1].bubble),
+ )
+ self.change_student_modes(
+ *["pondering"]*3,
+ look_at_arg = exp_question
)
- self.dither(2)
- for rule in combination_rules:
- interior = VGroup(*rule[5:-1])
- added_anims = []
- if rule is combination_rules[-1]:
- inner_func = VGroup(*rule[-4:-2])
- self.play(inner_func.shift, 0.5*UP)
- added_anims = [
- inner_func.shift, 0.5*DOWN,
- inner_func.highlight, YELLOW
- ]
- self.play(
- interior.highlight, YELLOW,
- *added_anims,
- submobject_mode = "lagged_start"
- )
- self.dither()
self.dither()
- #Address subtraction and division
- subtraction = TexMobject("\\sin(x)", "-", "x^2")
- decomposed_subtraction = TexMobject("\\sin(x)", "+(-1)\\cdot", "x^2")
- pre_division = TexMobject("\\frac{\\sin(x)}{x^2}")
- division = VGroup(
- VGroup(*pre_division[:6]),
- VGroup(*pre_division[6:7]),
- VGroup(*pre_division[7:]),
- )
- pre_decomposed_division = TexMobject("\\sin(x)\\cdot\\frac{1}{x^2}")
- decomposed_division = VGroup(
- VGroup(*pre_decomposed_division[:6]),
- VGroup(*pre_decomposed_division[6:9]),
- VGroup(*pre_decomposed_division[9:]),
- )
- for mob in subtraction, decomposed_subtraction, division, decomposed_division:
- mob.next_to(
- VGroup(self.get_teacher(), self.get_students()[-1]),
- UP, buff = MED_LARGE_BUFF
- )
+class PopulationSizeGraphVsPopulationMassGraph(Scene):
+ def construct(self):
+ pass
- top_group = VGroup(series, simple_rules, brace)
- combination_rules.save_state()
- self.play(
- top_group.next_to, SPACE_HEIGHT*UP, UP,
- combination_rules.to_edge, UP,
- )
- pairs = [
- (subtraction, decomposed_subtraction),
- (division, decomposed_division)
- ]
- for question, answer in pairs:
- self.play(
- Write(question),
- combination_rules.fade, 0.2,
- self.get_students()[2].change_mode, "raise_right_hand",
- self.get_teacher().change_mode, "plain",
- )
- self.dither()
- answer[1].highlight(GREEN)
- self.play(
- Transform(question, answer),
- self.get_teacher().change_mode, "hooray",
- self.get_students()[2].change_mode, "plain",
- )
- self.dither()
- self.play(FadeOut(question))
-
- #Monstrous expression
- monster = TexMobject(
- "\\Big(",
- "e^{\\sin(x)} \\cdot",
- "\\cos\\Big(",
- "\\frac{1}{x^3}",
- " + x^3",
- "\\Big)",
- "\\Big)^4"
- )
- monster.next_to(self.get_pi_creatures(), UP)
- parts = [
- VGroup(*monster[3][2:]),
- VGroup(*monster[3][:2]),
- monster[4],
- VGroup(monster[2], monster[5]),
- monster[1],
- VGroup(monster[0], monster[6])
+class DoublingPopulation(PiCreatureScene):
+ CONFIG = {
+ "time_color" : YELLOW,
+ "pi_creature_grid_dimensions" : (8, 8),
+ "pi_creature_grid_height" : 6,
+ }
+
+ def construct(self):
+ self.remove(self.get_pi_creatures())
+ self.introduce_expression()
+ self.introduce_pi_creatures()
+ self.count_through_days()
+ self.ask_about_dM_dt()
+ self.growth_per_day()
+ self.relate_growth_rate_to_pop_size()
+
+ def introduce_expression(self):
+ f_x = TexMobject("f(x)", "=", "2^x")
+ f_t = TexMobject("f(t)", "=", "2^t")
+ P_t = TexMobject("P(t)", "=", "2^t")
+ M_t = TexMobject("M(t)", "=", "2^t")
+ functions = VGroup(f_x, f_t, P_t, M_t)
+ for function in functions:
+ function.scale(1.2)
+ function.to_corner(UP+LEFT)
+ for function in functions[1:]:
+ for i, j in (0, 2), (2, 1):
+ function[i][j].highlight(self.time_color)
+
+ t_expression = TexMobject("t", "=", "\\text{Time (in days)}")
+ t_expression.to_corner(UP+RIGHT)
+ t_expression[0].highlight(self.time_color)
+
+ pop_brace, mass_brace = [
+ Brace(function[0], DOWN)
+ for function in P_t, M_t
]
- modes = 3*["erm"] + 3*["pleading"]
- for part, mode in zip(parts, modes):
- self.play(
- FadeIn(part, submobject_mode = "lagged_start"),
- self.get_teacher().change_mode, "raise_right_hand",
- *[
- ApplyMethod(pi.change_mode, mode)
- for pi in self.get_students()
- ]
- )
- self.dither()
- self.change_student_modes(*["happy"]*3)
- words = map(TextMobject, [
- "composition", "product",
- "composition", "sum",
- "composition"
- ])
+ for brace, word in (pop_brace, "size"), (mass_brace, "mass"):
+ text = brace.get_text("Population %s"%word)
+ text.to_edge(LEFT)
+ brace.text = text
- for word, part in zip(words, reversed(parts)):
- word.highlight(YELLOW)
- word.next_to(monster, UP)
- self.play(
- FadeIn(word),
- part.scale_in_place, 1.2,
- part.highlight, YELLOW
+ self.play(Write(f_x))
+ self.dither()
+ self.play(
+ Transform(f_x, f_t),
+ FadeIn(
+ t_expression,
+ run_time = 2,
+ submobject_mode = "lagged_start"
)
- self.dither()
- self.play(*map(FadeOut, [word, part]))
- self.play(FadeOut(parts[0]))
-
- #Bring back combinations
+ )
+ self.play(Transform(f_x, P_t))
self.play(
- combination_rules.restore,
- *[
- ApplyMethod(pi_creature.change_mode, "pondering")
- for pi_creature in self.get_pi_creatures()
- ]
+ GrowFromCenter(pop_brace),
+ Write(pop_brace.text, run_time = 2)
)
self.dither(2)
-class DampenedSpring(Scene):
- def construct(self):
- compact_spring, extended_spring = [
- ParametricFunction(
- lambda t : (t/denom)*RIGHT+np.sin(t)*UP+np.cos(t)*OUT,
- t_max = 12*np.pi,
- num_anchor_points = 100,
- color = GREY,
- ).shift(3*LEFT)
- for denom in 12.0, 2.0
- ]
- for spring in compact_spring, extended_spring:
- spring.scale(0.5)
- spring.rotate(np.pi/6, UP)
- spring.highlight(GREY)
- spring.shift(-spring.points[0] + 3*LEFT)
-
- moving_spring = compact_spring.copy()
-
- def update_spring(spring, a):
- spring.interpolate(
- compact_spring,
- extended_spring,
- 0.5*(np.exp(-4*a)*np.cos(40*a)+1)
- )
-
- equation = TexMobject(
- "\\text{Length} = 2 + e^{-4t}\\cos(20t)"
- )
- equation.to_edge(UP)
+ self.function = f_x
+ self.pop_brace = pop_brace
+ self.t_expression = t_expression
+ self.mass_function = M_t
+ self.mass_brace = mass_brace
+ def introduce_pi_creatures(self):
+ creatures = self.get_pi_creatures()
+ total_num_days = self.get_num_days()
+ num_start_days = 4
- self.add(moving_spring, equation)
- self.play(UpdateFromAlphaFunc(
- moving_spring, update_spring, run_time = 10,
- rate_func = None
- ))
+ self.reset()
+ for x in range(num_start_days):
+ self.let_one_day_pass()
self.dither()
-
-class ComingUp(Scene):
- def construct(self):
- rect = Rectangle(height = 9, width = 16)
- rect.set_stroke(WHITE)
- rect.scale_to_fit_height(2*SPACE_HEIGHT-2)
- title = TextMobject("Coming up...")
- title.to_edge(UP)
- rect.next_to(title, DOWN)
-
- self.play(Write(title))
- self.play(ShowCreation(rect))
+ self.play(
+ Transform(self.function, self.mass_function),
+ Transform(self.pop_brace, self.mass_brace),
+ Transform(self.pop_brace.text, self.mass_brace.text),
+ )
self.dither()
-
-class PreSumRuleDiscussion(Scene):
- def construct(self):
- title = TextMobject("Sum rule")
- title.to_edge(UP)
- self.add(title)
-
- specific = TexMobject(
- "\\frac{d}{dx}(", "\\sin(x)", "+", "x^2", ")",
- "=", "\\cos(x)", "+", "2x"
- )
- general = TexMobject(
- "\\frac{d}{dx}(", "g(x)", "+", "h(x)", ")",
- "=", "\\frac{dg}{dx}", "+", "\\frac{dh}{dx}"
- )
- for formula in specific, general:
- formula[1].highlight(SINE_COLOR)
- formula[6].highlight(SINE_COLOR)
- formula[3].highlight(X_SQUARED_COLOR)
- formula[8].highlight(X_SQUARED_COLOR)
- VGroup(specific, general).arrange_submobjects(DOWN, buff = LARGE_BUFF)
-
- #Add on rules
- self.add(specific)
- for i in 0, 4, 5:
- self.add(general[i])
- self.dither(2)
- for indices in [(1, 2, 3), (6,), (7, 8)]:
- self.play(*[
- ReplacementTransform(
- specific[i].copy(), general[i]
- )
- for i in indices
- ])
+ for x in range(total_num_days-num_start_days):
+ self.let_one_day_pass()
self.dither()
-
- #Highlight parts
- for i in 1, 3, -1, 6, 8:
- if i < 0:
- self.dither()
- else:
- part = specific[i]
- self.play(
- part.highlight, YELLOW,
- part.scale_in_place, 1.2,
- rate_func = there_and_back
- )
+ self.joint_blink(shuffle = False)
self.dither()
-class SumRule(GraphScene):
- CONFIG = {
- "x_labeled_nums" : [],
- "y_labeled_nums" : [],
- "y_axis_label" : "",
- "x_max" : 4,
- "x_axis_width" : 2*SPACE_WIDTH,
- "y_max" : 3,
- "graph_origin" : 2.5*DOWN + 2.5*LEFT,
- "graph_label_x_value" : 1.5,
- "example_input" : 0.5,
- "example_input_string" : "0.5",
- "dx" : 0.05,
- "v_lines_x_min" : -1,
- "v_lines_x_max" : 2,
- "graph_scale_factor" : 2,
- "tex_scale_factor" : 0.8,
- }
- def construct(self):
- self.write_function()
- self.add_graphs()
- self.zoom_in_on_graph()
- self.show_example_stacking()
- self.show_df()
- self.expand_derivative()
-
- def write_function(self):
- func_mob = TexMobject("f(x)", "=", "\\sin(x)", "+", "x^2")
- func_mob.scale(self.tex_scale_factor)
- func_mob.highlight_by_tex("f(x)", SUM_COLOR)
- func_mob.highlight_by_tex("\\sin(x)", SINE_COLOR)
- func_mob.highlight_by_tex("x^2", X_SQUARED_COLOR)
- func_mob.to_corner(UP+LEFT)
- self.add(func_mob)
-
- self.func_mob = func_mob
-
- def add_graphs(self):
- self.setup_axes()
- sine_graph = self.get_graph(np.sin, color = SINE_COLOR)
- parabola = self.get_graph(lambda x : x**2, color = X_SQUARED_COLOR)
- sum_graph = self.get_graph(
- lambda x : np.sin(x) + x**2,
- color = SUM_COLOR
- )
- sine_label = self.get_graph_label(
- sine_graph, "\\sin(x)",
- x_val = self.graph_label_x_value,
- direction = UP+RIGHT,
- buff = 0,
- )
- sine_label.scale_in_place(self.tex_scale_factor)
- parabola_label = self.get_graph_label(
- parabola, "x^2", x_val = self.graph_label_x_value,
- )
- parabola_label.scale_in_place(self.tex_scale_factor)
-
- graphs = VGroup(sine_graph, parabola)
- labels = VGroup(sine_label, parabola_label)
- for label in labels:
- label.add_background_rectangle()
-
- for graph, label in zip(graphs, labels):
- self.play(
- ShowCreation(graph),
- Write(label)
- )
- self.dither()
+ def count_through_days(self):
+ self.reset()
+ brace = self.get_population_size_descriptor()
+ days_to_let_pass = 3
- num_lines = (self.v_lines_x_max-self.v_lines_x_min)/self.dx
- sine_v_lines, parabox_v_lines = v_line_sets = [
- self.get_vertical_lines_to_graph(
- graph,
- x_min = self.v_lines_x_min,
- x_max = self.v_lines_x_max,
- num_lines = num_lines,
- stroke_width = 2
- )
- for graph in graphs
- ]
- sine_v_lines.shift(0.02*RIGHT)
- for v_lines in v_line_sets:
- self.play(ShowCreation(v_lines), Animation(labels))
- self.dither()
- self.play(*it.chain(
- [
- ApplyMethod(l2.move_to, l1.get_top(), DOWN)
- for l1, l2, in zip(*v_line_sets)
- ],
- [graph.fade for graph in graphs],
- [Animation(labels)]
- ))
+ self.play(GrowFromCenter(brace))
self.dither()
+ for x in range(days_to_let_pass):
+ self.let_one_day_pass()
+ new_brace = self.get_population_size_descriptor()
+ self.play(Transform(brace, new_brace))
+ self.dither()
- self.play(ShowCreation(sum_graph))
- self.dither()
+ self.population_size_descriptor = brace
- self.sum_graph = sum_graph
- self.parabola = parabola
- self.sine_graph = sine_graph
- self.graph_labels = labels
- self.v_line_sets = v_line_sets
-
- def zoom_in_on_graph(self):
- graph_parts = VGroup(
- self.axes,
- self.sine_graph, self.parabola, self.sum_graph,
- *self.v_line_sets
- )
- graph_parts.remove(self.func_mob, *self.graph_labels)
- graph_parts.generate_target()
- self.graph_labels.generate_target()
- for mob in graph_parts, self.graph_labels:
- mob.target.scale(
- self.graph_scale_factor,
- about_point = self.graph_origin,
- )
- for mob in self.graph_labels.target:
- mob.scale(
- 1./self.graph_scale_factor,
- about_point = mob.get_bottom()
- )
- mob.shift_onto_screen()
- self.play(*map(MoveToTarget, [
- graph_parts, self.graph_labels
- ]))
- self.dither()
+ def ask_about_dM_dt(self):
+ dM_dt_question = TexMobject("{dM", "\\over dt}", "=", "???")
+ dM, dt, equals, q_marks = dM_dt_question
+ dM_dt_question.next_to(self.function, DOWN, buff = LARGE_BUFF)
+ dM_dt_question.to_edge(LEFT)
- def show_example_stacking(self):
- v_line_sets = self.v_line_sets
- num_lines = len(v_line_sets[0])
- example_v_lines, nudged_v_lines = [
- VGroup(*[v_lines[index] for v_lines in v_line_sets])
- for index in (num_lines/2, num_lines/2+1)
- ]
- for line in nudged_v_lines:
- line.save_state()
- sine_lines, parabola_lines = [
- VGroup(example_v_lines[i], nudged_v_lines[i])
- for i in 0, 1
- ]
- faders = VGroup(*filter(
- lambda line : line not in example_v_lines,
- it.chain(*v_line_sets)
- ))
- label_groups = []
- for line, tex, vect in zip(sine_lines, ["", "+dx"], [LEFT, RIGHT]):
- dot = Dot(line.get_bottom(), radius = 0.03, color = YELLOW)
- label = TexMobject(
- "x=" + str(self.example_input) + tex
- )
- label.next_to(dot, DOWN+vect, buff = MED_LARGE_BUFF)
- arrow = Arrow(
- label.get_corner(UP-vect), dot,
- buff = SMALL_BUFF,
- color = WHITE,
- tip_length = 0.1
- )
- label_groups.append(VGroup(label, arrow, dot))
+ self.play(
+ FadeOut(self.pop_brace),
+ FadeOut(self.pop_brace.text),
+ Write(dM_dt_question)
+ )
+ self.dither(3)
+ for mob in dM, dt:
+ self.play(Indicate(mob))
+ self.dither()
+
+ self.dM_dt_question = dM_dt_question
- line_tex_direction_triplets = [
- (sine_lines[0], "\\sin(0.5)", LEFT),
- (sine_lines[1], "\\sin(0.5+dx)", RIGHT),
- (parabola_lines[0], "(0.5)^2", LEFT),
- (parabola_lines[1], "(0.5+dx)^2", RIGHT),
+ def growth_per_day(self):
+ day_to_day, frac = self.get_from_day_to_day_label()
+
+ self.play(
+ FadeOut(self.dM_dt_question),
+ FadeOut(self.population_size_descriptor),
+ FadeIn(day_to_day)
+ )
+ rect = self.let_day_pass_and_highlight_new_creatures(frac)
+
+ for x in range(2):
+ new_day_to_day, new_frac = self.get_from_day_to_day_label()
+ self.play(*map(FadeOut, [rect, frac]))
+ frac = new_frac
+ self.play(Transform(day_to_day, new_day_to_day))
+ rect = self.let_day_pass_and_highlight_new_creatures(frac)
+ self.play(*map(FadeOut, [rect, frac, day_to_day]))
+
+ def let_day_pass_and_highlight_new_creatures(self, frac):
+ num_new_creatures = 2**self.get_curr_day()
+
+ self.let_one_day_pass()
+ new_creatures = VGroup(
+ *self.get_on_screen_pi_creatures()[-num_new_creatures:]
+ )
+ rect = Rectangle(
+ color = GREEN,
+ fill_color = BLUE,
+ fill_opacity = 0.3,
+ )
+ rect.replace(new_creatures, stretch = True)
+ rect.stretch_to_fit_height(rect.get_height()+MED_SMALL_BUFF)
+ rect.stretch_to_fit_width(rect.get_width()+MED_SMALL_BUFF)
+ self.play(DrawBorderThenFill(rect))
+ self.play(Write(frac))
+ self.dither()
+ return rect
+
+ def relate_growth_rate_to_pop_size(self):
+ false_deriv = TexMobject(
+ "{d(2^t) ", "\\over dt}", "= 2^t"
+ )
+ difference_eq = TexMobject(
+ "{ {2^{t+1} - 2^t} \\over", "1}", "= 2^t"
+ )
+ real_deriv = TexMobject(
+ "{ {2^{t+dt} - 2^t} \\over", "dt}", "= \\, ???"
+ )
+ VGroup(
+ false_deriv[0][3],
+ false_deriv[2][-1],
+ difference_eq[0][1],
+ difference_eq[0][-2],
+ difference_eq[2][-1],
+ difference_eq[2][-1],
+ real_deriv[0][1],
+ real_deriv[0][-2],
+ ).highlight(YELLOW)
+ VGroup(
+ difference_eq[0][3],
+ difference_eq[1][-1],
+ real_deriv[0][3],
+ real_deriv[0][4],
+ real_deriv[1][-2],
+ real_deriv[1][-1],
+ ).highlight(GREEN)
+
+ expressions = [false_deriv, difference_eq, real_deriv]
+ text_arg_list = [
+ ("Tempting", "...",),
+ ("Rate of change", "\\\\ over one full day"),
+ ("Rate of change", "\\\\ in a small time"),
]
- for line, tex, direction in line_tex_direction_triplets:
- line.brace = Brace(
- line, direction,
- buff = SMALL_BUFF,
- min_num_quads = 2,
- )
- line.brace.highlight(line.get_color())
- line.brace.add_background_rectangle()
- line.brace_text = line.brace.get_text("$%s$"%tex)
- line.brace_text.scale(
- self.tex_scale_factor,
- about_point = line.brace_text.get_edge_center(-direction)
- )
- line.brace_text.add_background_rectangle()
- line.brace_anim = MaintainPositionRelativeTo(
- VGroup(line.brace, line.brace_text), line
+ for expression, text_args in zip(expressions, text_arg_list):
+ expression.next_to(
+ self.function, DOWN,
+ buff = LARGE_BUFF,
+ aligned_edge = LEFT,
)
+ expression.brace = Brace(expression, DOWN)
+ expression.brace_text = expression.brace.get_text(*text_args)
- ##Look at example lines
- self.play(
- example_v_lines.set_stroke, None, 4,
- faders.fade,
- Animation(self.graph_labels),
- Write(label_groups[0]),
- )
- for line in example_v_lines:
- line.save_state()
- self.dither()
- self.play(
- GrowFromCenter(sine_lines[0].brace),
- Write(sine_lines[0].brace_text),
- )
- self.dither()
- self.play(
- sine_lines[0].shift, UP+4*LEFT,
- sine_lines[0].brace_anim,
- parabola_lines[0].move_to, sine_lines[0], DOWN
- )
+ time = self.t_expression[-1]
+ new_time = TexMobject("3")
+ new_time.move_to(time, LEFT)
+
+ fading_creatures = VGroup(*self.get_on_screen_pi_creatures()[8:])
+
+
+ self.play(*map(FadeIn, [
+ false_deriv, false_deriv.brace, false_deriv.brace_text
+ ]))
self.dither()
- parabola_lines[0].brace_anim.update(1)
self.play(
- GrowFromCenter(parabola_lines[0].brace),
- Write(parabola_lines[0].brace_text),
+ Transform(time, new_time),
+ FadeOut(fading_creatures)
)
self.dither()
- self.play(*it.chain(*[
- [line.restore, line.brace_anim]
- for line in example_v_lines
- ]))
+ for x in range(3):
+ self.let_one_day_pass(run_time = 2)
+ self.dither(2)
- ## Nudged_lines
- self.play(
- Write(label_groups[1]),
- *it.chain(*[
- [line.restore, line.set_stroke, None, 4]
- for line in nudged_v_lines
- ])
- )
- self.dither()
- for line in nudged_v_lines:
+ for expression in difference_eq, real_deriv:
+ expression.brace_text[1].highlight(GREEN)
self.play(
- GrowFromCenter(line.brace),
- Write(line.brace_text)
+ Transform(false_deriv, expression),
+ Transform(false_deriv.brace, expression.brace),
+ Transform(false_deriv.brace_text, expression.brace_text),
)
+ self.dither(3)
+ self.reset()
+ for x in range(self.get_num_days()):
+ self.let_one_day_pass()
self.dither()
- self.sine_lines = sine_lines
- self.parabola_lines = parabola_lines
+ rect = Rectangle(color = YELLOW)
+ rect.replace(real_deriv)
+ rect.stretch_to_fit_width(rect.get_width()+MED_SMALL_BUFF)
+ rect.stretch_to_fit_height(rect.get_height()+MED_SMALL_BUFF)
+ self.play(*map(FadeOut, [
+ false_deriv.brace, false_deriv.brace_text
+ ]))
+ self.play(ShowCreation(rect))
+ self.play(*[
+ ApplyFunction(
+ lambda pi : pi.change_mode("pondering").look_at(real_deriv),
+ pi,
+ run_time = 2,
+ rate_func = squish_rate_func(smooth, a, a+0.5)
+ )
+ for pi in self.get_pi_creatures()
+ for a in [0.5*random.random()]
+ ])
+ self.dither(3)
- def show_df(self):
- sine_lines = self.sine_lines
- parabola_lines = self.parabola_lines
+ ###########
- df, equals, d_sine, plus, d_x_squared = deriv_mob = TexMobject(
- "df", "=", "d(\\sin(x))", "+", "d(x^2)"
- )
- df.highlight(SUM_COLOR)
- d_sine.highlight(SINE_COLOR)
- d_x_squared.highlight(X_SQUARED_COLOR)
- deriv_mob.scale(self.tex_scale_factor)
- deriv_mob.next_to(
- self.func_mob, DOWN,
- buff = MED_LARGE_BUFF,
- aligned_edge = LEFT
- )
- for submob in deriv_mob:
- submob.add_to_back(BackgroundRectangle(submob))
+ def create_pi_creatures(self):
+ width, height = self.pi_creature_grid_dimensions
+ creature_array = VGroup(*[
+ VGroup(*[
+ PiCreature(mode = "plain")
+ for y in range(height)
+ ]).arrange_submobjects(UP, buff = MED_LARGE_BUFF)
+ for x in range(width)
+ ]).arrange_submobjects(RIGHT, buff = MED_LARGE_BUFF)
+ creatures = VGroup(*it.chain(*creature_array))
+ creatures.scale_to_fit_height(self.pi_creature_grid_height)
+ creatures.to_corner(DOWN+RIGHT)
+
+ colors = color_gradient([BLUE, GREEN, GREY_BROWN], len(creatures))
+ random.shuffle(colors)
+ for creature, color in zip(creatures, colors):
+ creature.set_color(color)
+
+ return creatures
+
+ def reset(self):
+ time = self.t_expression[-1]
+ faders = [time] + list(self.get_on_screen_pi_creatures())
+ new_time = TexMobject("0")
+ new_time.next_to(self.t_expression[-2], RIGHT)
+ first_creature = self.get_pi_creatures()[0]
+
+ self.play(*map(FadeOut, faders))
+ self.play(*map(FadeIn, [first_creature, new_time]))
+ self.t_expression.submobjects[-1] = new_time
+
+ def let_one_day_pass(self, run_time = 2):
+ all_creatures = self.get_pi_creatures()
+ on_screen_creatures = self.get_on_screen_pi_creatures()
+ low_i = len(on_screen_creatures)
+ high_i = min(2*low_i, len(all_creatures))
+ new_creatures = VGroup(*all_creatures[low_i:high_i])
+
+ to_children_anims = []
+ growing_anims = []
+ for old_pi, pi in zip(on_screen_creatures, new_creatures):
+ pi.save_state()
+ child = pi.copy()
+ child.scale(0.25, about_point = child.get_bottom())
+ child.eyes.scale(1.5, about_point = child.eyes.get_bottom())
+ pi.move_to(old_pi)
+ pi.set_fill(opacity = 0)
+
+ index = list(new_creatures).index(pi)
+ prop = float(index)/len(new_creatures)
+ alpha = np.clip(len(new_creatures)/8.0, 0, 0.5)
+ rate_func = squish_rate_func(
+ smooth, alpha*prop, alpha*prop+(1-alpha)
+ )
- df_lines = self.show_difference(parabola_lines, df, equals)
- self.dither()
- self.play(FadeOut(df_lines))
- self.play(
- parabola_lines[0].shift,
- (parabola_lines[1].get_bottom()[1]-parabola_lines[0].get_bottom()[1])*UP,
- parabola_lines[0].brace_anim
- )
- d_sine_lines = self.show_difference(sine_lines, d_sine, plus)
- d_x_squared_lines = self.show_difference(parabola_lines, d_x_squared, VGroup())
- self.dither()
+ to_child_anim = Transform(pi, child, rate_func = rate_func)
+ to_child_anim.update(1)
+ growing_anim = ApplyMethod(pi.restore, rate_func = rate_func)
+ to_child_anim.update(0)
- self.deriv_mob = deriv_mob
- self.d_sine_lines = d_sine_lines
- self.d_x_squared_lines = d_x_squared_lines
+ to_children_anims.append(to_child_anim)
+ growing_anims.append(growing_anim)
- def show_difference(self, v_lines, target_tex, added_tex):
- distance = v_lines[1].get_top()[1]-v_lines[0].get_top()[1]
- h_lines = VGroup(*[
- DashedLine(ORIGIN, 2*RIGHT, stroke_width = 3)
- for x in range(2)
- ])
- h_lines.arrange_submobjects(DOWN, buff = distance)
- h_lines.move_to(v_lines[1].get_top(), UP+RIGHT)
+ time = self.t_expression[-1]
+ total_new_creatures = len(on_screen_creatures) + len(new_creatures)
+ new_time = TexMobject(str(int(np.log2(total_new_creatures))))
+ new_time.move_to(time, LEFT)
- brace = Brace(h_lines, LEFT)
- brace_text = target_tex.copy()
- brace_text.next_to(brace, LEFT)
+ growing_anims.append(Transform(time, new_time))
- self.play(ShowCreation(h_lines))
- self.play(GrowFromCenter(brace), Write(brace_text))
- self.dither()
- self.play(
- ReplacementTransform(brace_text.copy(), target_tex),
- Write(added_tex)
- )
- return VGroup(h_lines, brace, brace_text)
+ self.play(*to_children_anims, run_time = run_time/2.0)
+ self.play(*growing_anims, run_time = run_time/2.0)
+
+ def get_num_pi_creatures_on_screen(self):
+ mobjects = self.get_mobjects()
+ return sum([
+ pi in mobjects for pi in self.get_pi_creatures()
+ ])
- def expand_derivative(self):
- expanded_deriv = TexMobject(
- "df", "=", "\\cos(x)", "\\,dx", "+", "2x", "\\,dx"
- )
- expanded_deriv.highlight_by_tex("df", SUM_COLOR)
- VGroup(*expanded_deriv[2:4]).highlight(SINE_COLOR)
- VGroup(*expanded_deriv[5:7]).highlight(X_SQUARED_COLOR)
- expanded_deriv.scale(self.tex_scale_factor)
- expanded_deriv.next_to(
- self.deriv_mob, DOWN,
+ def get_population_size_descriptor(self):
+ on_screen_creatures = self.get_on_screen_pi_creatures()
+ brace = Brace(on_screen_creatures, LEFT)
+ n = len(on_screen_creatures)
+ label = brace.get_text(
+ "$2^%d$"%int(np.log2(n)),
+ "$=%d$"%n,
+ )
+ brace.add(label)
+ return brace
+
+ def get_num_days(self):
+ x, y = self.pi_creature_grid_dimensions
+ return int(np.log2(x*y))
+
+ def get_curr_day(self):
+ return int(np.log2(len(self.get_on_screen_pi_creatures())))
+
+ def get_from_day_to_day_label(self):
+ curr_day = self.get_curr_day()
+ top_words = TextMobject(
+ "From day", str(curr_day),
+ "to", str(curr_day+1), ":"
+ )
+ top_words.scale_to_fit_width(4)
+ top_words.next_to(
+ self.function, DOWN,
buff = MED_LARGE_BUFF,
- aligned_edge = LEFT
+ aligned_edge = LEFT,
)
- background_rect = BackgroundRectangle(expanded_deriv)
+ top_words[1].highlight(GREEN)
- rearranged_deriv = TexMobject(
- "{df \\over", "dx}", "=", "\\cos(x)", "+", "2x"
+ bottom_words = TexMobject(
+ str(2**curr_day),
+ "\\text{ creatures}", "\\over {1 \\text{ day}}"
)
- rearranged_deriv[0].highlight(SUM_COLOR)
- rearranged_deriv[3].highlight(SINE_COLOR)
- rearranged_deriv[5].highlight(X_SQUARED_COLOR)
- rearranged_deriv.scale(self.tex_scale_factor)
- rearranged_deriv.move_to(expanded_deriv, UP+LEFT)
- deriv_target_indices = [0, 2, 3, 1, 4, 5, 1]
+ bottom_words[0].highlight(GREEN)
+ bottom_words.next_to(top_words, DOWN, buff = MED_LARGE_BUFF)
+ return top_words, bottom_words
+
+class GraphOfTwoToT(GraphScene):
+ CONFIG = {
+ "x_axis_label" : "$t$",
+ "y_axis_label" : "$M$",
+ "x_labeled_nums" : range(1, 7),
+ "y_labeled_nums" : range(8, 40, 8),
+ "x_max" : 6,
+ "y_min" : 0,
+ "y_max" : 32,
+ "y_tick_frequency" : 2,
+ "graph_origin" : 2.5*DOWN + 5*LEFT,
+ }
+ def construct(self):
+ self.setup_axes()
+ example_t = 3
+ graph = self.get_graph(lambda t : 2**t, color = BLUE_C)
+ self.graph = graph
+ graph_label = self.get_graph_label(
+ graph, "M(t) = 2^t",
+ direction = LEFT,
+ )
+ label_group = self.get_label_group(example_t)
+ v_line, brace, height_label, ss_group, slope_label = label_group
+ self.animate_secant_slope_group_change(
+ ss_group,
+ target_dx = 1,
+ run_time = 0
+ )
+ self.remove(ss_group)
+
+ #Draw graph and revert to tangent
+ self.play(ShowCreation(graph))
+ self.play(Write(graph_label))
+ self.dither()
+ self.play(Write(ss_group))
+ self.dither()
+ for target_dx in 0.01, 1, 0.01:
+ self.animate_secant_slope_group_change(
+ ss_group,
+ target_dx = target_dx
+ )
+ self.dither()
+
+ #Mark up with values
+
+ self.play(ShowCreation(v_line))
+ self.play(
+ GrowFromCenter(brace),
+ Write(height_label, run_time = 1)
+ )
+ self.dither()
self.play(
FadeIn(
- background_rect,
- rate_func = squish_rate_func(smooth, 0.6, 1)
+ slope_label,
+ run_time = 4,
+ submobject_mode = "lagged_start"
),
- Write(expanded_deriv)
+ ReplacementTransform(
+ height_label.copy(),
+ slope_label.get_part_by_tex("2^")
+ )
)
self.dither()
- tex_group_pairs = [
- ("\\cos(0.5)dx", self.d_sine_lines),
- ("2(0.5)dx", self.d_x_squared_lines),
- ]
- def indicate(mob):
- self.play(
- mob.highlight, YELLOW,
- mob.scale_in_place, 1.2,
- rate_func = there_and_back
- )
- for tex, group in tex_group_pairs:
- old_label = group[-1]
- new_label = TexMobject(tex)
- pre_dx = VGroup(*new_label[:-2])
- dx = VGroup(*new_label[-2:])
- new_label.add_background_rectangle()
- new_label.scale(self.tex_scale_factor)
- new_label.move_to(old_label, RIGHT)
- new_label.highlight(old_label.get_color())
-
- self.play(FocusOn(old_label))
- indicate(old_label)
- self.dither()
- self.play(FadeOut(old_label))
- self.play(FadeIn(new_label))
- self.dither()
- indicate(dx)
- self.dither()
- indicate(pre_dx)
- self.dither()
- self.dither()
- self.play(*[
- Transform(
- expanded_deriv[i], rearranged_deriv[j],
- path_arc = -np.pi/2
- )
- for i, j in enumerate(deriv_target_indices)
+ #Vary value
+ threes = VGroup(height_label[1], slope_label[2][1])
+ ts = VGroup(*[
+ TexMobject("t").highlight(YELLOW).scale(0.75).move_to(three)
+ for three in threes
])
- self.dither()
+ self.play(Transform(threes, ts))
+
+ alt_example_t = example_t+1
+ def update_label_group(group, alpha):
+ t = interpolate(example_t, alt_example_t, alpha)
+ new_group = self.get_label_group(t)
+ Transform(group, new_group).update(1)
+ for t, three in zip(ts, threes):
+ t.move_to(three)
+ Transform(threes, ts).update(1)
+ return group
-class DiscussProducts(TeacherStudentsScene):
- def construct(self):
- wrong_product_rule = TexMobject(
- "\\frac{d(\\sin(x)x^2)}{dx}",
- "\\ne",
- "\\left(\\frac{d(\\sin(x))}{dx}\\right)",
- "\\left(\\frac{d(x^2)}{dx}\\right)",
- )
- not_equals = wrong_product_rule[1]
- wrong_product_rule[2].highlight(SINE_COLOR)
- wrong_product_rule[3].highlight(X_SQUARED_COLOR)
- wrong_product_rule.next_to(
- self.get_teacher().get_corner(UP+LEFT),
- UP,
- buff = MED_LARGE_BUFF
- ).shift_onto_screen()
+ self.play(UpdateFromAlphaFunc(
+ label_group, update_label_group,
+ run_time = 3,
+ ))
+ self.play(UpdateFromAlphaFunc(
+ label_group, update_label_group,
+ run_time = 3,
+ rate_func = lambda t : 1 - 1.5*smooth(t)
+ ))
- self.teacher_says(
- "Products are a bit different",
- target_mode = "sassy"
+ def get_label_group(self, t):
+ graph = self.graph
+
+ v_line = self.get_vertical_line_to_graph(
+ t, graph,
+ color = YELLOW,
)
- self.dither(2)
- self.play(RemovePiCreatureBubble(
- self.get_teacher(),
- target_mode = "raise_right_hand"
- ))
- self.play(Write(wrong_product_rule))
- self.change_student_modes(
- "pondering", "confused", "erm",
- added_anims = [
- not_equals.scale_in_place, 1.3,
- not_equals.highlight, RED
- ]
+ brace = Brace(v_line, RIGHT)
+ height_label = brace.get_text("$2^%d$"%t)
+
+ ss_group = self.get_secant_slope_group(
+ t, graph, dx = 0.01,
+ df_label = "dM",
+ dx_label = "dt",
+ dx_line_color = GREEN,
+ secant_line_color = RED,
)
- self.dither()
- self.teacher_says(
- "Think about the \\\\ underlying meaning",
- bubble_kwargs = {"height" : 3},
- added_anims = [
- wrong_product_rule.scale, 0.7,
- wrong_product_rule.to_corner, UP+LEFT
- ]
+ slope_label = TexMobject(
+ "\\text{Slope}", "=",
+ "2^%d"%t,
+ "(%.7f\\dots)"%np.log(2)
+ )
+ slope_label.next_to(
+ ss_group.secant_line.point_from_proportion(0.65),
+ DOWN+RIGHT,
+ buff = 0
+ )
+ slope_label.highlight_by_tex("Slope", RED)
+ return VGroup(
+ v_line, brace, height_label,
+ ss_group, slope_label
)
- self.change_student_modes(*["pondering"]*3)
- self.dither(2)
-class NotGraphsForProducts(GraphScene):
+class SimpleGraphOfTwoToT(GraphOfTwoToT):
CONFIG = {
- "y_max" : 25,
- "x_max" : 7,
+ "x_axis_label" : "",
+ "y_axis_label" : "",
}
def construct(self):
self.setup_axes()
- sine_graph = self.get_graph(np.sin, color = SINE_COLOR)
- sine_graph.label = self.get_graph_label(
- sine_graph, "\\sin(x)",
- x_val = 3*np.pi/2,
- direction = DOWN
- )
- parabola = self.get_graph(
- lambda x : x**2, color = X_SQUARED_COLOR
- )
- parabola.label = self.get_graph_label(
- parabola, "x^2",
- x_val = 2.5,
- direction = UP+LEFT,
- )
- product_graph = self.get_graph(
- lambda x : np.sin(x)*(x**2), color = PRODUCT_COLOR
- )
- product_graph.label = self.get_graph_label(
- product_graph, "\\sin(x)x^2",
- x_val = 2.8,
- direction = UP+RIGHT,
- buff = 0
- )
+ func = lambda t : 2**t
+ graph = self.get_graph(func)
+ line_pairs = VGroup()
+ for x in 1, 2, 3, 4, 5:
+ point = self.coords_to_point(x, func(x))
+ x_axis_point = self.coords_to_point(x, 0)
+ y_axis_point = self.coords_to_point(0, func(x))
+ line_pairs.add(VGroup(
+ DashedLine(x_axis_point, point),
+ DashedLine(y_axis_point, point),
+ ))
- graphs = [sine_graph, parabola, product_graph]
- for graph in graphs:
- self.play(
- ShowCreation(graph),
- Write(graph.label, run_time = 2)
- )
- self.dither()
- everything = VGroup(*filter(
- lambda m : not m.is_subpath,
- self.get_mobjects()
- ))
- words = TextMobject("Not the best visualization")
- words.scale(1.5)
- words.shift(SPACE_HEIGHT*UP/2)
- words.add_background_rectangle()
- words.highlight(RED)
- self.play(
- everything.fade,
- Write(words)
- )
+ self.play(ShowCreation(graph, run_time = 2))
+ for pair in line_pairs:
+ self.play(ShowCreation(pair))
self.dither()
-class ConfusedMorty(Scene):
- def construct(self):
- morty = Mortimer()
- self.add(morty)
- self.dither()
- self.play(morty.change_mode, "confused")
- self.play(Blink(morty))
- self.dither(2)
-
-class IntroduceProductAsArea(ReconfigurableScene):
+class AnalyzeExponentRatio(PiCreatureScene):
CONFIG = {
- "top_func" : np.sin,
- "top_func_label" : "\\sin(x)",
- "top_func_nudge_label" : "d(\\sin(x))",
- "top_func_derivative" : "\\cos(x)",
- "side_func" : lambda x : x**2,
- "side_func_label" : "x^2",
- "side_func_nudge_label" : "d(x^2)",
- "side_func_derivative" : "2x",
- "x_unit_to_space_unit" : 3,
- "box_kwargs" : {
- "fill_color" : YELLOW,
- "fill_opacity" : 0.75,
- "stroke_width" : 1,
- },
- "df_box_kwargs" : {
- "fill_color" : GREEN,
- "fill_opacity" : 0.75,
- "stroke_width" : 0,
- },
- "box_corner_location" : 6*LEFT+2.5*UP,
- "slider_center" : 3.5*RIGHT+2*DOWN,
- "slider_width" : 6,
- "slider_x_max" : 3,
- "x_slider_handle_height" : 0.25,
- "slider_handle_color" : BLUE,
- "default_x" : .75,
- "dx" : 0.1,
- "tiny_dx" : 0.01,
+ "base" : 2,
+ "base_str" : "2",
}
def construct(self):
- self.introduce_box()
- self.talk_though_sine()
- self.define_f_of_x()
- self.nudge_x()
- self.write_df()
- self.show_thinner_dx()
- self.expand_derivative()
- self.write_derivative_abstractly()
- self.write_mneumonic()
-
- def introduce_box(self):
- box, labels = self.box_label_group = self.get_box_label_group(self.default_x)
- self.x_slider = self.get_x_slider(self.default_x)
-
- self.play(Write(labels))
- self.play(DrawBorderThenFill(box))
- self.dither()
- for mob in self.x_slider:
- self.play(Write(mob, run_time = 1))
- self.dither()
- for new_x in 0.5, 2, self.default_x:
- self.animate_x_change(
- new_x, run_time = 2
- )
- self.dither()
+ base_str = self.base_str
- def talk_though_sine(self):
- x_axis = self.x_slider[0]
- graph = FunctionGraph(
- np.sin, x_min = 0, x_max = np.pi,
- color = SINE_COLOR
- )
- scale_factor = self.x_slider.get_width()/self.slider_x_max
- graph.scale(scale_factor)
- graph.move_to(x_axis.number_to_point(0), DOWN+LEFT)
+ func_def = TexMobject("M(", "t", ")", "= ", "%s^"%base_str, "t")
+ func_def.to_corner(UP+LEFT)
+ self.add(func_def)
- label = TexMobject("\\sin(x)")
- label.highlight(SINE_COLOR)
- label.next_to(graph, UP)
+ ratio = TexMobject(
+ "{ {%s^"%base_str, "{t", "+", "dt}", "-",
+ "%s^"%base_str, "t}",
+ "\\over \\,", "dt}"
+ )
+ ratio.shift(UP+LEFT)
- y_axis = x_axis.copy()
- y_axis.remove(*y_axis.numbers)
+ lhs = TexMobject("{dM", "\\over \\,", "dt}", "(", "t", ")", "=")
+ lhs.next_to(ratio, LEFT)
- v_line = Line(ORIGIN, UP, color = WHITE, stroke_width = 2)
- def v_line_update(v_line):
- x = x_axis.point_to_number(self.x_slider[1].get_top())
- v_line.scale_to_fit_height(np.sin(x)*scale_factor)
- v_line.move_to(x_axis.number_to_point(x), DOWN)
- v_line_update(v_line)
- self.play(
- Rotate(y_axis, np.pi/2, about_point = y_axis.get_left()),
- Animation(x_axis)
- )
- self.play(
- ShowCreation(graph),
- Write(label, run_time = 1)
+ two_to_t_plus_dt = VGroup(*ratio[:4])
+ two_to_t = VGroup(*ratio[5:7])
+ two_to_t_two_to_dt = TexMobject(
+ "%s^"%base_str, "t",
+ "%s^"%base_str, "{dt}"
)
- self.play(ShowCreation(v_line))
- for x, rt in zip([0.25, np.pi/2, 3, self.default_x], [2, 4, 4, 2]):
- self.animate_x_change(
- x, run_time = rt,
- added_anims = [
- UpdateFromFunc(v_line, v_line_update)
- ]
- )
- self.dither()
- self.play(*it.chain(
- map(FadeOut, [y_axis, graph, label, v_line]),
- [Animation(x_axis)]
- ))
- self.dither()
- for x in 1, 0.5, self.default_x:
- self.animate_x_change(x)
- self.dither()
+ two_to_t_two_to_dt.move_to(two_to_t_plus_dt, DOWN+LEFT)
+ exp_prop_brace = Brace(two_to_t_two_to_dt, UP)
- def define_f_of_x(self):
- f_def = TexMobject(
- "f(x)", "=",
- self.top_func_label,
- self.side_func_label,
- "=",
- "\\text{Area}"
- )
- f_def.to_corner(UP+RIGHT)
- f_def[-1].highlight(self.box_kwargs["fill_color"])
+ one = TexMobject("1")
+ one.move_to(ratio[5], DOWN)
+ lp, rp = parens = TexMobject("()")
+ parens.stretch(1.3, 1)
+ parens.scale_to_fit_height(ratio.get_height())
+ lp.next_to(ratio, LEFT, buff = 0)
+ rp.next_to(ratio, RIGHT, buff = 0)
- box, labels = self.box_label_group
+ extracted_two_to_t = TexMobject("%s^"%base_str, "t")
+ extracted_two_to_t.next_to(lp, LEFT, buff = SMALL_BUFF)
- self.play(Write(VGroup(*f_def[:-1])))
- self.play(Transform(
- box.copy().set_fill(opacity = 0), f_def[-1],
- run_time = 1.5,
- ))
- self.dither()
+ expressions = [
+ ratio, two_to_t_two_to_dt,
+ extracted_two_to_t, lhs, func_def
+ ]
+ for expression in expressions:
+ expression.highlight_by_tex("t", YELLOW)
+ expression.highlight_by_tex("dt", GREEN)
- self.f_def = f_def
-
- def nudge_x(self):
- box, labels = self.box_label_group
- nudge_label_group = self.get_nudge_label_group()
- original_dx = self.dx
- self.dx = self.tiny_dx
- thin_df_boxes = self.get_df_boxes()
- self.dx = original_dx
- df_boxes = self.get_df_boxes()
- right_box, corner_box, right_box = df_boxes
-
- self.play(FocusOn(nudge_label_group))
- self.play(*map(GrowFromCenter, nudge_label_group))
- self.animate_x_change(
- self.default_x+self.dx,
- rate_func = there_and_back,
- run_time = 2,
- added_anims = [Animation(nudge_label_group)]
- )
- self.dither()
+ #Apply exponential property
self.play(
- ReplacementTransform(thin_df_boxes, df_boxes),
- VGroup(*labels[1]).shift, right_box.get_width()*RIGHT,
+ Write(ratio), Write(lhs),
+ self.pi_creature.change_mode, "raise_right_hand"
)
+ self.dither(2)
self.play(
- df_boxes.space_out_submobjects, 1.1,
- df_boxes.move_to, box, UP+LEFT,
+ two_to_t_plus_dt.next_to, exp_prop_brace, UP,
+ self.pi_creature.change_mode, "pondering"
)
- self.dither()
-
- self.df_boxes = df_boxes
- self.df_box_labels = self.get_df_box_labels(df_boxes)
- self.x_slider.add(nudge_label_group)
+ self.play(
+ ReplacementTransform(
+ two_to_t_plus_dt.copy(), two_to_t_two_to_dt,
+ run_time = 2,
+ path_arc = np.pi,
+ ),
+ FadeIn(exp_prop_brace)
+ )
+ self.dither(2)
- def get_nudge_label_group(self):
- line, triangle, x_mob = self.x_slider
- dx_line = Line(*[
- line.number_to_point(self.x_slider.x_val + num)
- for num in 0, self.dx,
- ])
- dx_line.set_stroke(
- self.df_box_kwargs["fill_color"],
- width = 6
- )
- brace = Brace(dx_line, UP, buff = SMALL_BUFF)
- brace.stretch_to_fit_height(0.2)
- brace.next_to(dx_line, UP, buff = SMALL_BUFF)
- brace.set_stroke(width = 1)
- dx = TexMobject("dx")
- dx.scale(0.7)
- dx.next_to(brace, UP, buff = SMALL_BUFF)
- dx.highlight(dx_line.get_color())
-
- return VGroup(dx_line, brace, dx)
-
- def get_df_boxes(self):
- box, labels = self.box_label_group
- alt_box = self.get_box(self.x_slider.x_val + self.dx)
-
- h, w = box.get_height(), box.get_width()
- dh, dw = alt_box.get_height()-h, alt_box.get_width()-w
- heights_and_widths = [(dh, w), (dh, dw), (h, dw)]
- vects = [DOWN, DOWN+RIGHT, RIGHT]
- df_boxes = VGroup(*[
+ #Talk about exponential property
+ add_exp_rect, mult_rect = rects = [
Rectangle(
- height = height, width = width, **self.df_box_kwargs
- ).next_to(box, vect, buff = 0)
- for (height, width), vect in zip(
- heights_and_widths, vects
- )
- ])
- return df_boxes
-
- def get_df_box_labels(self, df_boxes):
- bottom_box, corner_box, right_box = df_boxes
- result = VGroup()
- quads = [
- (right_box, UP, self.top_func_nudge_label, LEFT),
- (corner_box, RIGHT, self.side_func_nudge_label, ORIGIN),
+ stroke_color = BLUE,
+ stroke_width = 2,
+ ).replace(mob).scale_in_place(1.1)
+ for mob in [
+ VGroup(*two_to_t_plus_dt[1:]),
+ two_to_t_two_to_dt
+ ]
]
- for box, vect, label_tex, aligned_edge in quads:
- brace = Brace(box, vect)
- label = TexMobject(label_tex)
- label.next_to(
- brace, vect,
- aligned_edge = aligned_edge,
- buff = SMALL_BUFF
- )
- label.highlight(df_boxes[0].get_color())
- result.add(VGroup(brace, label))
- return result
-
- def write_df(self):
- deriv = TexMobject(
- "df", "=",
- self.top_func_label,
- self.side_func_nudge_label,
- "+",
- self.side_func_label,
- self.top_func_nudge_label,
- )
- deriv.scale(0.9)
- deriv.next_to(self.f_def, DOWN, buff = LARGE_BUFF)
- deriv.to_edge(RIGHT)
- for submob, tex in zip(deriv, deriv.expression_parts):
- if tex.startswith("d"):
- submob.highlight(self.df_box_kwargs["fill_color"])
- bottom_box_area = VGroup(*deriv[2:4])
- right_box_area = VGroup(*deriv[5:7])
-
- bottom_box, corner_box, right_box = self.df_boxes
- plus = TexMobject("+").set_fill(opacity = 0)
- df_boxes_copy = VGroup(
- bottom_box.copy(),
- plus,
- right_box.copy(),
- plus.copy(),
- corner_box.copy(),
- )
-
- self.deriv = deriv
- self.df_boxes_copy = df_boxes_copy
- box, labels = self.box_label_group
- self.full_box_parts = VGroup(*it.chain(
- [box], self.df_boxes, labels, self.df_box_labels
- ))
+ words = VGroup(*[
+ TextMobject(s, " ideas")
+ for s in "Additive", "Multiplicative"
+ ])
+ words[0].move_to(words[1], LEFT)
+ words.highlight(BLUE)
+ words.next_to(two_to_t_plus_dt, RIGHT, buff = 1.5*LARGE_BUFF)
+ arrows = VGroup(*[
+ Arrow(word.get_left(), rect, color = words.get_color())
+ for word, rect in zip(words, rects)
+ ])
- self.play(Write(VGroup(*deriv[:2])))
- self.play(
- df_boxes_copy.arrange_submobjects,
- df_boxes_copy.set_fill, None, self.df_box_kwargs["fill_opacity"],
- df_boxes_copy.next_to, deriv[1]
- )
- deriv.submobjects[4] = df_boxes_copy[1]
+ self.play(ShowCreation(add_exp_rect))
+ self.dither()
+ self.play(ReplacementTransform(
+ add_exp_rect.copy(), mult_rect
+ ))
+ self.dither()
+ self.change_mode("happy")
+ self.play(Write(words[0], run_time = 2))
+ self.play(ShowCreation(arrows[0]))
self.dither()
-
- self.highlight_right_boxes()
- self.highlight_bottom_boxes()
- self.describe_bottom_box(bottom_box_area)
- self.describe_right_box(right_box_area)
- self.ignore_corner()
-
- # self.add(deriv)
-
- def highlight_boxes_and_label(self, boxes, label):
- boxes.save_state()
- label.save_state()
-
- self.play(GrowFromCenter(label))
self.play(
- boxes.highlight, RED,
- label.highlight, RED,
+ Transform(*words),
+ Transform(*arrows),
)
+ self.dither(2)
+ self.play(*map(FadeOut, [
+ words[0], arrows[0], add_exp_rect, mult_rect,
+ two_to_t_plus_dt, exp_prop_brace,
+ ]))
+
+ #Factor out 2^t
+ self.play(*[
+ FadeIn(
+ mob,
+ run_time = 2,
+ rate_func = squish_rate_func(smooth, 0.5, 1)
+ )
+ for mob in one, lp, rp
+ ] + [
+ ReplacementTransform(
+ mob, extracted_two_to_t,
+ path_arc = np.pi/2,
+ run_time = 2,
+ )
+ for mob in two_to_t, VGroup(*two_to_t_two_to_dt[:2])
+ ] + [
+ lhs.next_to, extracted_two_to_t, LEFT
+ ])
+ self.change_mode("pondering")
+ shifter = VGroup(ratio[4], one, *two_to_t_two_to_dt[2:])
+ stretcher = VGroup(lp, ratio[7], rp)
self.play(
- label[1].scale_in_place, 1.1,
- rate_func = there_and_back
+ shifter.next_to, ratio[7], UP,
+ stretcher.stretch_in_place, 0.9, 0
)
- self.play(boxes.restore, label.restore)
- self.dither()
+ self.dither(2)
- def highlight_right_boxes(self):
- self.highlight_boxes_and_label(
- VGroup(*self.df_boxes[1:]),
- self.df_box_labels[0]
- )
+ #Ask about dt -> 0
+ brace = Brace(VGroup(extracted_two_to_t, ratio), DOWN)
+ alt_brace = Brace(parens, DOWN)
+ dt_to_zero = TexMobject("dt", "\\to 0")
+ dt_to_zero.highlight_by_tex("dt", GREEN)
+ dt_to_zero.next_to(brace, DOWN)
- def highlight_bottom_boxes(self):
- self.highlight_boxes_and_label(
- VGroup(*self.df_boxes[:-1]),
- self.df_box_labels[1]
- )
+ self.play(GrowFromCenter(brace))
+ self.play(Write(dt_to_zero))
+ self.dither(2)
- def describe_bottom_box(self, bottom_box_area):
- bottom_box = self.df_boxes[0]
- bottom_box_copy = self.df_boxes_copy[0]
- other_box_copies = VGroup(*self.df_boxes_copy[1:])
- top_label = self.box_label_group[1][0]
- right_label = self.df_box_labels[1]
+ #Who cares
+ randy = Randolph()
+ randy.scale(0.7)
+ randy.to_edge(DOWN)
- faders = VGroup(*filter(
- lambda m : m not in [bottom_box, top_label, right_label],
- self.full_box_parts
- ))
- faders.save_state()
-
- self.play(faders.fade, 0.8)
- self.dither()
- self.play(FocusOn(bottom_box_copy))
self.play(
- ReplacementTransform(bottom_box_copy, bottom_box_area),
- other_box_copies.next_to, bottom_box_area, RIGHT
+ FadeIn(randy),
+ self.pi_creature.change_mode, "plain",
)
- self.dither()
- self.play(faders.restore)
-
- def describe_right_box(self, right_box_area):
- right_box = self.df_boxes[2]
- right_box_copy = self.df_boxes_copy[2]
- right_box_area.next_to(self.df_boxes_copy[1])
- other_box_copies = VGroup(*self.df_boxes_copy[3:])
- top_label = self.df_box_labels[0]
- right_label = self.box_label_group[1][1]
-
- faders = VGroup(*filter(
- lambda m : m not in [right_box, top_label, right_label],
- self.full_box_parts
+ self.play(PiCreatureSays(
+ randy, "Who cares?",
+ bubble_kwargs = {"direction" : LEFT},
+ target_mode = "angry",
))
- faders.save_state()
-
- self.play(faders.fade, 0.8)
- self.dither()
- self.play(FocusOn(right_box_copy))
+ self.dither(2)
self.play(
- ReplacementTransform(right_box_copy, right_box_area),
- other_box_copies.next_to, right_box_area, DOWN,
- MED_SMALL_BUFF, RIGHT,
-
+ RemovePiCreatureBubble(randy),
+ FadeOut(randy),
+ self.pi_creature.change_mode, "hooray",
+ self.pi_creature.look_at, parens
)
- self.dither()
- self.play(faders.restore)
-
- def ignore_corner(self):
- corner = self.df_boxes[1]
- corner.save_state()
- corner_copy = VGroup(*self.df_boxes_copy[-2:])
- words = TextMobject("Ignore")
- words.highlight(RED)
- words.next_to(corner_copy, LEFT, buff = LARGE_BUFF)
- words.shift(MED_SMALL_BUFF*DOWN)
- arrow = Arrow(words, corner_copy, buff = SMALL_BUFF, color = RED)
-
self.play(
- corner.highlight, RED,
- corner_copy.highlight, RED,
+ Transform(brace, alt_brace),
+ dt_to_zero.next_to, alt_brace, DOWN
)
self.dither()
- self.play(Write(words), ShowCreation(arrow))
- self.dither()
- self.play(*map(FadeOut, [words, arrow, corner_copy]))
- self.dither()
- corner_copy.highlight(BLACK)
-
- def show_thinner_dx(self):
- self.transition_to_alt_config(dx = self.tiny_dx)
-
- def expand_derivative(self):
- # self.play(
- # self.deriv.next_to, self.f_def, DOWN, MED_LARGE_BUFF,
- # self.deriv.shift_onto_screen
- # )
- # self.dither()
-
- expanded_deriv = TexMobject(
- "df", "=",
- self.top_func_label,
- self.side_func_derivative,
- "\\,dx",
- "+",
- self.side_func_label,
- self.top_func_derivative,
- "\\,dx"
- )
- final_deriv = TexMobject(
- "{df \\over ", "dx}", "=",
- self.top_func_label,
- self.side_func_derivative,
- "+",
- self.side_func_label,
- self.top_func_derivative,
- )
- color = self.deriv[0].get_color()
- for new_deriv in expanded_deriv, final_deriv:
- for submob, tex in zip(new_deriv, new_deriv.expression_parts):
- for substr in "df", "dx", self.top_func_derivative, self.side_func_derivative:
- if substr in tex:
- submob.highlight(color)
- new_deriv.scale(0.9)
- new_deriv.next_to(self.deriv, DOWN, buff = MED_LARGE_BUFF)
- new_deriv.shift_onto_screen()
-
- def indicate(mob):
- self.play(
- mob.scale_in_place, 1.2,
- mob.highlight, YELLOW,
- rate_func = there_and_back
- )
-
-
- for index in 6, 3:
- self.deriv.submobjects.insert(
- index+1, self.deriv[index].copy()
- )
- non_deriv_indices = range(len(expanded_deriv))
- for indices in [(3, 4), (7, 8)]:
- top_part = VGroup()
- bottom_part = VGroup()
- for i in indices:
- non_deriv_indices.remove(i)
- top_part.add(self.deriv[i].copy())
- bottom_part.add(expanded_deriv[i])
- self.play(top_part.move_to, bottom_part)
- self.dither()
- indicate(top_part)
- self.dither()
- self.play(ReplacementTransform(top_part, bottom_part))
- self.dither()
- top_part = VGroup()
- bottom_part = VGroup()
- for i in non_deriv_indices:
- top_part.add(self.deriv[i].copy())
- bottom_part.add(expanded_deriv[i])
- self.play(ReplacementTransform(
- top_part, bottom_part
- ))
- self.dither()
- self.play(*[
- ReplacementTransform(
- expanded_deriv[i], final_deriv[j],
- path_arc = -np.pi/2
- )
- for i, j in [
- (0, 0),
- (1, 2),
- (2, 3),
- (3, 4),
- (4, 1),
- (5, 5),
- (6, 6),
- (7, 7),
- (8, 1),
+ #Highlight separation
+ rects = [
+ Rectangle(
+ stroke_color = color,
+ stroke_width = 2,
+ ).replace(mob, stretch = True).scale_in_place(1.1)
+ for mob, color in [
+ (VGroup(parens, dt_to_zero), GREEN),
+ (extracted_two_to_t, YELLOW),
]
- ])
- self.dither()
- for index in 0, 1, 3, 4, 6, 7:
- indicate(final_deriv[index])
+ ]
+ self.play(ShowCreation(rects[0]))
+ self.dither(2)
+ self.play(ReplacementTransform(rects[0].copy(), rects[1]))
+ self.change_mode("happy")
self.dither()
+ self.play(*map(FadeOut, rects))
- def write_derivative_abstractly(self):
- self.transition_to_alt_config(
- return_to_original_configuration = False,
- top_func_label = "g(x)",
- top_func_nudge_label = "dg",
- top_func_derivative = "\\frac{dg}{dx}",
- side_func_label = "h(x)",
- side_func_nudge_label = "dh",
- side_func_derivative = "\\frac{dh}{dx}",
- )
- self.dither()
+ #Plug in specific values
+ static_constant = self.try_specific_dt_values()
+ constant = static_constant.copy()
- def write_mneumonic(self):
- morty = Mortimer()
- morty.scale(0.7)
- morty.to_edge(DOWN)
- morty.shift(2*LEFT)
- words = TextMobject(
- "``Left ", "d(Right) ", "+", " Right ", "d(Left)", "''",
- arg_separator = ""
- )
- VGroup(words[1], words[4]).highlight(self.df_boxes[0].get_color())
- words.scale(0.7)
- words.next_to(morty.get_corner(UP+LEFT), UP)
- words.shift_onto_screen()
-
- self.play(FadeIn(morty))
+ #Replace with actual constant
+ limit_term = VGroup(
+ brace, dt_to_zero, ratio[4], one, rects[0],
+ *ratio[7:]+two_to_t_two_to_dt[2:]
+ )
+ self.play(FadeIn(rects[0]))
+ self.play(limit_term.to_corner, DOWN+LEFT)
self.play(
- morty.change_mode, "raise_right_hand",
- Write(words)
+ lp.stretch, 0.5, 1,
+ lp.stretch, 0.8, 0,
+ lp.next_to, extracted_two_to_t[0], RIGHT,
+ rp.stretch, 0.5, 1,
+ rp.stretch, 0.8, 0,
+ rp.next_to, lp, RIGHT, SMALL_BUFF,
+ rp.shift, constant.get_width()*RIGHT,
+ constant.next_to, extracted_two_to_t[0], RIGHT, MED_LARGE_BUFF
)
self.dither()
-
- ###############
-
- def animate_x_change(
- self, target_x,
- box_label_group = None,
- x_slider = None,
- **kwargs
- ):
- box_label_group = box_label_group or self.box_label_group
- x_slider = x_slider or self.x_slider
- kwargs["run_time"] = kwargs.get("run_time", 2)
- added_anims = kwargs.get("added_anims", [])
-
- start_x = x_slider.x_val
- def update_box_label_group(box_label_group, alpha):
- new_x = interpolate(start_x, target_x, alpha)
- new_box_label_group = self.get_box_label_group(new_x)
- Transform(box_label_group, new_box_label_group).update(1)
-
- def update_x_slider(x_slider, alpha):
- new_x = interpolate(start_x, target_x, alpha)
- new_x_slider = self.get_x_slider(new_x)
- Transform(x_slider, new_x_slider).update(1)
-
- self.play(
- UpdateFromAlphaFunc(
- box_label_group,
- update_box_label_group
- ),
- UpdateFromAlphaFunc(
- x_slider,
- update_x_slider
- ),
- *added_anims,
- **kwargs
- )
- x_slider.x_val = target_x
-
- def get_x_slider(self, x):
- numbers = range(int(self.slider_x_max) + 1)
- line = NumberLine(
- x_min = 0,
- x_max = self.slider_x_max,
- space_unit_to_num = float(self.slider_width)/self.slider_x_max,
- color = GREY,
- numbers_with_elongated_ticks = numbers,
- tick_frequency = 0.25,
- )
- line.add_numbers(*numbers)
- line.numbers.next_to(line, UP, buff = SMALL_BUFF)
- for number in line.numbers:
- number.add_background_rectangle()
- line.move_to(self.slider_center)
-
- triangle = RegularPolygon(
- 3, start_angle = np.pi/2,
- fill_color = self.slider_handle_color,
- fill_opacity = 0.8,
- stroke_width = 0,
- )
- triangle.scale_to_fit_height(self.x_slider_handle_height)
- triangle.move_to(line.number_to_point(x), UP)
-
- x_mob = TexMobject("x")
- x_mob.next_to(triangle, DOWN, buff = SMALL_BUFF)
-
- result = VGroup(line, triangle, x_mob)
- result.x_val = x
- return result
-
- def get_box_label_group(self, x):
- box = self.get_box(x)
- labels = self.get_box_labels(box)
- return VGroup(box, labels)
-
- def get_box(self, x):
- box = Rectangle(
- width = self.x_unit_to_space_unit * self.top_func(x),
- height = self.x_unit_to_space_unit * self.side_func(x),
- **self.box_kwargs
- )
- box.move_to(self.box_corner_location, UP+LEFT)
- return box
-
- def get_box_labels(self, box):
- result = VGroup()
- for label_tex, vect in (self.top_func_label, UP), (self.side_func_label, RIGHT):
- brace = Brace(box, vect, min_num_quads = 5)
- label = TexMobject(label_tex)
- label.next_to(brace, vect, buff = SMALL_BUFF)
- result.add(VGroup(brace, label))
- return result
-
-class WriteDXSquared(Scene):
- def construct(self):
- term = TexMobject("(...)(dx)^2")
- term.highlight(RED)
- self.play(Write(term))
+ self.change_mode("confused")
self.dither()
-class MneumonicExample(TeacherStudentsScene):
- def construct(self):
- d, left, right, rp = deriv_q = TexMobject(
- "\\frac{d}{dx}(", "\\sin(x)", "x^2", ")"
- )
- deriv_q.to_edge(UP)
-
- words = TextMobject(
- "Left ", "d(Right) ", "+", " Right ", "d(Left)",
- arg_separator = ""
- )
- deriv = TexMobject("\\sin(x)", "2x", "+", "x^2", "\\cos(x)")
- for mob in words, deriv:
- VGroup(mob[1], mob[4]).highlight(GREEN)
- mob.next_to(deriv_q, DOWN, buff = MED_LARGE_BUFF)
- deriv.shift(words[2].get_center()-deriv[2].get_center())
+ #Indicate distinction between dt group and t group again
+ for mob in limit_term, extracted_two_to_t:
+ self.play(FocusOn(mob))
+ self.play(Indicate(mob))
+ self.dither()
- self.add(words)
- self.play(
- Write(deriv_q),
- self.get_teacher().change_mode, "raise_right_hand"
+ #hold_final_value
+ derivative = VGroup(
+ lhs, extracted_two_to_t, parens, constant
)
- self.change_student_modes(*["pondering"]*3)
+ func_def_rhs = VGroup(*func_def[-2:]).copy()
+ func_lp, func_rp = func_parens = TexMobject("()")
+ func_parens.set_fill(opacity = 0)
+ func_lp.next_to(func_def_rhs[0], LEFT, buff = 0)
+ func_rp.next_to(func_lp, RIGHT, buff = func_def_rhs.get_width())
+ func_def_rhs.add(func_parens)
+ M = lhs[0][1]
- left_words = VGroup(*words[:2])
- left_terms = VGroup(*deriv[:2])
self.play(
- left_words.next_to, left_terms, DOWN,
- MED_LARGE_BUFF, RIGHT
+ FadeOut(M),
+ func_def_rhs.move_to, M, LEFT,
+ func_def_rhs.set_fill, None, 1,
)
- self.play(ReplacementTransform(
- left_words.copy(), left_terms
- ))
- self.dither()
- self.play(*map(Indicate, [left, left_words[0], left_terms[0]]))
+ lhs[0].submobjects[1] = func_def_rhs
self.dither()
- self.play(*map(Indicate, [right, left_words[1], left_terms[1]]))
- self.dither()
-
- right_words = VGroup(*words[2:])
- right_terms = VGroup(*deriv[2:])
self.play(
- right_words.next_to, right_terms, DOWN,
- MED_LARGE_BUFF, LEFT
+ derivative.next_to, self.pi_creature, UP,
+ derivative.to_edge, RIGHT,
+ self.pi_creature.change_mode, "raise_right_hand"
)
- self.play(ReplacementTransform(
- right_words.copy(), right_terms
- ))
- self.dither()
- self.play(*map(Indicate, [right, right_words[1], right_terms[1]]))
- self.dither()
- self.play(*map(Indicate, [left, right_words[2], right_terms[2]]))
- self.dither(3)
+ self.dither(2)
+ for mob in extracted_two_to_t, constant:
+ self.play(Indicate(mob))
+ self.dither()
+ self.dither(2)
- self.play(self.get_teacher().change_mode, "shruggie")
- self.dither()
- self.change_student_modes(*["confused"]*3)
- self.dither(3)
+ def try_specific_dt_values(self):
+ expressions = []
+ for num_zeros in [1, 2, 4, 7]:
+ dt_str = "0." + num_zeros*"0" + "1"
+ dt_num = float(dt_str)
+ output_num = (self.base**dt_num - 1) / dt_num
+ output_str = "%.7f\\dots"%output_num
+
+ expression = TexMobject(
+ "{%s^"%self.base_str, "{%s}"%dt_str, "-1",
+ "\\over \\,", "%s}"%dt_str,
+ "=", output_str
+ )
+ expression.highlight_by_tex(dt_str, GREEN)
+ expression.highlight_by_tex(output_str, BLUE)
+ expression.to_corner(UP+RIGHT)
+ expressions.append(expression)
-class ConstantMultiplication(TeacherStudentsScene):
- def construct(self):
- question = TextMobject("What about $\\dfrac{d}{dx}(2\\sin(x))$?")
- answer = TextMobject("2\\cos(x)")
- self.teacher_says(question)
- self.dither()
- self.student_says(
- answer, target_mode = "hooray",
- added_anims = [question.copy().to_edge, UP]
+ curr_expression = expressions[0]
+ self.play(
+ Write(curr_expression),
+ self.pi_creature.change_mode, "pondering"
)
- self.play(self.get_teacher().change_mode, "happy")
- self.change_student_modes("pondering", "hooray", "pondering")
- self.dither(3)
+ self.dither(2)
+ for expression in expressions[1:]:
+ self.play(Transform(curr_expression, expression))
+ self.dither(2)
+ return curr_expression[-1]
-class ConstantMultiplicationFigure(IntroduceProductAsArea):
+class ExponentRatioWithThree(AnalyzeExponentRatio):
CONFIG = {
- "side_func" : lambda x : 1,
- "side_func_label" : "\\text{Constant}",
- "side_func_nudge_label" : "",
- "side_func_derivative" : "",
- "x_unit_to_space_unit" : 3,
- "default_x" : 0.5,
- "dx" : 0.1
+ "base" : 3,
+ "base_str" : "3",
}
- def construct(self):
- self.box_label_group = self.get_box_label_group(self.default_x)
- self.x_slider = self.get_x_slider(self.default_x)
- # df_boxes = self.get_df_boxes()
- # df_box_labels = self.get_df_box_labels(df_boxes)
-
- self.add(self.box_label_group, self.x_slider)
- self.nudge_x()
-
-class ShoveXSquaredInSine(Scene):
- def construct(self):
- title = TextMobject("Function composition")
- title.to_edge(UP)
-
- sine = TexMobject("g(", "x", ")", "=", "\\sin(", "x", ")")
- sine.highlight(SINE_COLOR)
- x_squared = TexMobject("h(x)", "=", "x^2")
- x_squared.highlight(X_SQUARED_COLOR)
- group = VGroup(sine, x_squared)
- group.arrange_submobjects(buff = LARGE_BUFF)
- group.shift(UP)
- composition = TexMobject(
- "g(", "h(x)", ")", "=", "\\sin(", "x^2", ")"
- )
- for i in 0, 2, 4, 6:
- composition[i].highlight(SINE_COLOR)
- for i in 1, 5:
- composition[i].highlight(X_SQUARED_COLOR)
- composition.next_to(group, DOWN, buff = LARGE_BUFF)
-
- brace = Brace(VGroup(*composition[-3:]), DOWN)
- deriv_q = brace.get_text("Derivative?")
-
- self.add(group)
- self.play(Write(title))
- self.dither()
- triplets = [
- [sine, (0, 2), (0, 2)],
- [x_squared, (0,), (1,)],
- [sine, (3, 4, 6), (3, 4, 6)],
- [x_squared, (2,), (5,)]
- ]
- for premob, pre_indices, comp_indicies in triplets:
- self.play(*[
- ReplacementTransform(
- premob[i].copy(), composition[j]
- )
- for i, j in zip(pre_indices, comp_indicies)
- ])
- self.dither()
- self.dither()
- self.play(
- GrowFromCenter(brace),
- Write(deriv_q)
- )
- self.dither()
-class ThreeLinesChainRule(ReconfigurableScene):
+class ExponentRatioWithSeven(AnalyzeExponentRatio):
CONFIG = {
- "start_x" : 0.5,
- "top_x" : 3,
- "example_x" : 1.5,
- "dx" : 0.1,
- "line_configs" : [
- {
- "func" : lambda x : x,
- "func_label" : "x",
- "triangle_color" : WHITE,
- "center_y" : 3,
- "x_min" : 0,
- "x_max" : 3,
- "numbers_to_show" : range(4),
- "numbers_with_elongated_ticks" : range(4),
- "tick_frequency" : 0.25,
- },
- {
- "func" : lambda x : x**2,
- "func_label" : "x^2",
- "triangle_color" : X_SQUARED_COLOR,
- "center_y" : 0.5,
- "x_min" : 0,
- "x_max" : 10,
- "numbers_to_show" : range(0, 11),
- "numbers_with_elongated_ticks" : range(0, 11, 1),
- "tick_frequency" : 0.25,
- },
- {
- "func" : lambda x : np.sin(x**2),
- "func_label" : "\\sin(x^2)",
- "triangle_color" : SINE_COLOR,
- "center_y" : -2,
- "x_min" : -2,
- "x_max" : 2,
- "numbers_to_show" : range(-2, 3),
- "numbers_with_elongated_ticks" : range(-2, 3),
- "tick_frequency" : 0.25,
- },
- ],
- "line_width" : 8,
- "triangle_height" : 0.25,
+ "base" : 7,
+ "base_str" : "7",
}
- def construct(self):
- self.introduce_line_group()
- self.draw_function_arrows()
- self.talk_through_movement()
- self.nudge_x()
- self.give_example_of_meaning()
-
- def introduce_line_group(self):
- self.line_group = self.get_line_group(self.start_x)
- lines, labels = self.line_group
-
- for line in lines:
- self.play(Write(line, run_time = 2))
- self.dither()
- last_label = labels[0].copy()
- last_label.to_corner(UP+LEFT)
- last_label.set_fill(opacity = 0)
- for label in labels:
- self.play(ReplacementTransform(
- last_label.copy(), label
- ))
- self.dither()
- last_label = label
- for x in 1, 0, self.start_x:
- self.animate_x_change(x, run_time = 1)
- self.dither()
- def draw_function_arrows(self):
- lines, line_labels = self.line_group
- labels = VGroup(*[
- TexMobject("(\\dots)^2").highlight(X_SQUARED_COLOR),
- TexMobject("\\sin(\\dots)").highlight(SINE_COLOR)
- ])
- arrows = VGroup()
- for lines_subset, label in zip([lines[:2], lines[1:]], labels):
- arrow = Arc(start_angle = np.pi/3, angle = -2*np.pi/3)
- arrow.add_tip()
- arrow.highlight(label.get_color())
- arrow.next_to(VGroup(*lines_subset))
- arrows.add(arrow)
- label.next_to(arrow, RIGHT)
-
- self.play(
- ShowCreation(arrow),
- Write(label)
- )
- self.dither()
- self.arrows = arrows
- self.arrow_labels = labels
+class ExponentRatioWithE(AnalyzeExponentRatio):
+ CONFIG = {
+ "base" : np.exp(1),
+ "base_str" : "e",
+ }
- def talk_through_movement(self):
- lines, labels = self.line_group
+class AskAboutConstantOne(TeacherStudentsScene):
+ def construct(self):
+ note = TexMobject(
+ "{ d(a^", "t", ")", "\\over \\,", "dt}",
+ "=", "a^", "t", "(\\text{Some constant})"
+ )
+ note.highlight_by_tex("t", YELLOW)
+ note.highlight_by_tex("dt", GREEN)
+ note.highlight_by_tex("constant", BLUE)
+ note.to_corner(UP+LEFT)
+ self.add(note)
- self.animate_x_change(self.top_x, run_time = 4)
- self.dither()
- for label in labels[0], labels[1]:
- oval = Circle(color = YELLOW)
- oval.replace(label, stretch = True)
- oval.scale(2.5)
- oval.move_to(label.get_bottom())
- self.play(ShowCreation(oval))
- self.dither()
- self.play(FadeOut(oval))
- sine_text = TexMobject("\\sin(9) \\approx 0.412")
- sine_text.move_to(labels[-1][-1])
- sine_text.to_edge(DOWN)
- sine_arrow = Arrow(
- sine_text.get_top(),
- labels[-1][0].get_bottom(),
- buff = SMALL_BUFF,
+ self.student_says(
+ "Is there a base where\\\\",
+ "that constant is 1?"
)
- self.play(
- FadeIn(sine_text),
- ShowCreation(sine_arrow)
+ self.change_student_modes(
+ "pondering", "raise_right_hand", "thinking",
+ # look_at_arg = self.get_students()[1].bubble
)
self.dither(2)
- self.play(*map(FadeOut, [sine_text, sine_arrow]))
- self.animate_x_change(self.example_x, run_time = 3)
-
- def nudge_x(self):
- lines, labels = self.line_group
- def get_value_points():
- return [
- label[0].get_bottom()
- for label in labels
- ]
- starts = get_value_points()
- self.animate_x_change(self.example_x + self.dx, run_time = 0)
- ends = get_value_points()
- self.animate_x_change(self.example_x, run_time = 0)
-
- nudge_lines = VGroup()
- braces = VGroup()
- numbers = VGroup()
- for start, end, line, label, config in zip(starts, ends, lines, labels, self.line_configs):
- color = label[0].get_color()
- nudge_line = Line(start, end)
- nudge_line.set_stroke(color, width = 6)
- brace = Brace(nudge_line, DOWN, buff = SMALL_BUFF)
- brace.highlight(color)
- func_label = config["func_label"]
- if len(func_label) == 1:
- text = "$d%s$"%func_label
- else:
- text = "$d(%s)$"%func_label
- brace.text = brace.get_text(text, buff = SMALL_BUFF)
- brace.text.highlight(color)
- brace.add(brace.text)
-
- line.add(nudge_line)
- nudge_lines.add(nudge_line)
- braces.add(brace)
- numbers.add(line.numbers)
- line.remove(*line.numbers)
- dx_brace, dx_squared_brace, dsine_brace = braces
-
- x_value = str(self.example_x)
- x_value_label = TexMobject("=%s"%x_value)
- x_value_label.next_to(labels[0][1], RIGHT)
- dx_squared_value = TexMobject(
- "= 2x\\,dx ", "\\\\ = 2(%s)dx"%x_value
- )
- dx_squared_value.shift(
- dx_squared_brace.text.get_right()+MED_SMALL_BUFF*RIGHT - \
- dx_squared_value[0].get_left()
- )
- dsine_value = TextMobject(
- "$=\\cos(%s)$"%self.line_configs[1]["func_label"],
- dx_squared_brace.text.get_tex_string()
- )
- dsine_value.next_to(dsine_brace.text)
- less_than_zero = TexMobject("<0")
- less_than_zero.next_to(dsine_brace.text)
-
- all_x_squared_relevant_labels = VGroup(
- dx_squared_brace, dsine_brace,
- labels[1], labels[2],
- dsine_value,
- )
- all_x_squared_relevant_labels.save_state()
-
- self.play(FadeOut(numbers))
- self.animate_x_change(
- self.example_x + self.dx,
- run_time = 1,
- added_anims = it.chain(
- [GrowFromCenter(dx_brace)],
- map(ShowCreation, nudge_lines)
- )
- )
- self.animate_x_change(self.example_x)
- self.dither()
- self.play(Write(x_value_label))
- self.dither()
- self.play(FocusOn(dx_squared_brace))
- self.play(Write(dx_squared_brace))
- self.wiggle_by_dx()
- self.dither()
- for part in dx_squared_value:
- self.play(Write(part))
- self.dither()
- self.play(FadeOut(dx_squared_value))
- self.dither()
- #Needs to be part of everything for the reconfiguraiton
- dsine_brace.set_fill(opacity = 0)
- dsine_value.set_fill(opacity = 0)
- self.add(dsine_brace, dsine_value)
- self.replace_x_squared_with_h()
- self.dither()
- self.play(dsine_brace.set_fill, None, 1)
- self.discuss_dsine_sign(less_than_zero)
- self.dither()
- dsine_value.set_fill(opacity = 1)
- self.play(Write(dsine_value))
+ self.play(FadeOut(note[-1], run_time = 3))
self.dither()
- self.play(
- all_x_squared_relevant_labels.restore,
- submobject_mode = "lagged_start",
- lag_factor = 3,
- run_time = 3,
- )
- self.__dict__.update(self.__class__.CONFIG)
- self.dither()
- for mob in dsine_value:
- self.play(Indicate(mob))
- self.dither()
- two_x_dx = dx_squared_value[0]
- dx_squared = dsine_value[1]
- two_x_dx_copy = VGroup(*two_x_dx[1:]).copy()
- self.play(FocusOn(two_x_dx))
- self.play(Write(two_x_dx))
- self.play(
- two_x_dx_copy.move_to, dx_squared, LEFT,
- dx_squared.next_to, dx_squared, UP,
- run_time = 2
+ self.teacher_says(
+ "There is!\\\\",
+ "$e = 2.71828\\dots$",
+ target_mode = "hooray"
)
- self.play(FadeOut(dx_squared))
- for sublist in two_x_dx_copy[:2], two_x_dx_copy[2:]:
- self.play(Indicate(VGroup(*sublist)))
- self.dither()
- self.dither(2)
-
- self.final_derivative = dsine_value
-
- def discuss_dsine_sign(self, less_than_zero):
- self.wiggle_by_dx()
- self.dither()
- for x in self.example_x+self.dx, self.example_x:
- self.animate_x_change(x, run_time = 2)
- self.dither()
- if less_than_zero not in self.get_mobjects():
- self.play(Write(less_than_zero))
- else:
- self.play(FadeOut(less_than_zero))
-
- def replace_x_squared_with_h(self):
- new_config = copy.deepcopy(self.__class__.CONFIG)
- new_config["line_configs"][1]["func_label"] = "h"
- new_config["line_configs"][2]["func_label"] = "\\sin(h)"
- self.transition_to_alt_config(
- return_to_original_configuration = False,
- **new_config
- )
-
- def give_example_of_meaning(self):
- words = TextMobject("For example,")
- expression = TexMobject("\\cos(1.5^2)\\cdot 2(1.5)\\,dx")
- group = VGroup(words, expression)
- group.arrange_submobjects(DOWN, aligned_edge = LEFT)
- group.scale(0.8)
- group.to_edge(RIGHT)
- arrow = Arrow(group.get_bottom(), self.final_derivative[0].get_top())
-
- self.play(*map(FadeOut, [self.arrows, self.arrow_labels]))
- self.play(FadeIn(group))
- self.play(ShowCreation(arrow))
- self.dither()
- self.wiggle_by_dx()
- self.dither()
-
+ self.change_student_modes(*["confused"]*3)
+ self.dither(3)
- ########
-
- def wiggle_by_dx(self, **kwargs):
- kwargs["run_time"] = kwargs.get("run_time", 1)
- kwargs["rate_func"] = kwargs.get("rate_func", there_and_back)
- target_x = self.line_group.x_val + self.dx
- self.animate_x_change(target_x, **kwargs)
-
- def animate_x_change(self, target_x, **kwargs):
- #Assume fixed lines, only update labels
- kwargs["run_time"] = kwargs.get("run_time", 2)
- added_anims = kwargs.get("added_anims", [])
- start_x = self.line_group.x_val
- def update(line_group, alpha):
- lines, labels = line_group
- new_x = interpolate(start_x, target_x, alpha)
- for line, label, config in zip(lines, labels, self.line_configs):
- new_label = self.get_line_label(
- line, new_x, **config
- )
- Transform(label, new_label).update(1)
- line_group.x_val = new_x
- self.play(
- UpdateFromAlphaFunc(self.line_group, update),
- *added_anims,
- **kwargs
- )
-
- def get_line_group(self, x):
- group = VGroup()
- group.lines, group.labels = VGroup(), VGroup()
- for line_config in self.line_configs:
- number_line = self.get_number_line(**line_config)
- label = self.get_line_label(number_line, x, **line_config)
- group.lines.add(number_line)
- group.labels.add(label)
- group.add(group.lines, group.labels)
- group.x_val = x
- return group
-
- def get_number_line(
- self, center_y, **number_line_config
- ):
- number_line = NumberLine(color = GREY, **number_line_config)
- number_line.stretch_to_fit_width(self.line_width)
- number_line.add_numbers()
- number_line.shift(center_y*UP)
- number_line.to_edge(LEFT, buff = LARGE_BUFF)
-
- return number_line
-
- def get_line_label(
- self, number_line, x, func, func_label, triangle_color,
- **spillover_kwargs
- ):
- triangle = RegularPolygon(
- n=3, start_angle = -np.pi/2,
- fill_color = triangle_color,
- fill_opacity = 0.75,
- stroke_width = 0,
- )
- triangle.scale_to_fit_height(self.triangle_height)
- triangle.move_to(
- number_line.number_to_point(func(x)), DOWN
- )
-
- label_mob = TexMobject(func_label)
- label_mob.next_to(triangle, UP, buff = SMALL_BUFF, aligned_edge = LEFT)
-
- return VGroup(triangle, label_mob)
-
-class GeneralizeChainRule(Scene):
+class NaturalLog(Scene):
def construct(self):
- example = TexMobject(
- "\\frac{d}{dx}", "\\sin(", "x^2", ")", "=",
- "\\cos(", "x^2", ")", "\\,2x",
- )
- general = TexMobject(
- "\\frac{d}{dx}", "g(", "h(x)", ")", "=",
- "{dg \\over ", " dh}", "(", "h(x)", ")", "{dh \\over", " dx}", "(x)"
- )
- example.to_edge(UP, buff = LARGE_BUFF)
- example.shift(RIGHT)
- general.next_to(example, DOWN, buff = 1.5*LARGE_BUFF)
- for mob in example, general:
- mob.highlight(SINE_COLOR)
- mob[0].highlight(WHITE)
- for tex in "x^2", "2x", "(x)", "{dh", " dx}":
- mob.highlight_by_tex(tex, X_SQUARED_COLOR, substring = True)
-
- example_outer = VGroup(*example[1:4])
- example_inner = example[2]
- d_example_outer = VGroup(*example[5:8])
- d_example_inner = example[6]
- d_example_d_inner = example[8]
-
- general_outer = VGroup(*general[1:4])
- general_inner = general[2]
- d_general_outer = VGroup(*general[5:10])
- d_general_inner = general[8]
- d_general_d_inner = VGroup(*general[10:13])
-
- example_outer_brace = Brace(example_outer)
- example_inner_brace = Brace(example_inner, UP, buff = SMALL_BUFF)
- d_example_outer_brace = Brace(d_example_outer)
- d_example_inner_brace = Brace(d_example_inner, buff = SMALL_BUFF)
- d_example_d_inner_brace = Brace(d_example_d_inner, UP, buff = SMALL_BUFF)
-
- general_outer_brace = Brace(general_outer)
- general_inner_brace = Brace(general_inner, UP, buff = SMALL_BUFF)
- d_general_outer_brace = Brace(d_general_outer)
- d_general_inner_brace = Brace(d_general_inner, buff = SMALL_BUFF)
- d_general_d_inner_brace = Brace(d_general_d_inner, UP, buff = SMALL_BUFF)
-
- for brace in example_outer_brace, general_outer_brace:
- brace.text = brace.get_text("Outer")
- for brace in example_inner_brace, general_inner_brace:
- brace.text = brace.get_text("Inner")
- for brace in d_example_outer_brace, d_general_outer_brace:
- brace.text = brace.get_text("d(Outer)")
- brace.text.shift(SMALL_BUFF*LEFT)
- for brace in d_example_d_inner_brace, d_general_d_inner_brace:
- brace.text = brace.get_text("d(Inner)", buff = SMALL_BUFF)
-
- #d(out)d(in) for example
- self.add(example)
- braces = VGroup(
- example_outer_brace,
- example_inner_brace,
- d_example_outer_brace
- )
- for brace in braces:
- self.play(GrowFromCenter(brace))
- self.play(Write(brace.text, run_time = 1))
- self.dither()
- self.dither()
- self.play(*it.chain(*[
- [mob.scale_in_place, 1.2, mob.highlight, YELLOW]
- for mob in example_inner, d_example_inner
- ]), rate_func = there_and_back)
- self.play(Transform(
- example_inner.copy(), d_example_inner,
- path_arc = -np.pi/2,
- remover = True
+ expressions = VGroup(*map(self.get_expression, [2, 3, 7]))
+ expressions.arrange_submobjects(DOWN, buff = MED_SMALL_BUFF)
+ expressions.to_edge(LEFT)
+
+ self.play(FadeIn(
+ expressions,
+ run_time = 3,
+ submobject_mode = "lagged_start"
))
self.dither()
self.play(
- GrowFromCenter(d_example_d_inner_brace),
- Write(d_example_d_inner_brace.text)
- )
- self.play(Transform(
- VGroup(*reversed(example_inner.copy())),
- d_example_d_inner,
- path_arc = -np.pi/2,
+ expressions.set_fill, None, 1,
run_time = 2,
- remover = True
- ))
+ submobject_mode = "lagged_start"
+ )
self.dither()
+ for i in 0, 2, 1:
+ self.show_natural_loggedness(expressions[i])
- #Generalize
- self.play(*map(FadeIn, general[:5]))
- self.dither()
- self.play(
- Transform(example_outer_brace, general_outer_brace),
- Transform(example_outer_brace.text, general_outer_brace.text),
- Transform(example_inner_brace, general_inner_brace),
- Transform(example_inner_brace.text, general_inner_brace.text),
+ def show_natural_loggedness(self, expression):
+ base, constant = expression[1], expression[-3]
+
+ log_constant, exp_constant = constant.copy(), constant.copy()
+ log_base, exp_base = base.copy(), base.copy()
+ log_equals, exp_equals = map(TexMobject, "==")
+
+ ln = TexMobject("\\ln(2)")
+ log_base.move_to(ln[-2])
+ ln.remove(ln[-2])
+ log_equals.next_to(ln, LEFT)
+ log_constant.next_to(log_equals, LEFT)
+ log_expression = VGroup(
+ ln, log_constant, log_equals, log_base
)
- self.dither()
- self.play(
- Transform(d_example_outer_brace, d_general_outer_brace),
- Transform(d_example_outer_brace.text, d_general_outer_brace.text),
+
+ e = TexMobject("e")
+ exp_constant.scale(0.7)
+ exp_constant.next_to(e, UP+RIGHT, buff = 0)
+ exp_base.next_to(exp_equals, RIGHT)
+ VGroup(exp_base, exp_equals).next_to(
+ VGroup(e, exp_constant), RIGHT,
+ aligned_edge = DOWN
)
- self.play(Write(d_general_outer))
- self.dither(2)
- self.play(
- Transform(d_example_d_inner_brace, d_general_d_inner_brace),
- Transform(d_example_d_inner_brace.text, d_general_d_inner_brace.text),
+ exp_expression = VGroup(
+ e, exp_constant, exp_equals, exp_base
)
- self.play(Write(d_general_d_inner))
- self.dither(2)
- #Name chain rule
- name = TextMobject("``Chain rule''")
- name.scale(1.2)
- name.highlight(YELLOW)
- name.to_corner(UP+LEFT)
- self.play(Write(name))
- self.dither()
+ for group, vect in (log_expression, UP), (exp_expression, DOWN):
+ group.to_edge(RIGHT)
+ group.shift(vect)
- #Point out dh bottom
- morty = Mortimer().flip()
- morty.to_corner(DOWN+LEFT)
- d_general_outer_copy = d_general_outer.copy()
- morty.set_fill(opacity = 0)
self.play(
- morty.set_fill, None, 1,
- morty.change_mode, "raise_left_hand",
- morty.look, UP+LEFT,
- d_general_outer_copy.next_to,
- morty.get_corner(UP+LEFT), UP, MED_LARGE_BUFF,
- d_general_outer_copy.shift_onto_screen
- )
- self.dither()
- circle = Circle(color = YELLOW)
- circle.replace(d_general_outer_copy[1])
- circle.scale_in_place(1.4)
- self.play(ShowCreation(circle))
- self.play(Blink(morty))
- self.dither()
- inner = d_general_outer_copy[3]
- self.play(
- morty.change_mode, "hooray",
- morty.look_at, inner,
- inner.shift, UP
+ ReplacementTransform(base.copy(), log_base),
+ ReplacementTransform(constant.copy(), log_constant),
+ run_time = 2
)
- self.play(inner.shift, DOWN)
- self.dither()
- self.play(morty.change_mode, "pondering")
- self.play(Blink(morty))
+ self.play(Write(ln), Write(log_equals))
self.dither()
- self.play(*map(FadeOut, [
- d_general_outer_copy, inner, circle
- ]))
-
- #Show cancelation
- braces = [
- d_example_d_inner_brace,
- d_example_outer_brace,
- example_inner_brace,
- example_outer_brace,
- ]
- texts = [brace.text for brace in braces]
- self.play(*map(FadeOut, braces+texts))
-
- to_collapse = VGroup(VGroup(*general[7:10]), general[12])
- dg_dh = VGroup(*general[5:7])
- dh_dx = VGroup(*general[10:12])
- to_collapse.generate_target()
- points = VGroup(*map(VectorizedPoint,
- [m.get_left() for m in to_collapse]
- ))
self.play(
- Transform(to_collapse, points),
- dh_dx.next_to, dg_dh,
- morty.look_at, dg_dh,
+ ReplacementTransform(
+ log_expression.copy(),
+ exp_expression,
+ run_time = 2,
+ )
)
- self.dither()
- for mob in list(dg_dh)+list(dh_dx):
- circle = Circle(color = YELLOW)
- circle.replace(mob)
- circle.scale_in_place(1.3)
- self.play(ShowCreation(circle))
- self.dither()
- self.play(FadeOut(circle))
-
- strikes = VGroup()
- for dh in dg_dh[1], dh_dx[0]:
- strike = TexMobject("/")
- strike.stretch(2, dim = 0)
- strike.rotate(-np.pi/12)
- strike.move_to(dh)
- strike.highlight(RED)
- strikes.add(strike)
- self.play(Write(strikes))
- self.play(morty.change_mode, "hooray")
- equals_dg_dx = TexMobject("= \\frac{dg}{dx}")
- equals_dg_dx.next_to(dh_dx)
- self.play(Write(equals_dg_dx))
- self.play(Blink(morty))
self.dither(2)
- ##More than a notational trick
+ ln_a = expression[-1]
self.play(
- PiCreatureSays(morty, """
- This is more than a
- notational trick
- """),
- VGroup(
- dg_dh, dh_dx, equals_dg_dx, strikes,
- *general[:5]
- ).shift, DOWN,
- FadeOut(example)
+ FadeOut(expression[-2]),
+ FadeOut(constant),
+ ln_a.move_to, constant, LEFT,
+ ln_a.highlight, BLUE
)
self.dither()
- self.play(Blink(morty))
+ self.play(*map(FadeOut, [log_expression, exp_expression]))
self.dither()
-class WatchingVideo(PiCreatureScene):
- def construct(self):
- laptop = Laptop()
- laptop.scale(2)
- laptop.to_corner(UP+RIGHT)
- randy = self.get_primary_pi_creature()
- randy.move_to(laptop, DOWN+LEFT)
- randy.shift(MED_SMALL_BUFF*UP)
- randy.look_at(laptop.screen)
-
-
- formulas = VGroup(*[
- TexMobject("\\frac{d}{dx}\\left( %s \\right)"%s)
- for s in [
- "e^x \\sin(x)",
- "\\sin(x) \\cdot \\frac{1}{\\cos(x)}",
- "\\cos(3x)^2",
- "e^x(x^2 + 3x + 2)",
- ]
- ])
- formulas.arrange_submobjects(
- DOWN,
- buff = MED_LARGE_BUFF,
- aligned_edge = LEFT
+ def get_expression(self, base):
+ expression = TexMobject(
+ "{d(", "%d^"%base, "t", ")", "\\over \\,", "dt}",
+ "=", "%d^"%base, "t", "(%.4f\\dots)"%np.log(base),
)
- formulas.next_to(randy, LEFT, buff = MED_LARGE_BUFF)
- formulas.shift_onto_screen()
+ expression.highlight_by_tex("t", YELLOW)
+ expression.highlight_by_tex("dt", GREEN)
+ expression.highlight_by_tex("\\dots", BLUE)
- self.add(randy, laptop)
- self.dither()
- self.play(randy.change_mode, "erm")
- self.play(Blink(randy))
- self.dither()
- self.play(randy.change_mode, "maybe")
- self.dither()
- self.play(Blink(randy))
- for formula in formulas:
- self.play(
- Write(formula, run_time = 2),
- randy.change_mode, "thinking"
- )
- self.dither()
+ brace = Brace(expression.get_part_by_tex("\\dots"), UP)
+ brace_text = brace.get_text("$\\ln(%d)$"%base)
+ for mob in brace, brace_text:
+ mob.set_fill(opacity = 0)
- def create_pi_creatures(self):
- return [Randolph().shift(DOWN+RIGHT)]
+ expression.add(brace, brace_text)
+ return expression
class NextVideo(TeacherStudentsScene):
def construct(self):
series = VideoSeries()
series.to_edge(UP)
+ this_video = series[3]
next_video = series[4]
+ brace = Brace(this_video, DOWN)
+ this_video.save_state()
+ this_video.highlight(YELLOW)
- pre_expression = TexMobject(
- "x", "^2", "+", "y", "^2", "=", "1"
+ this_tex = TexMobject(
+ "{d(", "a^t", ") \\over dt} = ", "a^t", "\\ln(a)"
)
- d_expression = TexMobject(
- "2", "x", "\\,dx", "+", "2", "y", "\\,dy", "=", "0"
- )
- expression_to_d_expression_indices = [
- 1, 0, 0, 2, 4, 3, 3, 5, 6
- ]
- expression = VGroup()
- for i, j in enumerate(expression_to_d_expression_indices):
- submob = pre_expression[j].copy()
- if d_expression.expression_parts[i] == "2":
- two = TexMobject("2")
- two.replace(submob)
- expression.add(two)
- else:
- expression.add(submob)
-
- for mob in expression, d_expression:
- mob.scale(1.2)
- mob.next_to(
- self.get_teacher().get_corner(UP+LEFT), UP,
- buff = MED_LARGE_BUFF
- )
- mob.shift_onto_screen()
-
- axes = Axes(x_min = -3, x_max = 3, color = GREY)
- axes.add(Circle(color = YELLOW))
- line = Line(np.sqrt(2)*UP, np.sqrt(2)*RIGHT)
- line.scale_in_place(1.5)
- axes.add(line)
-
- axes.scale(0.5)
- axes.next_to(d_expression, LEFT)
+ this_tex[1][1].highlight(YELLOW)
+ this_tex[3][1].highlight(YELLOW)
+ this_tex.next_to(brace, DOWN)
- self.add(series)
- self.play(
- next_video.shift, 0.5*DOWN,
- next_video.highlight, YELLOW,
- self.get_teacher().change_mode, "raise_right_hand"
+ next_tex = VGroup(*map(TextMobject, [
+ "Chain rule", "Product rule", "$\\vdots$"
+ ]))
+ next_tex.arrange_submobjects(DOWN)
+ next_tex.next_to(brace, DOWN)
+ next_tex.shift(
+ next_video.get_center()[0]*RIGHT\
+ -next_tex.get_center()[0]*RIGHT
)
- self.dither()
- self.play(
- Write(expression),
- *[
- ApplyMethod(pi.change_mode, "pondering")
- for pi in self.get_students()
- ]
+
+ self.add(series, brace, *this_tex[:3])
+ self.change_student_modes(
+ "confused", "pondering", "erm",
+ look_at_arg = this_tex
)
- self.play(FadeIn(axes))
- self.dither()
- self.remove(expression)
- self.play(Transform(expression, d_expression, path_arc = np.pi/2))
+ self.play(ReplacementTransform(
+ this_tex[1].copy(), this_tex[3]
+ ))
self.dither()
self.play(
- Rotate(
- line, np.pi/4,
- about_point = axes.get_center(),
- rate_func = wiggle,
- run_time = 3
+ Write(this_tex[4]),
+ ReplacementTransform(
+ this_tex[3][0].copy(),
+ this_tex[4][3],
+ path_arc = np.pi,
+ remover = True
)
)
self.dither(2)
+ self.play(this_tex.replace, this_video)
+ self.play(
+ brace.next_to, next_video, DOWN,
+ this_video.restore,
+ Animation(this_tex),
+ next_video.highlight, YELLOW,
+ Write(next_tex),
+ self.get_teacher().change_mode, "raise_right_hand"
+ )
+ self.change_student_modes(
+ *["pondering"]*3,
+ look_at_arg = next_tex
+ )
+ self.dither(3)
-class Chapter4Thanks(PatreonThanks):
+class ExpPatreonThanks(PatreonThanks):
CONFIG = {
"specific_patrons" : [
"Ali Yahya",
"Meshal Alshammari",
"CrypticSwarm ",
+ "Kathryn Schmiedicke",
+ "Nathan Pellegrin",
+ "Karan Bhargava",
+ "Justin Helps",
"Ankit Agarwal",
"Yu Jun",
- "Shelby Doolittle",
"Dave Nicponski",
"Damion Kistler",
"Juan Benet",
@@ -2256,7 +1142,12 @@ class Chapter4Thanks(PatreonThanks):
"Derek Dai",
"Joseph John Cox",
"Luc Ritchie",
+ "Mustafa Mahdi",
+ "Daan Smedinga",
+ "Jonathan Eppele",
+ "Albert Nguyen",
"Nils Schneider",
+ "Mustafa Mahdi",
"Mathew Bramson",
"Guido Gambardella",
"Jerry Ling",
@@ -2271,31 +1162,42 @@ class Chapter4Thanks(PatreonThanks):
]
}
-class Thumbnail(IntroduceProductAsArea):
- CONFIG = {
- "default_x" : 0.8,
- "dx" : 0.05
- }
+class Thumbnail(Scene):
def construct(self):
- self.x_slider = self.get_x_slider(self.default_x)
- blg = self.box_label_group = self.get_box_label_group(
- self.default_x
- )
- df_boxes = self.get_df_boxes()
- df_boxes.space_out_submobjects(1.1)
- df_boxes.move_to(blg[0], UP+LEFT)
- blg[1][1].next_to(df_boxes[-1], RIGHT)
- df_box_labels = self.get_df_box_labels(df_boxes)
- blg.add(df_boxes, df_box_labels)
- blg.scale_to_fit_height(2*SPACE_HEIGHT-2*MED_LARGE_BUFF)
- blg.center()
- self.add(blg)
-
-
-
-
-
-
+ derivative = TexMobject(
+ "\\frac{d(a^t)}{dt} =", "a^t \\ln(a)"
+ )
+ derivative[0][3].highlight(YELLOW)
+ derivative[1][1].highlight(YELLOW)
+ derivative[0][2].highlight(BLUE)
+ derivative[1][0].highlight(BLUE)
+ derivative[1][5].highlight(BLUE)
+ derivative.scale(3)
+ # derivative.to_edge(UP)
+ derivative.shift(DOWN)
+
+ brace = Brace(Line(LEFT, RIGHT), UP)
+ brace.scale_to_fit_width(derivative[1].get_width())
+ brace.next_to(derivative[1], UP)
+ question = TextMobject("Why?")
+ question.scale(2.5)
+ question.next_to(brace, UP)
+
+ # randy = Randolph()
+ # randy.scale(1.3)
+ # randy.next_to(ORIGIN, LEFT).to_edge(DOWN)
+ # randy.change_mode("pondering")
+
+ # question = TextMobject("What is $e\\,$?")
+ # e = question[-2]
+ # e.scale(1.2, about_point = e.get_bottom())
+ # e.highlight(BLUE)
+ # question.scale(1.7)
+ # question.next_to(randy, RIGHT, aligned_edge = UP)
+ # question.shift(DOWN)
+ # randy.look_at(question)
+
+ self.add(derivative, brace, question)
diff --git a/eoc/chapter5.py b/eoc/chapter5.py
index 568f6ff32..39dc3b2d5 100644
--- a/eoc/chapter5.py
+++ b/eoc/chapter5.py
@@ -25,2632 +25,2227 @@ from camera import Camera
from mobject.svg_mobject import *
from mobject.tex_mobject import *
-from topics.common_scenes import *
+
+from topics.common_scenes import OpeningQuote, PatreonThanks
from eoc.graph_scene import *
-SPACE_UNIT_TO_PLANE_UNIT = 0.75
+SINE_COLOR = BLUE
+X_SQUARED_COLOR = GREEN
+SUM_COLOR = YELLOW
+PRODUCT_COLOR = YELLOW
class Chapter5OpeningQuote(OpeningQuote):
CONFIG = {
"quote" : [
- "Do not ask whether a ",
- "statement is true until",
- "you know what it means."
+ "Using the chain rule is like peeling an onion: ",
+ "you have to deal with each layer at a time, and ",
+ "if it is too big you will start crying."
],
- "author" : "Errett Bishop"
+ "author" : "(Anonymous professor)"
}
-class ThisWasConfusing(TeacherStudentsScene):
- def construct(self):
- words = TextMobject("Implicit differentiation")
- words.move_to(self.get_teacher().get_corner(UP+LEFT), DOWN+RIGHT)
- words.set_fill(opacity = 0)
-
- self.play(
- self.get_teacher().change_mode, "raise_right_hand",
- words.set_fill, None, 1,
- words.shift, 0.5*UP
- )
- self.change_student_modes(
- *["confused"]*3,
- look_at_arg = words,
- added_anims = [Animation(self.get_teacher())]
- )
- self.dither()
- self.play(
- self.get_teacher().change_mode, "confused",
- self.get_teacher().look_at, words,
- )
- self.dither(3)
-
-class SlopeOfCircleExample(ZoomedScene):
- CONFIG = {
- "plane_kwargs" : {
- "x_radius" : SPACE_WIDTH/SPACE_UNIT_TO_PLANE_UNIT,
- "y_radius" : SPACE_HEIGHT/SPACE_UNIT_TO_PLANE_UNIT,
- "space_unit_to_x_unit" : SPACE_UNIT_TO_PLANE_UNIT,
- "space_unit_to_y_unit" : SPACE_UNIT_TO_PLANE_UNIT,
- },
- "example_point" : (3, 4),
- "circle_radius" : 5,
- "circle_color" : YELLOW,
- "example_color" : MAROON_B,
- "zoom_factor" : 20,
- "zoomed_canvas_corner" : UP+LEFT,
- "zoomed_canvas_corner_buff" : MED_SMALL_BUFF,
- }
+class TransitionFromLastVideo(TeacherStudentsScene):
def construct(self):
- self.setup_plane()
- self.introduce_circle()
- self.talk_through_pythagorean_theorem()
- self.draw_example_slope()
- self.show_perpendicular_radius()
- self.show_dx_and_dy()
- self.write_slope_as_dy_dx()
- self.point_out_this_is_not_a_graph()
- self.perform_implicit_derivative()
- self.show_final_slope()
-
- def setup_plane(self):
- self.plane = NumberPlane(**self.plane_kwargs)
- self.plane.main_lines.fade()
- self.plane.add(self.plane.get_axis_labels())
- self.plane.add_coordinates()
-
- self.add(self.plane)
-
- def introduce_circle(self):
- circle = Circle(
- radius = self.circle_radius*SPACE_UNIT_TO_PLANE_UNIT,
- color = self.circle_color,
- )
- equation = TexMobject("x^2 + y^2 = 5^2")
- equation.add_background_rectangle()
- equation.next_to(
- circle.point_from_proportion(1./8),
- UP+RIGHT
- )
- equation.to_edge(RIGHT)
-
- self.play(ShowCreation(circle, run_time = 2))
- self.play(Write(equation))
- self.dither()
-
- self.circle = circle
- self.circle_equation = equation
-
- def talk_through_pythagorean_theorem(self):
- point = self.plane.num_pair_to_point(self.example_point)
- x_axis_point = point[0]*RIGHT
- dot = Dot(point, color = self.example_color)
-
- x_line = Line(ORIGIN, x_axis_point, color = GREEN)
- y_line = Line(x_axis_point, point, color = RED)
- radial_line = Line(ORIGIN, point, color = self.example_color)
- lines = VGroup(radial_line, x_line, y_line)
- labels = VGroup()
-
- self.play(ShowCreation(dot))
- for line, tex in zip(lines, "5xy"):
- label = TexMobject(tex)
- label.highlight(line.get_color())
- label.add_background_rectangle()
- label.next_to(
- line.get_center(),
- rotate_vector(UP, line.get_angle()),
- buff = SMALL_BUFF
- )
- self.play(
- ShowCreation(line),
- Write(label)
- )
- labels.add(label)
-
- full_group = VGroup(dot, lines, labels)
- start_angle = angle_of_vector(point)
- end_angle = np.pi/12
- spatial_radius = np.linalg.norm(point)
- def update_full_group(group, alpha):
- dot, lines, labels = group
- angle = interpolate(start_angle, end_angle, alpha)
- new_point = spatial_radius*rotate_vector(RIGHT, angle)
- new_x_axis_point = new_point[0]*RIGHT
- dot.move_to(new_point)
-
- radial_line, x_line, y_line = lines
- x_line.put_start_and_end_on(ORIGIN, new_x_axis_point)
- y_line.put_start_and_end_on(new_x_axis_point, new_point)
- radial_line.put_start_and_end_on(ORIGIN, new_point)
- for line, label in zip(lines, labels):
- label.next_to(
- line.get_center(),
- rotate_vector(UP, line.get_angle()),
- buff = SMALL_BUFF
- )
- return group
-
- self.play(UpdateFromAlphaFunc(
- full_group, update_full_group,
- rate_func = there_and_back,
- run_time = 5,
- ))
- self.dither(2)
+ simple_rules = VGroup(*map(TexMobject, [
+ "\\frac{d(x^3)}{dx} = 3x^2",
+ "\\frac{d(\\sin(x))}{dx} = \\cos(x)",
+ "\\frac{d(e^x)}{dx} = e^x",
+ ]))
- #Move labels to equation
- movers = labels.copy()
- pairs = zip(
- [movers[1], movers[2], movers[0]],
- self.circle_equation[1][0:-1:3]
- )
- self.play(*[
- ApplyMethod(m1.replace, m2)
- for m1, m2 in pairs
+ combination_rules = VGroup(*[
+ TexMobject("\\frac{d}{dx}\\left(%s\\right)"%tex)
+ for tex in [
+ "\\sin(x) + x^2",
+ "\\sin(x)(x^2)",
+ "\\sin(x^2)",
+ ]
])
- self.dither()
-
- self.play(*map(FadeOut, [lines, labels, movers]))
- self.remove(full_group)
- self.add(dot)
- self.dither()
-
- self.example_point_dot = dot
+ for rules in simple_rules, combination_rules:
+ rules.arrange_submobjects(buff = LARGE_BUFF)
+ rules.next_to(self.get_teacher(), UP, buff = MED_LARGE_BUFF)
+ rules.to_edge(LEFT)
- def draw_example_slope(self):
- point = self.example_point_dot.get_center()
- line = Line(ORIGIN, point)
- line.highlight(self.example_color)
- line.rotate(np.pi/2)
- line.scale(2)
- line.move_to(point)
-
- word = TextMobject("Slope?")
- word.next_to(line.get_start(), UP, aligned_edge = LEFT)
- word.add_background_rectangle()
-
- coords = TexMobject("(%d, %d)"%self.example_point)
- coords.add_background_rectangle()
- coords.scale(0.7)
- coords.next_to(point, LEFT)
- coords.shift(SMALL_BUFF*DOWN)
- coords.highlight(self.example_color)
-
- self.play(GrowFromCenter(line))
- self.play(Write(word))
- self.dither()
- self.play(Write(coords))
- self.dither()
-
- self.tangent_line = line
- self.slope_word = word
- self.example_point_coords_mob = coords
-
- def show_perpendicular_radius(self):
- point = self.example_point_dot.get_center()
- radial_line = Line(ORIGIN, point, color = RED)
-
- perp_mark = VGroup(
- Line(UP, UP+RIGHT),
- Line(UP+RIGHT, RIGHT),
- )
- perp_mark.scale(0.2)
- perp_mark.set_stroke(width = 2)
- perp_mark.rotate(radial_line.get_angle()+np.pi)
- perp_mark.shift(point)
-
- self.play(ShowCreation(radial_line))
- self.play(ShowCreation(perp_mark))
- self.dither()
- self.play(Indicate(perp_mark))
- self.dither()
-
- morty = Mortimer().flip().to_corner(DOWN+LEFT)
- self.play(FadeIn(morty))
- self.play(PiCreatureBubbleIntroduction(
- morty, "Suppose you \\\\ don't know this.",
- ))
- to_fade =self.get_mobjects_from_last_animation()
- self.play(Blink(morty))
- self.dither()
-
- self.play(*map(FadeOut, to_fade))
- self.play(*map(FadeOut, [radial_line, perp_mark]))
- self.dither()
-
- def show_dx_and_dy(self):
- dot = self.example_point_dot
- point = dot.get_center()
- step_vect = rotate_vector(point, np.pi/2)
- step_length = 1./self.zoom_factor
- step_vect *= step_length/np.linalg.norm(step_vect)
-
- step_line = Line(ORIGIN, LEFT)
- step_line.highlight(WHITE)
- brace = Brace(step_line, DOWN)
- step_text = brace.get_text("Step", buff = SMALL_BUFF)
- step_group = VGroup(step_line, brace, step_text)
- step_group.rotate(angle_of_vector(point) - np.pi/2)
- step_group.scale(1./self.zoom_factor)
- step_group.shift(point)
-
- interim_point = step_line.get_corner(UP+RIGHT)
- dy_line = Line(point, interim_point)
- dx_line = Line(interim_point, point+step_vect)
- dy_line.highlight(RED)
- dx_line.highlight(GREEN)
- for line, tex in (dx_line, "dx"), (dy_line, "dy"):
- label = TexMobject(tex)
- label.scale(1./self.zoom_factor)
- next_to_vect = np.round(
- rotate_vector(DOWN, line.get_angle())
- )
- label.next_to(
- line, next_to_vect,
- buff = MED_SMALL_BUFF/self.zoom_factor
- )
- label.highlight(line.get_color())
- line.label = label
+ series = VideoSeries()
+ series.to_edge(UP)
+ last_video = series[2]
+ last_video.save_state()
+ this_video = series[3]
+ brace = Brace(last_video)
- self.activate_zooming()
- self.little_rectangle.move_to(step_line.get_center())
- self.little_rectangle.save_state()
- self.little_rectangle.scale_in_place(self.zoom_factor)
- self.dither()
+ #Simple rules
+ self.add(series)
self.play(
- self.little_rectangle.restore,
- dot.scale_in_place, 1./self.zoom_factor,
- run_time = 2
+ FadeIn(brace),
+ last_video.highlight, YELLOW
)
- self.dither()
- self.play(ShowCreation(step_line))
- self.play(GrowFromCenter(brace))
- self.play(Write(step_text))
- self.dither()
- for line in dy_line, dx_line:
- self.play(ShowCreation(line))
- self.play(Write(line.label))
+ for rule in simple_rules:
+ self.play(
+ Write(rule, run_time = 2),
+ self.get_teacher().change_mode, "raise_right_hand",
+ *[
+ ApplyMethod(pi.change_mode, "pondering")
+ for pi in self.get_students()
+ ]
+ )
self.dither()
- self.dither()
-
- self.step_group = step_group
- self.dx_line = dx_line
- self.dy_line = dy_line
-
- def write_slope_as_dy_dx(self):
- slope_word = self.slope_word
- new_slope_word = TextMobject("Slope =")
- new_slope_word.add_background_rectangle()
- new_slope_word.next_to(ORIGIN, RIGHT)
- new_slope_word.shift(slope_word.get_center()[1]*UP)
-
- dy_dx = TexMobject("\\frac{dy}{dx}")
- VGroup(*dy_dx[:2]).highlight(RED)
- VGroup(*dy_dx[-2:]).highlight(GREEN)
- dy_dx.next_to(new_slope_word, RIGHT)
- dy_dx.add_background_rectangle()
-
- self.play(Transform(slope_word, new_slope_word))
- self.play(Write(dy_dx))
- self.dither()
-
- self.dy_dx = dy_dx
-
- def point_out_this_is_not_a_graph(self):
- equation = self.circle_equation
- x = equation[1][0]
- y = equation[1][3]
- brace = Brace(equation, DOWN)
- brace_text = brace.get_text(
- "Not $y = f(x)$",
- buff = SMALL_BUFF
- )
- brace_text.highlight(RED)
- alt_brace_text = brace.get_text("Implicit curve")
- for text in brace_text, alt_brace_text:
- text.add_background_rectangle()
- text.to_edge(RIGHT, buff = MED_SMALL_BUFF)
-
- new_circle = self.circle.copy()
- new_circle.highlight(BLUE)
-
- self.play(
- GrowFromCenter(brace),
- Write(brace_text)
- )
- self.dither()
- self.play(Indicate(x))
- self.dither()
- self.play(Indicate(y))
- self.dither()
- self.play(Transform(brace_text, alt_brace_text))
- self.dither()
- self.play(
- ShowCreation(new_circle, run_time = 2),
- Animation(brace_text)
- )
- self.play(new_circle.set_stroke, None, 0)
- self.dither()
- self.play(*map(FadeOut, [brace, brace_text]))
- self.dither()
-
- def perform_implicit_derivative(self):
- equation = self.circle_equation
- morty = Mortimer()
- morty.flip()
- morty.next_to(ORIGIN, LEFT)
- morty.to_edge(DOWN, buff = SMALL_BUFF)
- q_marks = TexMobject("???")
- q_marks.next_to(morty, UP)
-
- rect = Rectangle(
- width = SPACE_WIDTH - SMALL_BUFF,
- height = SPACE_HEIGHT - SMALL_BUFF,
- stroke_width = 0,
- fill_color = BLACK,
- fill_opacity = 0.8,
- )
- rect.to_corner(DOWN+RIGHT, buff = 0)
-
- derivative = TexMobject("2x\\,dx + 2y\\,dy = 0")
- dx = VGroup(*derivative[2:4])
- dy = VGroup(*derivative[7:9])
- dx.highlight(GREEN)
- dy.highlight(RED)
-
-
-
- self.play(
- FadeIn(rect),
- FadeIn(morty),
- equation.next_to, ORIGIN, DOWN, MED_LARGE_BUFF,
- equation.shift, SPACE_WIDTH*RIGHT/2,
- )
+ self.dither(2)
+ self.play(simple_rules.replace, last_video)
self.play(
- morty.change_mode, "confused",
- morty.look_at, equation
- )
- self.play(Blink(morty))
- derivative.next_to(equation, DOWN)
- derivative.shift(
- equation[1][-3].get_center()[0]*RIGHT - \
- derivative[-2].get_center()[0]*RIGHT
+ last_video.restore,
+ Animation(simple_rules),
+ brace.next_to, this_video, DOWN,
+ this_video.highlight, YELLOW
)
-
- #Differentiate
+ #Combination rules
self.play(
- morty.look_at, derivative[0],
+ Write(combination_rules),
*[
- ReplacementTransform(
- equation[1][i].copy(),
- derivative[j],
- )
- for i, j in (1, 0), (0, 1)
+ ApplyMethod(pi.change_mode, "confused")
+ for pi in self.get_students()
]
)
- self.play(Write(dx, run_time = 1))
- self.dither()
- self.play(*[
- ReplacementTransform(
- equation[1][i].copy(),
- derivative[j],
- )
- for i, j in (2, 4), (3, 6), (4, 5)
- ])
- self.play(Write(dy, run_time = 1))
- self.play(Blink(morty))
- self.play(*[
- ReplacementTransform(
- equation[1][i].copy(),
- derivative[j],
+ self.dither(2)
+ for rule in combination_rules:
+ interior = VGroup(*rule[5:-1])
+ added_anims = []
+ if rule is combination_rules[-1]:
+ inner_func = VGroup(*rule[-4:-2])
+ self.play(inner_func.shift, 0.5*UP)
+ added_anims = [
+ inner_func.shift, 0.5*DOWN,
+ inner_func.highlight, YELLOW
+ ]
+ self.play(
+ interior.highlight, YELLOW,
+ *added_anims,
+ submobject_mode = "lagged_start"
)
- for i, j in (-3, -2), (-2, -1), (-1, -1)
- ])
- self.dither()
-
- #React
- self.play(morty.change_mode, "erm")
- self.play(Blink(morty))
- self.play(Write(q_marks))
- self.dither()
- self.play(Indicate(dx), morty.look_at, dx)
- self.play(Indicate(dy), morty.look_at, dy)
+ self.dither()
self.dither()
- self.play(
- morty.change_mode, "shruggie",
- FadeOut(q_marks)
- )
- self.play(Blink(morty))
- self.play(
- morty.change_mode, "pondering",
- morty.look_at, derivative,
- )
- #Rearrange
- x, y, eq = np.array(derivative)[[1, 6, 9]]
- final_form = TexMobject(
- "\\frac{dy}{dx} = \\frac{-x}{y}"
- )
- new_dy = VGroup(*final_form[:2])
- new_dx = VGroup(*final_form[3:5])
- new_dy.highlight(dy.get_color())
- new_dx.highlight(dx.get_color())
- new_dy.add(final_form[2])
- new_x = VGroup(*final_form[6:8])
- new_y = VGroup(*final_form[8:10])
- new_eq = final_form[5]
-
- final_form.next_to(derivative, DOWN)
- final_form.shift((eq.get_center()[0]-new_eq.get_center()[0])*RIGHT)
-
-
- self.play(*[
- ReplacementTransform(
- mover.copy(), target,
- run_time = 2,
- path_arc = np.pi/2,
+ #Address subtraction and division
+ subtraction = TexMobject("\\sin(x)", "-", "x^2")
+ decomposed_subtraction = TexMobject("\\sin(x)", "+(-1)\\cdot", "x^2")
+ pre_division = TexMobject("\\frac{\\sin(x)}{x^2}")
+ division = VGroup(
+ VGroup(*pre_division[:6]),
+ VGroup(*pre_division[6:7]),
+ VGroup(*pre_division[7:]),
+ )
+ pre_decomposed_division = TexMobject("\\sin(x)\\cdot\\frac{1}{x^2}")
+ decomposed_division = VGroup(
+ VGroup(*pre_decomposed_division[:6]),
+ VGroup(*pre_decomposed_division[6:9]),
+ VGroup(*pre_decomposed_division[9:]),
+ )
+ for mob in subtraction, decomposed_subtraction, division, decomposed_division:
+ mob.next_to(
+ VGroup(self.get_teacher(), self.get_students()[-1]),
+ UP, buff = MED_LARGE_BUFF
)
- for mover, target in [
- (dy, new_dy),
- (dx, new_dx),
- (eq, new_eq),
- (x, new_x),
- (y, new_y)
- ]
- ] + [
- morty.look_at, final_form
- ])
- self.dither(2)
-
- self.morty = morty
- self.neg_x_over_y = VGroup(*final_form[6:])
-
- def show_final_slope(self):
- morty = self.morty
- dy_dx = self.dy_dx
- coords = self.example_point_coords_mob
- x, y = coords[1][1].copy(), coords[1][3].copy()
-
- frac = self.neg_x_over_y.copy()
- frac.generate_target()
- eq = TexMobject("=")
- eq.add_background_rectangle()
- eq.next_to(dy_dx, RIGHT)
- frac.target.next_to(eq, RIGHT)
- frac.target.shift(SMALL_BUFF*DOWN)
- rect = BackgroundRectangle(frac.target)
-
- self.play(
- FadeIn(rect),
- MoveToTarget(frac),
- Write(eq),
- morty.look_at, rect,
- run_time = 2,
- )
- self.dither()
- self.play(FocusOn(coords), morty.look_at, coords)
- self.play(Indicate(coords))
- scale_factor = 1.4
- self.play(
- x.scale, scale_factor,
- x.highlight, GREEN,
- x.move_to, frac[1],
- FadeOut(frac[1]),
- y.scale, scale_factor,
- y.highlight, RED,
- y.move_to, frac[3], DOWN,
- y.shift, SMALL_BUFF*UP,
- FadeOut(frac[3]),
- morty.look_at, frac,
- run_time = 2
- )
- self.dither()
- self.play(Blink(morty))
-
-class NameImplicitDifferentation(TeacherStudentsScene):
- def construct(self):
- title = TextMobject("``Implicit differentiation''")
-
- equation = TexMobject("x^2", "+", "y^2", "=", "5^2")
- derivative = TexMobject(
- "2x\\,dx", "+", "2y\\,dy", "=", "0"
- )
- VGroup(*derivative[0][2:]).highlight(GREEN)
- VGroup(*derivative[2][2:]).highlight(RED)
- arrow = Arrow(ORIGIN, DOWN, buff = SMALL_BUFF)
- group = VGroup(title, equation, arrow, derivative)
- group.arrange_submobjects(DOWN)
- group.to_edge(UP)
- self.add(title, equation)
+ top_group = VGroup(series, simple_rules, brace)
+ combination_rules.save_state()
self.play(
- self.get_teacher().change_mode, "raise_right_hand",
- ShowCreation(arrow)
- )
- self.change_student_modes(
- *["confused"]*3,
- look_at_arg = derivative,
- added_anims = [ReplacementTransform(equation.copy(), derivative)]
- )
- self.dither(2)
- self.teacher_says(
- "Don't worry...",
- added_anims = [
- group.scale, 0.7,
- group.to_corner, UP+LEFT,
- ]
+ top_group.next_to, SPACE_HEIGHT*UP, UP,
+ combination_rules.to_edge, UP,
)
- self.change_student_modes(*["happy"]*3)
- self.dither(3)
-
-class Ladder(VMobject):
- CONFIG = {
- "height" : 4,
- "width" : 1,
- "n_rungs" : 7,
- }
- def generate_points(self):
- left_line, right_line = [
- Line(ORIGIN, self.height*UP).shift(self.width*vect/2.0)
- for vect in LEFT, RIGHT
+ pairs = [
+ (subtraction, decomposed_subtraction),
+ (division, decomposed_division)
]
- rungs = [
- Line(
- left_line.point_from_proportion(a),
- right_line.point_from_proportion(a),
+ for question, answer in pairs:
+ self.play(
+ Write(question),
+ combination_rules.fade, 0.2,
+ self.get_students()[2].change_mode, "raise_right_hand",
+ self.get_teacher().change_mode, "plain",
)
- for a in np.linspace(0, 1, 2*self.n_rungs+1)[1:-1:2]
- ]
- self.add(left_line, right_line, *rungs)
- self.center()
-
-class RelatedRatesExample(ThreeDScene):
- CONFIG = {
- "start_x" : 3.0,
- "start_y" : 4.0,
- "wall_dimensions" : [0.3, 5, 5],
- "wall_color" : color_gradient([GREY_BROWN, BLACK], 4)[1],
- "wall_center" : 1.5*LEFT+0.5*UP,
- }
- def construct(self):
- self.introduce_ladder()
- self.write_related_rates()
- self.measure_ladder()
- self.slide_ladder()
- self.ponder_question()
- self.write_equation()
- self.isolate_x_of_t()
- self.discuss_lhs_as_function()
- self.let_dt_pass()
- self.take_derivative_of_rhs()
- self.take_derivative_of_lhs()
- self.bring_back_velocity_arrows()
- self.replace_terms_in_final_form()
- self.write_final_solution()
-
- def introduce_ladder(self):
- ladder = Ladder(height = self.get_ladder_length())
-
- wall = Prism(
- dimensions = self.wall_dimensions,
- fill_color = self.wall_color,
- fill_opacity = 1,
- )
- wall.rotate(np.pi/12, UP)
- wall.shift(self.wall_center)
-
- ladder.generate_target()
- ladder.fallen = ladder.copy()
- ladder.target.rotate(self.get_ladder_angle(), LEFT)
- ladder.fallen.rotate(np.pi/2, LEFT)
- for ladder_copy in ladder.target, ladder.fallen:
- ladder_copy.rotate(-5*np.pi/12, UP)
- ladder_copy.next_to(wall, LEFT, 0, DOWN)
- ladder_copy.shift(0.8*RIGHT) ##BAD!
-
-
- self.play(
- ShowCreation(ladder, run_time = 2)
- )
- self.dither()
-
- self.play(
- DrawBorderThenFill(wall),
- MoveToTarget(ladder),
- run_time = 2
- )
- self.dither()
-
- self.ladder = ladder
-
- def write_related_rates(self):
- words = TextMobject("Related rates")
- words.to_corner(UP+RIGHT)
- self.play(Write(words))
- self.dither()
-
- self.related_rates_words = words
-
- def measure_ladder(self):
- ladder = self.ladder
- ladder_brace = self.get_ladder_brace(ladder)
-
- x_and_y_lines = self.get_x_and_y_lines(ladder)
- x_line, y_line = x_and_y_lines
-
- y_label = TexMobject("%dm"%int(self.start_y))
- y_label.next_to(y_line, LEFT, buff = SMALL_BUFF)
- y_label.highlight(y_line.get_color())
-
- x_label = TexMobject("%dm"%int(self.start_x))
- x_label.next_to(x_line, UP)
- x_label.highlight(x_line.get_color())
-
- self.play(Write(ladder_brace))
- self.dither()
- self.play(ShowCreation(y_line), Write(y_label))
- self.dither()
- self.play(ShowCreation(x_line), Write(x_label))
- self.dither(2)
- self.play(*map(FadeOut, [x_label, y_label]))
-
- self.ladder_brace = ladder_brace
- self.x_and_y_lines = x_and_y_lines
- self.numerical_x_and_y_labels = VGroup(x_label, y_label)
-
- def slide_ladder(self):
- ladder = self.ladder
- brace = self.ladder_brace
- x_and_y_lines = self.x_and_y_lines
- x_line, y_line = x_and_y_lines
-
- down_arrow, left_arrow = [
- Arrow(ORIGIN, vect, color = YELLOW, buff = 0)
- for vect in DOWN, LEFT
- ]
- down_arrow.shift(y_line.get_start()+MED_SMALL_BUFF*RIGHT)
- left_arrow.shift(x_line.get_start()+SMALL_BUFF*DOWN)
-
- # speed_label = TexMobject("1 \\text{m}/\\text{s}")
- speed_label = TexMobject("1 \\frac{\\text{m}}{\\text{s}}")
- speed_label.next_to(down_arrow, RIGHT, buff = SMALL_BUFF)
-
- q_marks = TexMobject("???")
- q_marks.next_to(left_arrow, DOWN, buff = SMALL_BUFF)
-
-
- added_anims = [
- UpdateFromFunc(brace, self.update_brace),
- UpdateFromFunc(x_and_y_lines, self.update_x_and_y_lines),
- Animation(down_arrow),
+ self.dither()
+ answer[1].highlight(GREEN)
+ self.play(
+ Transform(question, answer),
+ self.get_teacher().change_mode, "hooray",
+ self.get_students()[2].change_mode, "plain",
+ )
+ self.dither()
+ self.play(FadeOut(question))
+
+ #Monstrous expression
+ monster = TexMobject(
+ "\\Big(",
+ "e^{\\sin(x)} \\cdot",
+ "\\cos\\Big(",
+ "\\frac{1}{x^3}",
+ " + x^3",
+ "\\Big)",
+ "\\Big)^4"
+ )
+ monster.next_to(self.get_pi_creatures(), UP)
+ parts = [
+ VGroup(*monster[3][2:]),
+ VGroup(*monster[3][:2]),
+ monster[4],
+ VGroup(monster[2], monster[5]),
+ monster[1],
+ VGroup(monster[0], monster[6])
]
- self.play(ShowCreation(down_arrow))
- self.play(Write(speed_label))
- self.let_ladder_fall(ladder, *added_anims)
- self.dither()
- self.reset_ladder(ladder, *added_anims)
- self.play(ShowCreation(left_arrow))
- self.play(Write(q_marks))
- self.dither()
- self.let_ladder_fall(ladder, *added_anims)
- self.dither()
- self.reset_ladder(ladder, *added_anims)
- self.dither()
-
- self.dy_arrow = down_arrow
- self.dy_label = speed_label
- self.dx_arrow = left_arrow
- self.dx_label = q_marks
-
- def ponder_question(self):
- randy = Randolph(mode = "pondering")
- randy.flip()
- randy.to_corner(DOWN+RIGHT)
-
- self.play(FadeIn(randy))
- self.play(Blink(randy))
- self.dither()
- self.play(
- randy.change_mode, "confused",
- randy.look_at, self.ladder.get_top()
- )
- self.play(randy.look_at, self.ladder.get_bottom())
- self.play(randy.look_at, self.ladder.get_top())
- self.play(Blink(randy))
- self.dither()
- self.play(PiCreatureSays(
- randy, "Give names"
- ))
- self.play(Blink(randy))
- self.play(*map(FadeOut, [
- randy, randy.bubble, randy.bubble.content
- ]))
-
- def write_equation(self):
- self.x_and_y_labels = self.get_x_and_y_labels()
- x_label, y_label = self.x_and_y_labels
-
- equation = TexMobject(
- "x(t)", "^2", "+", "y(t)", "^2", "=", "5^2"
- )
- equation[0].highlight(GREEN)
- equation[3].highlight(RED)
- equation.next_to(self.related_rates_words, DOWN, buff = MED_LARGE_BUFF)
- equation.to_edge(RIGHT, buff = LARGE_BUFF)
-
- self.play(Write(y_label))
- self.dither()
- self.let_ladder_fall(
- self.ladder,
- y_label.shift, self.start_y*DOWN/2,
- *self.get_added_anims_for_ladder_fall()[:-1],
- rate_func = lambda t : 0.2*there_and_back(t),
- run_time = 3
- )
- self.play(FocusOn(x_label))
- self.play(Write(x_label))
- self.dither(2)
- self.play(
- ReplacementTransform(x_label.copy(), equation[0]),
- ReplacementTransform(y_label.copy(), equation[3]),
- Write(VGroup(*np.array(equation)[[1, 2, 4, 5, 6]]))
- )
- self.dither(2)
- self.let_ladder_fall(
- self.ladder,
- *self.get_added_anims_for_ladder_fall(),
- rate_func = there_and_back,
- run_time = 6
- )
+ modes = 3*["erm"] + 3*["pleading"]
+ for part, mode in zip(parts, modes):
+ self.play(
+ FadeIn(part, submobject_mode = "lagged_start"),
+ self.get_teacher().change_mode, "raise_right_hand",
+ *[
+ ApplyMethod(pi.change_mode, mode)
+ for pi in self.get_students()
+ ]
+ )
self.dither()
+ self.change_student_modes(*["happy"]*3)
+ words = map(TextMobject, [
+ "composition", "product",
+ "composition", "sum",
+ "composition"
+ ])
- self.equation = equation
-
- def isolate_x_of_t(self):
- alt_equation = TexMobject(
- "x(t)", "=", "\\big(5^2", "-", "y(t)", "^2 \\big)", "^{1/2}",
- )
- alt_equation[0].highlight(GREEN)
- alt_equation[4].highlight(RED)
- alt_equation.next_to(self.equation, DOWN, buff = MED_LARGE_BUFF)
- alt_equation.to_edge(RIGHT)
-
- randy = Randolph()
- randy.next_to(
- alt_equation, DOWN,
- buff = MED_LARGE_BUFF,
- aligned_edge = LEFT,
- )
- randy.look_at(alt_equation)
-
- find_dx_dt = TexMobject("\\text{Find } \\,", "\\frac{dx}{dt}")
- find_dx_dt.next_to(randy, RIGHT, aligned_edge = UP)
- find_dx_dt[1].highlight(GREEN)
+ for word, part in zip(words, reversed(parts)):
+ word.highlight(YELLOW)
+ word.next_to(monster, UP)
+ self.play(
+ FadeIn(word),
+ part.scale_in_place, 1.2,
+ part.highlight, YELLOW
+ )
+ self.dither()
+ self.play(*map(FadeOut, [word, part]))
+ self.play(FadeOut(parts[0]))
- self.play(FadeIn(randy))
+ #Bring back combinations
self.play(
- randy.change_mode, "raise_right_hand",
- randy.look_at, alt_equation,
+ combination_rules.restore,
*[
- ReplacementTransform(
- self.equation[i].copy(),
- alt_equation[j],
- path_arc = np.pi/2,
- run_time = 3,
- rate_func = squish_rate_func(
- smooth, j/12.0, (j+6)/12.0
- )
- )
- for i, j in enumerate([0, 6, 3, 4, 5, 1, 2])
+ ApplyMethod(pi_creature.change_mode, "pondering")
+ for pi_creature in self.get_pi_creatures()
]
)
- self.play(Blink(randy))
- self.dither()
- self.play(
- Write(find_dx_dt),
- randy.change_mode, "pondering",
- randy.look_at, find_dx_dt,
- )
- self.let_ladder_fall(
- self.ladder, *self.get_added_anims_for_ladder_fall(),
- run_time = 8,
- rate_func = there_and_back
- )
- self.play(*map(FadeOut, [
- randy, find_dx_dt, alt_equation
- ]))
- self.dither()
-
- def discuss_lhs_as_function(self):
- equation = self.equation
- lhs = VGroup(*equation[:5])
- brace = Brace(lhs, DOWN)
- function_of_time = brace.get_text(
- "Function of time"
- )
- constant_words = TextMobject(
- """that happens to
- be constant"""
- )
- constant_words.highlight(YELLOW)
- constant_words.next_to(function_of_time, DOWN)
-
- derivative = TexMobject(
- "\\frac{d\\left(x(t)^2 + y(t)^2 \\right)}{dt}"
- )
- derivative.next_to(equation, DOWN, buff = MED_LARGE_BUFF)
- derivative.shift( ##Align x terms
- equation[0][0].get_center()[0]*RIGHT-\
- derivative[2].get_center()[0]*RIGHT
- )
- derivative_interior = lhs.copy()
- derivative_interior.move_to(VGroup(*derivative[2:13]))
- derivative_scaffold = VGroup(
- *list(derivative[:2])+list(derivative[13:])
- )
-
- self.play(
- GrowFromCenter(brace),
- Write(function_of_time)
- )
- self.dither()
- self.play(Write(constant_words))
- self.let_ladder_fall(
- self.ladder, *self.get_added_anims_for_ladder_fall(),
- run_time = 6,
- rate_func = lambda t : 0.5*there_and_back(t)
- )
- self.dither()
- self.play(*map(FadeOut, [
- brace, constant_words, function_of_time
- ]))
- self.play(
- ReplacementTransform(lhs.copy(), derivative_interior),
- Write(derivative_scaffold),
- )
- self.dither()
-
- self.derivative = VGroup(
- derivative_scaffold, derivative_interior
- )
-
- def let_dt_pass(self):
- dt_words = TextMobject("After", "$dt$", "seconds...")
- dt_words.to_corner(UP+LEFT)
- dt = dt_words[1]
- dt.highlight(YELLOW)
- dt_brace = Brace(dt, buff = SMALL_BUFF)
- dt_brace_text = dt_brace.get_text("Think 0.01", buff = SMALL_BUFF)
- dt_brace_text.highlight(dt.get_color())
-
- shadow_ladder = self.ladder.copy()
- shadow_ladder.fade(0.5)
-
- x_line, y_line = self.x_and_y_lines
- y_top = y_line.get_start()
- x_left = x_line.get_start()
-
- self.play(Write(dt_words, run_time = 2))
- self.play(
- GrowFromCenter(dt_brace),
- Write(dt_brace_text, run_time = 2)
- )
- self.play(*map(FadeOut, [
- self.dy_arrow, self.dy_label,
- self.dx_arrow, self.dx_label,
- ]))
- self.add(shadow_ladder)
- self.let_ladder_fall(
- self.ladder, *self.get_added_anims_for_ladder_fall(),
- rate_func = lambda t : 0.1*smooth(t),
- run_time = 1
- )
-
- new_y_top = y_line.get_start()
- new_x_left = x_line.get_start()
-
- dy_line = Line(y_top, new_y_top)
- dy_brace = Brace(dy_line, RIGHT, buff = SMALL_BUFF)
- dy_label = dy_brace.get_text("$dy$", buff = SMALL_BUFF)
- dy_label.highlight(RED)
-
- dx_line = Line(x_left, new_x_left)
- dx_brace = Brace(dx_line, DOWN, buff = SMALL_BUFF)
- dx_label = dx_brace.get_text("$dx$")
- dx_label.highlight(GREEN)
-
- VGroup(dy_line, dx_line).highlight(YELLOW)
+ self.dither(2)
- for line, brace, label in (dy_line, dy_brace, dy_label), (dx_line, dx_brace, dx_label):
- self.play(
- ShowCreation(line),
- GrowFromCenter(brace),
- Write(label),
- run_time = 1
+class DampenedSpring(Scene):
+ def construct(self):
+ compact_spring, extended_spring = [
+ ParametricFunction(
+ lambda t : (t/denom)*RIGHT+np.sin(t)*UP+np.cos(t)*OUT,
+ t_max = 12*np.pi,
+ num_anchor_points = 100,
+ color = GREY,
+ ).shift(3*LEFT)
+ for denom in 12.0, 2.0
+ ]
+ for spring in compact_spring, extended_spring:
+ spring.scale(0.5)
+ spring.rotate(np.pi/6, UP)
+ spring.highlight(GREY)
+ spring.shift(-spring.points[0] + 3*LEFT)
+
+ moving_spring = compact_spring.copy()
+
+ def update_spring(spring, a):
+ spring.interpolate(
+ compact_spring,
+ extended_spring,
+ 0.5*(np.exp(-4*a)*np.cos(40*a)+1)
)
- self.dither()
- self.play(Indicate(self.derivative[1]))
- self.dither()
-
- self.dy_group = VGroup(dy_line, dy_brace, dy_label)
- self.dx_group = VGroup(dx_line, dx_brace, dx_label)
- self.shadow_ladder = shadow_ladder
-
- def take_derivative_of_rhs(self):
- derivative = self.derivative
- equals_zero = TexMobject("= 0")
- equals_zero.next_to(derivative)
-
- rhs = self.equation[-1]
-
- self.play(Write(equals_zero))
- self.dither()
- self.play(FocusOn(rhs))
- self.play(Indicate(rhs))
- self.dither()
- self.reset_ladder(
- self.ladder,
- *self.get_added_anims_for_ladder_fall()+[
- Animation(self.dy_group),
- Animation(self.dx_group),
- ],
- rate_func = there_and_back,
- run_time = 3
- )
- self.dither()
- self.equals_zero = equals_zero
-
- def take_derivative_of_lhs(self):
- derivative_scaffold, equation = self.derivative
- equals_zero_copy = self.equals_zero.copy()
-
- lhs_derivative = TexMobject(
- "2", "x(t)", "\\frac{dx}{dt}", "+",
- "2", "y(t)", "\\frac{dy}{dt}",
- )
- lhs_derivative[1].highlight(GREEN)
- VGroup(*lhs_derivative[2][:2]).highlight(GREEN)
- lhs_derivative[5].highlight(RED)
- VGroup(*lhs_derivative[6][:2]).highlight(RED)
- lhs_derivative.next_to(
- derivative_scaffold, DOWN,
- aligned_edge = RIGHT,
- buff = MED_LARGE_BUFF
+ equation = TexMobject(
+ "\\text{Length} = 2 + e^{-4t}\\cos(20t)"
)
- equals_zero_copy.next_to(lhs_derivative, RIGHT)
+ equation.to_edge(UP)
- pairs = [
- (0, 1), (1, 0), #x^2 -> 2x
- (2, 3), (3, 5), (4, 4), #+y^2 -> +2y
- ]
- def perform_replacement(index_pairs):
- self.play(*[
- ReplacementTransform(
- equation[i].copy(), lhs_derivative[j],
- path_arc = np.pi/2,
- run_time = 2
- )
- for i, j in index_pairs
- ])
- perform_replacement(pairs[:2])
- self.play(Write(lhs_derivative[2]))
- self.dither()
- self.play(Indicate(
- VGroup(
- *list(lhs_derivative[:2])+\
- list(lhs_derivative[2][:2])
- ),
- run_time = 2
+ self.add(moving_spring, equation)
+ self.play(UpdateFromAlphaFunc(
+ moving_spring, update_spring, run_time = 10,
+ rate_func = None
))
- self.play(Indicate(VGroup(*lhs_derivative[2][3:])))
- self.dither(2)
- perform_replacement(pairs[2:])
- self.play(Write(lhs_derivative[6]))
self.dither()
- self.play(FocusOn(self.equals_zero))
- self.play(ReplacementTransform(
- self.equals_zero.copy(),
- equals_zero_copy
- ))
- self.dither(2)
-
- lhs_derivative.add(equals_zero_copy)
- self.lhs_derivative = lhs_derivative
-
- def bring_back_velocity_arrows(self):
- dx_dy_group = VGroup(self.dx_group, self.dy_group)
- arrow_group = VGroup(
- self.dy_arrow, self.dy_label,
- self.dx_arrow, self.dx_label,
- )
- ladder_fall_args = [self.ladder] + self.get_added_anims_for_ladder_fall()
-
+class ComingUp(Scene):
+ def construct(self):
+ rect = Rectangle(height = 9, width = 16)
+ rect.set_stroke(WHITE)
+ rect.scale_to_fit_height(2*SPACE_HEIGHT-2)
+ title = TextMobject("Coming up...")
+ title.to_edge(UP)
+ rect.next_to(title, DOWN)
- self.reset_ladder(*ladder_fall_args + [
- FadeOut(dx_dy_group),
- FadeOut(self.derivative),
- FadeOut(self.equals_zero),
- self.lhs_derivative.shift, 2*UP,
- ])
- self.remove(self.shadow_ladder)
- self.play(FadeIn(arrow_group))
- self.let_ladder_fall(*ladder_fall_args)
- self.dither()
- self.reset_ladder(*ladder_fall_args)
+ self.play(Write(title))
+ self.play(ShowCreation(rect))
self.dither()
- def replace_terms_in_final_form(self):
- x_label, y_label = self.x_and_y_labels
- num_x_label, num_y_label = self.numerical_x_and_y_labels
+class PreSumRuleDiscussion(Scene):
+ def construct(self):
+ title = TextMobject("Sum rule")
+ title.to_edge(UP)
+ self.add(title)
- new_lhs_derivative = TexMobject(
- "2", "(%d)"%int(self.start_x), "\\frac{dx}{dt}", "+",
- "2", "(%d)"%int(self.start_y), "(-1)",
- "= 0"
- )
- new_lhs_derivative[1].highlight(GREEN)
- VGroup(*new_lhs_derivative[2][:2]).highlight(GREEN)
- new_lhs_derivative[5].highlight(RED)
- new_lhs_derivative.next_to(
- self.lhs_derivative, DOWN,
- buff = MED_LARGE_BUFF,
- aligned_edge = RIGHT
- )
- def fill_in_equation_part(*indices):
+ specific = TexMobject(
+ "\\frac{d}{dx}(", "\\sin(x)", "+", "x^2", ")",
+ "=", "\\cos(x)", "+", "2x"
+ )
+ general = TexMobject(
+ "\\frac{d}{dx}(", "g(x)", "+", "h(x)", ")",
+ "=", "\\frac{dg}{dx}", "+", "\\frac{dh}{dx}"
+ )
+ for formula in specific, general:
+ formula[1].highlight(SINE_COLOR)
+ formula[6].highlight(SINE_COLOR)
+ formula[3].highlight(X_SQUARED_COLOR)
+ formula[8].highlight(X_SQUARED_COLOR)
+ VGroup(specific, general).arrange_submobjects(DOWN, buff = LARGE_BUFF)
+
+ #Add on rules
+ self.add(specific)
+ for i in 0, 4, 5:
+ self.add(general[i])
+ self.dither(2)
+ for indices in [(1, 2, 3), (6,), (7, 8)]:
self.play(*[
ReplacementTransform(
- self.lhs_derivative[i].copy(),
- new_lhs_derivative[i],
- run_time = 2
+ specific[i].copy(), general[i]
)
for i in indices
])
-
- self.play(FadeOut(y_label), FadeIn(num_y_label))
- fill_in_equation_part(3, 4, 5)
- self.play(FadeOut(x_label), FadeIn(num_x_label))
- for indices in [(0, 1), (6,), (2, 7)]:
- fill_in_equation_part(*indices)
self.dither()
- self.dither()
-
- self.new_lhs_derivative = new_lhs_derivative
- def write_final_solution(self):
- solution = TexMobject(
- "\\frac{dx}{dt} = \\frac{4}{3}"
- )
- for i in 0, 1, -1:
- solution[i].highlight(GREEN)
- solution[-3].highlight(RED)
- solution.next_to(
- self.new_lhs_derivative, DOWN,
- buff = MED_LARGE_BUFF,
- aligned_edge = RIGHT
- )
+ #Highlight parts
+ for i in 1, 3, -1, 6, 8:
+ if i < 0:
+ self.dither()
+ else:
+ part = specific[i]
+ self.play(
+ part.highlight, YELLOW,
+ part.scale_in_place, 1.2,
+ rate_func = there_and_back
+ )
+ self.dither()
- box = Rectangle(color = YELLOW)
- box.replace(solution)
- box.scale_in_place(1.5)
+class SumRule(GraphScene):
+ CONFIG = {
+ "x_labeled_nums" : [],
+ "y_labeled_nums" : [],
+ "y_axis_label" : "",
+ "x_max" : 4,
+ "x_axis_width" : 2*SPACE_WIDTH,
+ "y_max" : 3,
+ "graph_origin" : 2.5*DOWN + 2.5*LEFT,
+ "graph_label_x_value" : 1.5,
+ "example_input" : 0.5,
+ "example_input_string" : "0.5",
+ "dx" : 0.05,
+ "v_lines_x_min" : -1,
+ "v_lines_x_max" : 2,
+ "graph_scale_factor" : 2,
+ "tex_scale_factor" : 0.8,
+ }
+ def construct(self):
+ self.write_function()
+ self.add_graphs()
+ self.zoom_in_on_graph()
+ self.show_example_stacking()
+ self.show_df()
+ self.expand_derivative()
+
+ def write_function(self):
+ func_mob = TexMobject("f(x)", "=", "\\sin(x)", "+", "x^2")
+ func_mob.scale(self.tex_scale_factor)
+ func_mob.highlight_by_tex("f(x)", SUM_COLOR)
+ func_mob.highlight_by_tex("\\sin(x)", SINE_COLOR)
+ func_mob.highlight_by_tex("x^2", X_SQUARED_COLOR)
+ func_mob.to_corner(UP+LEFT)
+ self.add(func_mob)
+
+ self.func_mob = func_mob
+
+ def add_graphs(self):
+ self.setup_axes()
+ sine_graph = self.get_graph(np.sin, color = SINE_COLOR)
+ parabola = self.get_graph(lambda x : x**2, color = X_SQUARED_COLOR)
+ sum_graph = self.get_graph(
+ lambda x : np.sin(x) + x**2,
+ color = SUM_COLOR
+ )
+ sine_label = self.get_graph_label(
+ sine_graph, "\\sin(x)",
+ x_val = self.graph_label_x_value,
+ direction = UP+RIGHT,
+ buff = 0,
+ )
+ sine_label.scale_in_place(self.tex_scale_factor)
+ parabola_label = self.get_graph_label(
+ parabola, "x^2", x_val = self.graph_label_x_value,
+ )
+ parabola_label.scale_in_place(self.tex_scale_factor)
+
+ graphs = VGroup(sine_graph, parabola)
+ labels = VGroup(sine_label, parabola_label)
+ for label in labels:
+ label.add_background_rectangle()
- self.play(Write(solution))
- self.dither()
- self.play(ShowCreation(box))
+ for graph, label in zip(graphs, labels):
+ self.play(
+ ShowCreation(graph),
+ Write(label)
+ )
self.dither()
- #########
-
- def get_added_anims_for_ladder_fall(self):
- return [
- UpdateFromFunc(self.ladder_brace, self.update_brace),
- UpdateFromFunc(self.x_and_y_lines, self.update_x_and_y_lines),
- UpdateFromFunc(self.x_and_y_labels, self.update_x_and_y_labels),
+ num_lines = (self.v_lines_x_max-self.v_lines_x_min)/self.dx
+ sine_v_lines, parabox_v_lines = v_line_sets = [
+ self.get_vertical_lines_to_graph(
+ graph,
+ x_min = self.v_lines_x_min,
+ x_max = self.v_lines_x_max,
+ num_lines = num_lines,
+ stroke_width = 2
+ )
+ for graph in graphs
]
+ sine_v_lines.shift(0.02*RIGHT)
+ for v_lines in v_line_sets:
+ self.play(ShowCreation(v_lines), Animation(labels))
+ self.dither()
+ self.play(*it.chain(
+ [
+ ApplyMethod(l2.move_to, l1.get_top(), DOWN)
+ for l1, l2, in zip(*v_line_sets)
+ ],
+ [graph.fade for graph in graphs],
+ [Animation(labels)]
+ ))
+ self.dither()
- def let_ladder_fall(self, ladder, *added_anims, **kwargs):
- kwargs["run_time"] = kwargs.get("run_time", self.start_y)
- kwargs["rate_func"] = kwargs.get("rate_func", None)
- self.play(
- Transform(ladder, ladder.fallen),
- *added_anims,
- **kwargs
- )
-
- def reset_ladder(self, ladder, *added_anims, **kwargs):
- kwargs["run_time"] = kwargs.get("run_time", 2)
- self.play(
- Transform(ladder, ladder.target),
- *added_anims,
- **kwargs
- )
-
- def update_brace(self, brace):
- Transform(
- brace, self.get_ladder_brace(self.ladder)
- ).update(1)
- return brace
-
- def update_x_and_y_lines(self, x_and_y_lines):
- Transform(
- x_and_y_lines,
- self.get_x_and_y_lines(self.ladder)
- ).update(1)
- return x_and_y_lines
-
- def update_x_and_y_labels(self, x_and_y_labels):
- Transform(
- x_and_y_labels,
- self.get_x_and_y_labels()
- ).update(1)
- return x_and_y_labels
-
- def get_ladder_brace(self, ladder):
- vect = rotate_vector(LEFT, -self.get_ladder_angle())
- brace = Brace(ladder, vect)
- length_string = "%dm"%int(self.get_ladder_length())
- length_label = brace.get_text(
- length_string, use_next_to = False
- )
- brace.add(length_label)
- brace.length_label = length_label
- return brace
-
- def get_x_and_y_labels(self):
- x_line, y_line = self.x_and_y_lines
-
- x_label = TexMobject("x(t)")
- x_label.highlight(x_line.get_color())
- x_label.next_to(x_line, DOWN, buff = SMALL_BUFF)
-
- y_label = TexMobject("y(t)")
- y_label.highlight(y_line.get_color())
- y_label.next_to(y_line, LEFT, buff = SMALL_BUFF)
-
- return VGroup(x_label, y_label)
-
- def get_x_and_y_lines(self, ladder):
- bottom_point, top_point = np.array(ladder[1].get_start_and_end())
- interim_point = top_point[0]*RIGHT + bottom_point[1]*UP
- interim_point += SMALL_BUFF*DOWN
- y_line = Line(top_point, interim_point)
- y_line.highlight(RED)
- x_line = Line(bottom_point, interim_point)
- x_line.highlight(GREEN)
-
- return VGroup(x_line, y_line)
-
- def get_ladder_angle(self):
- if hasattr(self, "ladder"):
- c1 = self.ladder.get_corner(UP+RIGHT)
- c2 = self.ladder.get_corner(DOWN+LEFT)
- vect = c1-c2
- return np.pi/2 - angle_of_vector(vect)
- else:
- return np.arctan(self.start_x/self.start_y)
-
- def get_ladder_length(self):
- return np.linalg.norm([self.start_x, self.start_y])
-
-class LightweightLadderScene(RelatedRatesExample):
- CONFIG = {
- "skip_animations" : True
- }
- def construct(self):
- self.introduce_ladder()
- self.measure_ladder()
- self.add(self.numerical_x_and_y_labels)
+ self.play(ShowCreation(sum_graph))
+ self.dither()
-class LightweightCircleExample(SlopeOfCircleExample):
- CONFIG = {
- "skip_animations" : True,
- "plane_kwargs" : {
- "x_radius" : 5,
- "y_radius" : 5,
- "space_unit_to_x_unit" : SPACE_UNIT_TO_PLANE_UNIT,
- "space_unit_to_y_unit" : SPACE_UNIT_TO_PLANE_UNIT,
- },
- }
- def construct(self):
- self.setup_plane()
- self.introduce_circle()
- self.talk_through_pythagorean_theorem()
- self.draw_example_slope()
+ self.sum_graph = sum_graph
+ self.parabola = parabola
+ self.sine_graph = sine_graph
+ self.graph_labels = labels
+ self.v_line_sets = v_line_sets
- self.remove(self.circle_equation)
- self.remove(self.slope_word)
- self.example_point_coords_mob.scale(
- 1.5, about_point = self.example_point_coords_mob.get_corner(UP+RIGHT)
+ def zoom_in_on_graph(self):
+ graph_parts = VGroup(
+ self.axes,
+ self.sine_graph, self.parabola, self.sum_graph,
+ *self.v_line_sets
)
- self.plane.axis_labels[0].shift(3*LEFT)
+ graph_parts.remove(self.func_mob, *self.graph_labels)
+ graph_parts.generate_target()
+ self.graph_labels.generate_target()
+ for mob in graph_parts, self.graph_labels:
+ mob.target.scale(
+ self.graph_scale_factor,
+ about_point = self.graph_origin,
+ )
+ for mob in self.graph_labels.target:
+ mob.scale(
+ 1./self.graph_scale_factor,
+ about_point = mob.get_bottom()
+ )
+ mob.shift_onto_screen()
+ self.play(*map(MoveToTarget, [
+ graph_parts, self.graph_labels
+ ]))
+ self.dither()
-class CompareLadderAndCircle(PiCreatureScene, ThreeDScene):
- def construct(self):
- self.introduce_both_scenes()
- self.show_derivatives()
- self.comment_on_ladder_derivative()
- self.comment_on_circle_derivative()
-
- def introduce_both_scenes(self):
- ladder_scene = LightweightLadderScene()
- ladder_mobs = VGroup(*ladder_scene.get_top_level_mobjects())
- circle_scene = LightweightCircleExample()
- circle_mobs = VGroup(*circle_scene.get_top_level_mobjects())
- for mobs, vect in (ladder_mobs, LEFT), (circle_mobs, RIGHT):
- mobs.scale_to_fit_height(SPACE_HEIGHT-MED_LARGE_BUFF)
- mobs.next_to(
- self.pi_creature.get_corner(UP+vect), UP,
+ def show_example_stacking(self):
+ v_line_sets = self.v_line_sets
+ num_lines = len(v_line_sets[0])
+ example_v_lines, nudged_v_lines = [
+ VGroup(*[v_lines[index] for v_lines in v_line_sets])
+ for index in (num_lines/2, num_lines/2+1)
+ ]
+ for line in nudged_v_lines:
+ line.save_state()
+ sine_lines, parabola_lines = [
+ VGroup(example_v_lines[i], nudged_v_lines[i])
+ for i in 0, 1
+ ]
+ faders = VGroup(*filter(
+ lambda line : line not in example_v_lines,
+ it.chain(*v_line_sets)
+ ))
+ label_groups = []
+ for line, tex, vect in zip(sine_lines, ["", "+dx"], [LEFT, RIGHT]):
+ dot = Dot(line.get_bottom(), radius = 0.03, color = YELLOW)
+ label = TexMobject(
+ "x=" + str(self.example_input) + tex
+ )
+ label.next_to(dot, DOWN+vect, buff = MED_LARGE_BUFF)
+ arrow = Arrow(
+ label.get_corner(UP-vect), dot,
+ buff = SMALL_BUFF,
+ color = WHITE,
+ tip_length = 0.1
+ )
+ label_groups.append(VGroup(label, arrow, dot))
+
+ line_tex_direction_triplets = [
+ (sine_lines[0], "\\sin(0.5)", LEFT),
+ (sine_lines[1], "\\sin(0.5+dx)", RIGHT),
+ (parabola_lines[0], "(0.5)^2", LEFT),
+ (parabola_lines[1], "(0.5+dx)^2", RIGHT),
+ ]
+ for line, tex, direction in line_tex_direction_triplets:
+ line.brace = Brace(
+ line, direction,
buff = SMALL_BUFF,
- aligned_edge = -vect
+ min_num_quads = 2,
+ )
+ line.brace.highlight(line.get_color())
+ line.brace.add_background_rectangle()
+ line.brace_text = line.brace.get_text("$%s$"%tex)
+ line.brace_text.scale(
+ self.tex_scale_factor,
+ about_point = line.brace_text.get_edge_center(-direction)
+ )
+ line.brace_text.add_background_rectangle()
+ line.brace_anim = MaintainPositionRelativeTo(
+ VGroup(line.brace, line.brace_text), line
)
- ladder_mobs.save_state()
- ladder_mobs.fade(1)
- ladder_mobs.rotate_in_place(np.pi/3, UP)
+ ##Look at example lines
self.play(
- self.pi_creature.change_mode, "raise_right_hand",
- self.pi_creature.look_at, ladder_mobs,
- ApplyMethod(ladder_mobs.restore, run_time = 2)
+ example_v_lines.set_stroke, None, 4,
+ faders.fade,
+ Animation(self.graph_labels),
+ Write(label_groups[0]),
)
+ for line in example_v_lines:
+ line.save_state()
+ self.dither()
self.play(
- self.pi_creature.change_mode, "raise_left_hand",
- self.pi_creature.look_at, circle_mobs,
- Write(circle_mobs, run_time = 2)
+ GrowFromCenter(sine_lines[0].brace),
+ Write(sine_lines[0].brace_text),
)
- self.dither(2)
+ self.dither()
self.play(
- circle_mobs.to_edge, RIGHT,
- ladder_mobs.to_edge, LEFT,
- )
-
- def show_derivatives(self):
- equation = TexMobject(
- "x", "^2", "+", "y", "^2", "= 5^2"
+ sine_lines[0].shift, UP+4*LEFT,
+ sine_lines[0].brace_anim,
+ parabola_lines[0].move_to, sine_lines[0], DOWN
)
- derivative = TexMobject(
- "2", "x", "dx", "+", "2", "y", "dy", "=0"
+ self.dither()
+ parabola_lines[0].brace_anim.update(1)
+ self.play(
+ GrowFromCenter(parabola_lines[0].brace),
+ Write(parabola_lines[0].brace_text),
)
- self.color_equations(equation, derivative)
- equation.to_edge(UP)
- equation.shift(MED_LARGE_BUFF*LEFT)
- derivative.next_to(equation, DOWN, buff = MED_LARGE_BUFF)
+ self.dither()
+ self.play(*it.chain(*[
+ [line.restore, line.brace_anim]
+ for line in example_v_lines
+ ]))
+ ## Nudged_lines
self.play(
- Write(equation),
- self.pi_creature.change_mode, "plain",
- self.pi_creature.look_at, equation
+ Write(label_groups[1]),
+ *it.chain(*[
+ [line.restore, line.set_stroke, None, 4]
+ for line in nudged_v_lines
+ ])
)
self.dither()
- self.play(*[
- ReplacementTransform(
- equation[i].copy(), derivative[j],
- path_arc = np.pi/2
+ for line in nudged_v_lines:
+ self.play(
+ GrowFromCenter(line.brace),
+ Write(line.brace_text)
)
- for i, j in enumerate([1, 0, 3, 5, 4, 7])
- ]+[
- Write(derivative[j])
- for j in 2, 6
- ])
- self.play(
- self.pi_creature.change_mode, "pondering",
- self.pi_creature.look_at, derivative
- )
self.dither()
- self.equation = equation
- self.derivative = derivative
+ self.sine_lines = sine_lines
+ self.parabola_lines = parabola_lines
- def comment_on_ladder_derivative(self):
- equation = self.equation
- derivative = self.derivative
+ def show_df(self):
+ sine_lines = self.sine_lines
+ parabola_lines = self.parabola_lines
- time_equation = TexMobject(
- "x(t)", "^2", "+", "y(t)", "^2", "= 5^2"
+ df, equals, d_sine, plus, d_x_squared = deriv_mob = TexMobject(
+ "df", "=", "d(\\sin(x))", "+", "d(x^2)"
)
- time_derivative = TexMobject(
- "2", "x(t)", "\\frac{dx}{dt}", "+",
- "2", "y(t)", "\\frac{dy}{dt}", "=0"
+ df.highlight(SUM_COLOR)
+ d_sine.highlight(SINE_COLOR)
+ d_x_squared.highlight(X_SQUARED_COLOR)
+ deriv_mob.scale(self.tex_scale_factor)
+ deriv_mob.next_to(
+ self.func_mob, DOWN,
+ buff = MED_LARGE_BUFF,
+ aligned_edge = LEFT
)
- self.color_equations(time_equation, time_derivative)
- time_equation.move_to(equation)
- time_derivative.move_to(derivative, UP)
-
- brace = Brace(time_derivative)
- brace_text = brace.get_text("A rate")
+ for submob in deriv_mob:
+ submob.add_to_back(BackgroundRectangle(submob))
- equation.save_state()
- derivative.save_state()
-
- self.play(Transform(equation, time_equation))
- self.dither()
- self.play(Transform(derivative, time_derivative))
+ df_lines = self.show_difference(parabola_lines, df, equals)
self.dither()
- self.play(GrowFromCenter(brace))
- self.play(Write(brace_text))
- self.change_mode("hooray")
- self.dither(2)
+ self.play(FadeOut(df_lines))
self.play(
- equation.restore,
- derivative.restore,
- FadeOut(brace),
- FadeOut(brace_text),
- self.pi_creature.change_mode, "confused"
+ parabola_lines[0].shift,
+ (parabola_lines[1].get_bottom()[1]-parabola_lines[0].get_bottom()[1])*UP,
+ parabola_lines[0].brace_anim
)
+ d_sine_lines = self.show_difference(sine_lines, d_sine, plus)
+ d_x_squared_lines = self.show_difference(parabola_lines, d_x_squared, VGroup())
self.dither()
- def comment_on_circle_derivative(self):
- derivative = self.derivative
- dx = derivative.get_part_by_tex("dx")
- dy = derivative.get_part_by_tex("dy")
-
- for mob in dx, dy:
- brace = Brace(mob)
- brace.next_to(mob[0], DOWN, buff = SMALL_BUFF, aligned_edge = LEFT)
- text = brace.get_text("No $dt$", buff = SMALL_BUFF)
- text.highlight(YELLOW)
-
- self.play(
- GrowFromCenter(brace),
- Write(text)
- )
- self.dither()
-
- self.play(
- self.pi_creature.change_mode, "pondering",
- self.pi_creature.look, DOWN+LEFT
- )
- self.dither(2)
-
- #######
+ self.deriv_mob = deriv_mob
+ self.d_sine_lines = d_sine_lines
+ self.d_x_squared_lines = d_x_squared_lines
- def create_pi_creature(self):
- self.pi_creature = Mortimer().to_edge(DOWN)
- return self.pi_creature
+ def show_difference(self, v_lines, target_tex, added_tex):
+ distance = v_lines[1].get_top()[1]-v_lines[0].get_top()[1]
+ h_lines = VGroup(*[
+ DashedLine(ORIGIN, 2*RIGHT, stroke_width = 3)
+ for x in range(2)
+ ])
+ h_lines.arrange_submobjects(DOWN, buff = distance)
+ h_lines.move_to(v_lines[1].get_top(), UP+RIGHT)
- def color_equations(self, equation, derivative):
- for mob in equation[0], derivative[1]:
- mob.highlight(GREEN)
- for mob in equation[3], derivative[5]:
- mob.highlight(RED)
+ brace = Brace(h_lines, LEFT)
+ brace_text = target_tex.copy()
+ brace_text.next_to(brace, LEFT)
-class TwoVariableFunctionAndDerivative(SlopeOfCircleExample):
- CONFIG = {
- "zoomed_canvas_corner" : DOWN+RIGHT,
- "zoomed_canvas_space_shape" : (3, 4),
- }
- def construct(self):
- self.setup_plane()
- self.write_equation()
- self.show_example_point()
- self.shift_example_point((4, 4))
- self.shift_example_point((3, 3))
- self.shift_example_point(self.example_point)
- self.take_derivative_symbolically()
- self.show_dx_dy_step()
- self.plug_in_example_values()
- self.ask_about_equalling_zero()
- self.show_tangent_step()
- self.point_out_equalling_zero()
- self.show_tangent_line()
-
- def write_equation(self):
- equation = TexMobject("x", "^2", "+", "y", "^2")
- equation.add_background_rectangle()
-
- brace = Brace(equation, UP, buff = SMALL_BUFF)
- s_expression = self.get_s_expression("x", "y")
- s_rect, s_of_xy = s_expression
- s, xy = s_of_xy
- s_expression.next_to(brace, UP, buff = SMALL_BUFF)
-
- group = VGroup(equation, s_expression, brace)
- group.shift(2*SPACE_WIDTH*LEFT/3)
- group.to_edge(UP, buff = MED_SMALL_BUFF)
-
- s.save_state()
- s.next_to(brace, UP)
-
-
- self.play(Write(equation))
- self.play(GrowFromCenter(brace))
- self.play(Write(s))
+ self.play(ShowCreation(h_lines))
+ self.play(GrowFromCenter(brace), Write(brace_text))
self.dither()
self.play(
- FadeIn(s_rect),
- s.restore,
- GrowFromCenter(xy)
+ ReplacementTransform(brace_text.copy(), target_tex),
+ Write(added_tex)
)
- self.dither()
+ return VGroup(h_lines, brace, brace_text)
- self.equation = equation
- self.s_expression = s_expression
-
- def show_example_point(self):
- point = self.plane.num_pair_to_point(self.example_point)
- dot = Dot(point, color = self.example_color)
- new_s_expression = self.get_s_expression(*self.example_point)
- new_s_expression.next_to(dot, UP+RIGHT, buff = 0)
- new_s_expression.highlight(self.example_color)
- equals_25 = TexMobject("=%d"%int(np.linalg.norm(self.example_point)**2))
- equals_25.highlight(YELLOW)
- equals_25.next_to(new_s_expression, RIGHT, align_using_submobjects = True)
- equals_25.add_background_rectangle()
+ def expand_derivative(self):
+ expanded_deriv = TexMobject(
+ "df", "=", "\\cos(x)", "\\,dx", "+", "2x", "\\,dx"
+ )
+ expanded_deriv.highlight_by_tex("df", SUM_COLOR)
+ VGroup(*expanded_deriv[2:4]).highlight(SINE_COLOR)
+ VGroup(*expanded_deriv[5:7]).highlight(X_SQUARED_COLOR)
+ expanded_deriv.scale(self.tex_scale_factor)
+ expanded_deriv.next_to(
+ self.deriv_mob, DOWN,
+ buff = MED_LARGE_BUFF,
+ aligned_edge = LEFT
+ )
+ background_rect = BackgroundRectangle(expanded_deriv)
- circle = Circle(
- radius = self.circle_radius*self.plane.space_unit_to_x_unit,
- color = self.circle_color,
+ rearranged_deriv = TexMobject(
+ "{df \\over", "dx}", "=", "\\cos(x)", "+", "2x"
)
+ rearranged_deriv[0].highlight(SUM_COLOR)
+ rearranged_deriv[3].highlight(SINE_COLOR)
+ rearranged_deriv[5].highlight(X_SQUARED_COLOR)
+ rearranged_deriv.scale(self.tex_scale_factor)
+ rearranged_deriv.move_to(expanded_deriv, UP+LEFT)
+ deriv_target_indices = [0, 2, 3, 1, 4, 5, 1]
self.play(
- ReplacementTransform(
- self.s_expression.copy(),
- new_s_expression
+ FadeIn(
+ background_rect,
+ rate_func = squish_rate_func(smooth, 0.6, 1)
),
- ShowCreation(dot)
+ Write(expanded_deriv)
)
- self.play(ShowCreation(circle), Animation(dot))
- self.play(Write(equals_25))
self.dither()
- self.example_point_dot = dot
- self.example_point_label = VGroup(
- new_s_expression, equals_25
- )
+ tex_group_pairs = [
+ ("\\cos(0.5)dx", self.d_sine_lines),
+ ("2(0.5)dx", self.d_x_squared_lines),
+ ]
+ def indicate(mob):
+ self.play(
+ mob.highlight, YELLOW,
+ mob.scale_in_place, 1.2,
+ rate_func = there_and_back
+ )
+ for tex, group in tex_group_pairs:
+ old_label = group[-1]
+ new_label = TexMobject(tex)
+ pre_dx = VGroup(*new_label[:-2])
+ dx = VGroup(*new_label[-2:])
+ new_label.add_background_rectangle()
+ new_label.scale(self.tex_scale_factor)
+ new_label.move_to(old_label, RIGHT)
+ new_label.highlight(old_label.get_color())
+
+ self.play(FocusOn(old_label))
+ indicate(old_label)
+ self.dither()
+ self.play(FadeOut(old_label))
+ self.play(FadeIn(new_label))
+ self.dither()
+ indicate(dx)
+ self.dither()
+ indicate(pre_dx)
+ self.dither()
+ self.dither()
+ self.play(*[
+ Transform(
+ expanded_deriv[i], rearranged_deriv[j],
+ path_arc = -np.pi/2
+ )
+ for i, j in enumerate(deriv_target_indices)
+ ])
+ self.dither()
- def shift_example_point(self, coords):
- point = self.plane.num_pair_to_point(coords)
- s_expression = self.get_s_expression(*coords)
- s_expression.next_to(point, UP+RIGHT, buff = SMALL_BUFF)
- s_expression.highlight(self.example_color)
- result = coords[0]**2 + coords[1]**2
- rhs = TexMobject("=%d"%int(result))
- rhs.add_background_rectangle()
- rhs.highlight(YELLOW)
- rhs.next_to(s_expression, RIGHT, align_using_submobjects = True)
- point_label = VGroup(s_expression, rhs)
+class DiscussProducts(TeacherStudentsScene):
+ def construct(self):
+ wrong_product_rule = TexMobject(
+ "\\frac{d(\\sin(x)x^2)}{dx}",
+ "\\ne",
+ "\\left(\\frac{d(\\sin(x))}{dx}\\right)",
+ "\\left(\\frac{d(x^2)}{dx}\\right)",
+ )
+ not_equals = wrong_product_rule[1]
+ wrong_product_rule[2].highlight(SINE_COLOR)
+ wrong_product_rule[3].highlight(X_SQUARED_COLOR)
+ wrong_product_rule.next_to(
+ self.get_teacher().get_corner(UP+LEFT),
+ UP,
+ buff = MED_LARGE_BUFF
+ ).shift_onto_screen()
- self.play(
- self.example_point_dot.move_to, point,
- Transform(self.example_point_label, point_label)
+ self.teacher_says(
+ "Products are a bit different",
+ target_mode = "sassy"
)
self.dither(2)
-
- def take_derivative_symbolically(self):
- equation = self.equation
- derivative = TexMobject(
- "dS =", "2", "x", "\\,dx", "+", "2", "y", "\\,dy",
+ self.play(RemovePiCreatureBubble(
+ self.get_teacher(),
+ target_mode = "raise_right_hand"
+ ))
+ self.play(Write(wrong_product_rule))
+ self.change_student_modes(
+ "pondering", "confused", "erm",
+ added_anims = [
+ not_equals.scale_in_place, 1.3,
+ not_equals.highlight, RED
+ ]
)
- derivative[2].highlight(GREEN)
- derivative[6].highlight(RED)
- derivative.next_to(equation, DOWN, buff = MED_LARGE_BUFF)
- derivative.add_background_rectangle()
- derivative.to_edge(LEFT)
-
- self.play(*[
- FadeIn(derivative[0])
- ]+[
- ReplacementTransform(
- self.s_expression[1][0].copy(),
- derivative[1][0],
- )
- ]+[
- Write(derivative[1][j])
- for j in 3, 7
- ])
- self.play(*[
- ReplacementTransform(
- equation[1][i].copy(), derivative[1][j],
- path_arc = np.pi/2,
- run_time = 2,
- rate_func = squish_rate_func(smooth, (j-1)/12., (j+6)/12.)
- )
- for i, j in enumerate([2, 1, 4, 6, 5])
- ])
+ self.dither()
+ self.teacher_says(
+ "Think about the \\\\ underlying meaning",
+ bubble_kwargs = {"height" : 3},
+ added_anims = [
+ wrong_product_rule.scale, 0.7,
+ wrong_product_rule.to_corner, UP+LEFT
+ ]
+ )
+ self.change_student_modes(*["pondering"]*3)
self.dither(2)
- self.derivative = derivative
-
- def show_dx_dy_step(self):
- dot = self.example_point_dot
- s_label = self.example_point_label
- rhs = s_label[-1]
- s_label.remove(rhs)
-
- point = dot.get_center()
- vect = 2*LEFT + DOWN
- new_point = point + vect*0.6/self.zoom_factor
- interim_point = new_point[0]*RIGHT + point[1]*UP
-
- dx_line = Line(point, interim_point, color = GREEN)
- dy_line = Line(interim_point, new_point, color = RED)
- for line, tex, vect in (dx_line, "dx", UP), (dy_line, "dy", LEFT):
- label = TexMobject(tex)
- label.highlight(line.get_color())
- label.next_to(line, vect, buff = SMALL_BUFF)
- label.add_background_rectangle()
- label.scale(
- 1./self.zoom_factor,
- about_point = line.get_center()
+class NotGraphsForProducts(GraphScene):
+ CONFIG = {
+ "y_max" : 25,
+ "x_max" : 7,
+ }
+ def construct(self):
+ self.setup_axes()
+ sine_graph = self.get_graph(np.sin, color = SINE_COLOR)
+ sine_graph.label = self.get_graph_label(
+ sine_graph, "\\sin(x)",
+ x_val = 3*np.pi/2,
+ direction = DOWN
+ )
+ parabola = self.get_graph(
+ lambda x : x**2, color = X_SQUARED_COLOR
+ )
+ parabola.label = self.get_graph_label(
+ parabola, "x^2",
+ x_val = 2.5,
+ direction = UP+LEFT,
+ )
+ product_graph = self.get_graph(
+ lambda x : np.sin(x)*(x**2), color = PRODUCT_COLOR
+ )
+ product_graph.label = self.get_graph_label(
+ product_graph, "\\sin(x)x^2",
+ x_val = 2.8,
+ direction = UP+RIGHT,
+ buff = 0
+ )
+
+ graphs = [sine_graph, parabola, product_graph]
+ for graph in graphs:
+ self.play(
+ ShowCreation(graph),
+ Write(graph.label, run_time = 2)
)
- line.label = label
-
- self.activate_zooming()
- lil_rect = self.little_rectangle
- lil_rect.move_to(dot)
- lil_rect.shift(0.05*lil_rect.get_width()*LEFT)
- lil_rect.shift(0.2*lil_rect.get_height()*DOWN)
- lil_rect.save_state()
- lil_rect.scale_to_fit_height(SPACE_HEIGHT - MED_LARGE_BUFF)
- lil_rect.move_to(s_label, UP)
- lil_rect.shift(MED_SMALL_BUFF*UP)
self.dither()
+
+ everything = VGroup(*filter(
+ lambda m : not m.is_subpath,
+ self.get_mobjects()
+ ))
+ words = TextMobject("Not the best visualization")
+ words.scale(1.5)
+ words.shift(SPACE_HEIGHT*UP/2)
+ words.add_background_rectangle()
+ words.highlight(RED)
self.play(
- FadeOut(rhs),
- dot.scale, 1./self.zoom_factor, point,
- s_label.scale, 1./self.zoom_factor, point,
- lil_rect.restore,
- run_time = 2
+ everything.fade,
+ Write(words)
)
self.dither()
- for line in dx_line, dy_line:
- self.play(ShowCreation(line))
- self.play(Write(line.label, run_time = 1))
- self.dither()
-
- new_dot = Dot(color = dot.get_color())
- new_s_label = self.get_s_expression(
- "%d + dx"%int(self.example_point[0]),
- "%d + dy"%int(self.example_point[1]),
- )
- new_dot.scale_to_fit_height(dot.get_height())
- new_dot.move_to(new_point)
- new_s_label.scale_to_fit_height(s_label.get_height())
- new_s_label.scale(0.8)
- new_s_label.next_to(
- new_dot, DOWN,
- buff = SMALL_BUFF/self.zoom_factor,
- aligned_edge = LEFT
- )
- new_s_label.shift(MED_LARGE_BUFF*LEFT/self.zoom_factor)
- new_s_label.highlight(self.example_color)
- VGroup(*new_s_label[1][1][3:5]).highlight(GREEN)
- VGroup(*new_s_label[1][1][-3:-1]).highlight(RED)
- self.play(ShowCreation(new_dot))
- self.play(Write(new_s_label))
+class ConfusedMorty(Scene):
+ def construct(self):
+ morty = Mortimer()
+ self.add(morty)
self.dither()
+ self.play(morty.change_mode, "confused")
+ self.play(Blink(morty))
+ self.dither(2)
- ds = self.derivative[1][0]
- self.play(FocusOn(ds))
- self.play(Indicate(ds))
+class IntroduceProductAsArea(ReconfigurableScene):
+ CONFIG = {
+ "top_func" : np.sin,
+ "top_func_label" : "\\sin(x)",
+ "top_func_nudge_label" : "d(\\sin(x))",
+ "top_func_derivative" : "\\cos(x)",
+ "side_func" : lambda x : x**2,
+ "side_func_label" : "x^2",
+ "side_func_nudge_label" : "d(x^2)",
+ "side_func_derivative" : "2x",
+ "x_unit_to_space_unit" : 3,
+ "box_kwargs" : {
+ "fill_color" : YELLOW,
+ "fill_opacity" : 0.75,
+ "stroke_width" : 1,
+ },
+ "df_box_kwargs" : {
+ "fill_color" : GREEN,
+ "fill_opacity" : 0.75,
+ "stroke_width" : 0,
+ },
+ "box_corner_location" : 6*LEFT+2.5*UP,
+ "slider_center" : 3.5*RIGHT+2*DOWN,
+ "slider_width" : 6,
+ "slider_x_max" : 3,
+ "x_slider_handle_height" : 0.25,
+ "slider_handle_color" : BLUE,
+ "default_x" : .75,
+ "dx" : 0.1,
+ "tiny_dx" : 0.01,
+ }
+ def construct(self):
+ self.introduce_box()
+ self.talk_though_sine()
+ self.define_f_of_x()
+ self.nudge_x()
+ self.write_df()
+ self.show_thinner_dx()
+ self.expand_derivative()
+ self.write_derivative_abstractly()
+ self.write_mneumonic()
+
+ def introduce_box(self):
+ box, labels = self.box_label_group = self.get_box_label_group(self.default_x)
+ self.x_slider = self.get_x_slider(self.default_x)
+
+ self.play(Write(labels))
+ self.play(DrawBorderThenFill(box))
+ self.dither()
+ for mob in self.x_slider:
+ self.play(Write(mob, run_time = 1))
+ self.dither()
+ for new_x in 0.5, 2, self.default_x:
+ self.animate_x_change(
+ new_x, run_time = 2
+ )
self.dither()
- self.tiny_step_group = VGroup(
- dx_line, dx_line.label,
- dy_line, dy_line.label,
- s_label, new_s_label, new_dot
- )
-
- def plug_in_example_values(self):
- deriv_example = TexMobject(
- "dS =", "2", "(3)", "\\,(-0.02)", "+", "2", "(4)", "\\,(-0.01)",
+ def talk_though_sine(self):
+ x_axis = self.x_slider[0]
+ graph = FunctionGraph(
+ np.sin, x_min = 0, x_max = np.pi,
+ color = SINE_COLOR
)
+ scale_factor = self.x_slider.get_width()/self.slider_x_max
+ graph.scale(scale_factor)
+ graph.move_to(x_axis.number_to_point(0), DOWN+LEFT)
- deriv_example[2].highlight(GREEN)
- deriv_example[6].highlight(RED)
- deriv_example.add_background_rectangle()
- deriv_example.scale(0.8)
- deriv_example.next_to(ORIGIN, UP, buff = SMALL_BUFF)
- deriv_example.to_edge(LEFT, buff = MED_SMALL_BUFF)
-
- def add_example_parts(*indices):
- self.play(*[
- ReplacementTransform(
- self.derivative[1][i].copy(),
- deriv_example[1][i],
- run_time = 2
- )
- for i in indices
- ])
+ label = TexMobject("\\sin(x)")
+ label.highlight(SINE_COLOR)
+ label.next_to(graph, UP)
- self.play(FadeIn(deriv_example[0]))
- add_example_parts(0)
- self.dither()
- add_example_parts(1, 2, 4, 5, 6)
- self.dither(2)
- add_example_parts(3)
- self.dither()
- add_example_parts(7)
- self.dither()
+ y_axis = x_axis.copy()
+ y_axis.remove(*y_axis.numbers)
- #React
- randy = Randolph()
- randy.next_to(ORIGIN, LEFT)
- randy.to_edge(DOWN)
+ v_line = Line(ORIGIN, UP, color = WHITE, stroke_width = 2)
+ def v_line_update(v_line):
+ x = x_axis.point_to_number(self.x_slider[1].get_top())
+ v_line.scale_to_fit_height(np.sin(x)*scale_factor)
+ v_line.move_to(x_axis.number_to_point(x), DOWN)
+ v_line_update(v_line)
- self.play(FadeIn(randy))
- self.play(
- randy.change_mode, "pondering",
- randy.look_at, deriv_example.get_left()
- )
- self.play(Blink(randy))
- self.play(randy.look_at, deriv_example.get_right())
- self.dither()
self.play(
- Indicate(self.equation),
- randy.look_at, self.equation
+ Rotate(y_axis, np.pi/2, about_point = y_axis.get_left()),
+ Animation(x_axis)
)
- self.play(Blink(randy))
self.play(
- randy.change_mode, "thinking",
- randy.look_at, self.big_rectangle
- )
- self.dither(2)
- self.play(PiCreatureSays(
- randy, "Approximately",
- target_mode = "sassy"
+ ShowCreation(graph),
+ Write(label, run_time = 1)
+ )
+ self.play(ShowCreation(v_line))
+ for x, rt in zip([0.25, np.pi/2, 3, self.default_x], [2, 4, 4, 2]):
+ self.animate_x_change(
+ x, run_time = rt,
+ added_anims = [
+ UpdateFromFunc(v_line, v_line_update)
+ ]
+ )
+ self.dither()
+ self.play(*it.chain(
+ map(FadeOut, [y_axis, graph, label, v_line]),
+ [Animation(x_axis)]
))
self.dither()
- self.play(RemovePiCreatureBubble(randy))
- self.play(randy.look_at, deriv_example)
- self.play(FadeOut(deriv_example))
+ for x in 1, 0.5, self.default_x:
+ self.animate_x_change(x)
self.dither()
- self.randy = randy
+ def define_f_of_x(self):
+ f_def = TexMobject(
+ "f(x)", "=",
+ self.top_func_label,
+ self.side_func_label,
+ "=",
+ "\\text{Area}"
+ )
+ f_def.to_corner(UP+RIGHT)
+ f_def[-1].highlight(self.box_kwargs["fill_color"])
+
+ box, labels = self.box_label_group
+
+ self.play(Write(VGroup(*f_def[:-1])))
+ self.play(Transform(
+ box.copy().set_fill(opacity = 0), f_def[-1],
+ run_time = 1.5,
+ ))
+ self.dither()
- def ask_about_equalling_zero(self):
- dot = self.example_point_dot
- randy = self.randy
+ self.f_def = f_def
- equals_zero = TexMobject("=0")
- equals_zero.highlight(YELLOW)
- equals_zero.add_background_rectangle()
- equals_zero.next_to(self.derivative, RIGHT)
+ def nudge_x(self):
+ box, labels = self.box_label_group
+ nudge_label_group = self.get_nudge_label_group()
+ original_dx = self.dx
+ self.dx = self.tiny_dx
+ thin_df_boxes = self.get_df_boxes()
+ self.dx = original_dx
+ df_boxes = self.get_df_boxes()
+ right_box, corner_box, right_box = df_boxes
- self.play(
- Write(equals_zero),
- randy.change_mode, "confused",
- randy.look_at, equals_zero
- )
+ self.play(FocusOn(nudge_label_group))
+ self.play(*map(GrowFromCenter, nudge_label_group))
+ self.animate_x_change(
+ self.default_x+self.dx,
+ rate_func = there_and_back,
+ run_time = 2,
+ added_anims = [Animation(nudge_label_group)]
+ )
self.dither()
- self.play(Blink(randy))
self.play(
- randy.change_mode, "plain",
- randy.look_at, self.big_rectangle,
+ ReplacementTransform(thin_df_boxes, df_boxes),
+ VGroup(*labels[1]).shift, right_box.get_width()*RIGHT,
)
self.play(
- FadeOut(self.tiny_step_group),
- self.little_rectangle.move_to, dot,
+ df_boxes.space_out_submobjects, 1.1,
+ df_boxes.move_to, box, UP+LEFT,
)
self.dither()
- self.equals_zero = equals_zero
+ self.df_boxes = df_boxes
+ self.df_box_labels = self.get_df_box_labels(df_boxes)
+ self.x_slider.add(nudge_label_group)
- def show_tangent_step(self):
- dot = self.example_point_dot
- randy = self.randy
-
- point = dot.get_center()
- step_vect = rotate_vector(point, np.pi/2)/np.linalg.norm(point)
- new_point = point + step_vect/self.zoom_factor
- interim_point = point[0]*RIGHT + new_point[1]*UP
- new_dot = dot.copy().move_to(new_point)
-
- step_line = Line(point, new_point, color = WHITE)
- dy_line = Line(point, interim_point, color = RED)
- dx_line = Line(interim_point, new_point, color = GREEN)
-
- s_label = TexMobject("S = 25")
- s_label.highlight(self.example_color)
- s_label.next_to(
- point, DOWN,
- buff = MED_LARGE_BUFF,
- aligned_edge = RIGHT
- )
- s_label.scale(1./self.zoom_factor, about_point = point)
- arrow1, arrow2 = [
- Arrow(
- s_label.get_top(), mob,
- preserve_tip_size_when_scaling = False,
- color = self.example_color,
- buff = SMALL_BUFF/self.zoom_factor,
- tip_length = 0.15/self.zoom_factor
+ def get_nudge_label_group(self):
+ line, triangle, x_mob = self.x_slider
+ dx_line = Line(*[
+ line.number_to_point(self.x_slider.x_val + num)
+ for num in 0, self.dx,
+ ])
+ dx_line.set_stroke(
+ self.df_box_kwargs["fill_color"],
+ width = 6
+ )
+ brace = Brace(dx_line, UP, buff = SMALL_BUFF)
+ brace.stretch_to_fit_height(0.2)
+ brace.next_to(dx_line, UP, buff = SMALL_BUFF)
+ brace.set_stroke(width = 1)
+ dx = TexMobject("dx")
+ dx.scale(0.7)
+ dx.next_to(brace, UP, buff = SMALL_BUFF)
+ dx.highlight(dx_line.get_color())
+
+ return VGroup(dx_line, brace, dx)
+
+ def get_df_boxes(self):
+ box, labels = self.box_label_group
+ alt_box = self.get_box(self.x_slider.x_val + self.dx)
+
+ h, w = box.get_height(), box.get_width()
+ dh, dw = alt_box.get_height()-h, alt_box.get_width()-w
+ heights_and_widths = [(dh, w), (dh, dw), (h, dw)]
+ vects = [DOWN, DOWN+RIGHT, RIGHT]
+ df_boxes = VGroup(*[
+ Rectangle(
+ height = height, width = width, **self.df_box_kwargs
+ ).next_to(box, vect, buff = 0)
+ for (height, width), vect in zip(
+ heights_and_widths, vects
)
- for mob in dot, new_dot
+ ])
+ return df_boxes
+
+ def get_df_box_labels(self, df_boxes):
+ bottom_box, corner_box, right_box = df_boxes
+ result = VGroup()
+ quads = [
+ (right_box, UP, self.top_func_nudge_label, LEFT),
+ (corner_box, RIGHT, self.side_func_nudge_label, ORIGIN),
]
-
- for line, tex, vect in (dy_line, "dy", RIGHT), (dx_line, "dx", UP):
- label = TexMobject(tex)
- label.highlight(line.get_color())
- label.next_to(line, vect)
- label.scale(
- 1./self.zoom_factor,
- about_point = line.get_center()
+ for box, vect, label_tex, aligned_edge in quads:
+ brace = Brace(box, vect)
+ label = TexMobject(label_tex)
+ label.next_to(
+ brace, vect,
+ aligned_edge = aligned_edge,
+ buff = SMALL_BUFF
)
- line.label = label
+ label.highlight(df_boxes[0].get_color())
+ result.add(VGroup(brace, label))
+ return result
+
+ def write_df(self):
+ deriv = TexMobject(
+ "df", "=",
+ self.top_func_label,
+ self.side_func_nudge_label,
+ "+",
+ self.side_func_label,
+ self.top_func_nudge_label,
+ )
+ deriv.scale(0.9)
+ deriv.next_to(self.f_def, DOWN, buff = LARGE_BUFF)
+ deriv.to_edge(RIGHT)
+ for submob, tex in zip(deriv, deriv.expression_parts):
+ if tex.startswith("d"):
+ submob.highlight(self.df_box_kwargs["fill_color"])
+ bottom_box_area = VGroup(*deriv[2:4])
+ right_box_area = VGroup(*deriv[5:7])
+
+ bottom_box, corner_box, right_box = self.df_boxes
+ plus = TexMobject("+").set_fill(opacity = 0)
+ df_boxes_copy = VGroup(
+ bottom_box.copy(),
+ plus,
+ right_box.copy(),
+ plus.copy(),
+ corner_box.copy(),
+ )
+
+ self.deriv = deriv
+ self.df_boxes_copy = df_boxes_copy
+ box, labels = self.box_label_group
+ self.full_box_parts = VGroup(*it.chain(
+ [box], self.df_boxes, labels, self.df_box_labels
+ ))
- self.play(ShowCreation(line))
- self.play(Write(label))
- self.play(ShowCreation(new_dot))
+ self.play(Write(VGroup(*deriv[:2])))
self.play(
- randy.change_mode, "pondering",
- randy.look_at, self.big_rectangle
+ df_boxes_copy.arrange_submobjects,
+ df_boxes_copy.set_fill, None, self.df_box_kwargs["fill_opacity"],
+ df_boxes_copy.next_to, deriv[1]
)
- self.play(Blink(randy))
- self.dither()
-
- self.play(Write(s_label))
- self.play(ShowCreation(arrow1))
+ deriv.submobjects[4] = df_boxes_copy[1]
self.dither()
- self.play(ReplacementTransform(arrow1.copy(), arrow2))
- self.dither(2)
- def point_out_equalling_zero(self):
- derivative = self.derivative
- equals_zero = self.equals_zero
- randy = self.randy
+ self.highlight_right_boxes()
+ self.highlight_bottom_boxes()
+ self.describe_bottom_box(bottom_box_area)
+ self.describe_right_box(right_box_area)
+ self.ignore_corner()
- self.play(
- FocusOn(equals_zero),
- self.randy.look_at, equals_zero
- )
- self.play(Indicate(equals_zero, color = RED))
- self.play(Blink(randy))
- self.play(randy.change_mode, "happy")
- self.play(randy.look_at, self.big_rectangle)
- self.dither(2)
+ # self.add(deriv)
- def show_tangent_line(self):
- randy = self.randy
- point = self.example_point_dot.get_center()
- line = Line(ORIGIN, 5*RIGHT)
- line.rotate(angle_of_vector(point)+np.pi/2)
- line.move_to(point)
+ def highlight_boxes_and_label(self, boxes, label):
+ boxes.save_state()
+ label.save_state()
- self.play(PiCreatureSays(
- randy, "Approximately...",
- ))
- self.play(Blink(randy))
- self.play(RemovePiCreatureBubble(randy))
+ self.play(GrowFromCenter(label))
self.play(
- GrowFromCenter(line),
- randy.look_at, line
+ boxes.highlight, RED,
+ label.highlight, RED,
)
- self.dither(2)
self.play(
- self.little_rectangle.scale_in_place, self.zoom_factor/2,
- run_time = 4,
+ label[1].scale_in_place, 1.1,
rate_func = there_and_back
)
- self.dither(2)
-
- ############
+ self.play(boxes.restore, label.restore)
+ self.dither()
- def get_s_expression(self, x, y):
- result = TexMobject("S", "(%s, %s)"%(str(x), str(y)))
- result.add_background_rectangle()
- return result
+ def highlight_right_boxes(self):
+ self.highlight_boxes_and_label(
+ VGroup(*self.df_boxes[1:]),
+ self.df_box_labels[0]
+ )
-class TryOtherExamples(TeacherStudentsScene):
- def construct(self):
- formula = TexMobject("\\sin(x)y^2 = x")
- formula.next_to(
- self.get_teacher().get_corner(UP+LEFT), UP,
- buff = MED_LARGE_BUFF,
- aligned_edge = RIGHT
+ def highlight_bottom_boxes(self):
+ self.highlight_boxes_and_label(
+ VGroup(*self.df_boxes[:-1]),
+ self.df_box_labels[1]
)
+ def describe_bottom_box(self, bottom_box_area):
+ bottom_box = self.df_boxes[0]
+ bottom_box_copy = self.df_boxes_copy[0]
+ other_box_copies = VGroup(*self.df_boxes_copy[1:])
+ top_label = self.box_label_group[1][0]
+ right_label = self.df_box_labels[1]
- self.teacher_says(
- """Nothing special
- about $x^2 + y^2 = 25$"""
- )
- self.dither()
- self.play(RemovePiCreatureBubble(
- self.get_teacher(),
- target_mode = "raise_right_hand"
+ faders = VGroup(*filter(
+ lambda m : m not in [bottom_box, top_label, right_label],
+ self.full_box_parts
))
- self.play(Write(formula, run_time = 1))
- self.change_student_modes(*["pondering"]*3)
- self.dither(2)
- self.play(formula.to_corner, UP+LEFT)
- self.dither()
-
-class AlternateExample(ZoomedScene):
- CONFIG = {
- "example_color" : MAROON_B,
- "zoom_factor" : 10,
- "zoomed_canvas_corner" : DOWN+RIGHT,
- "zoomed_canvas_space_shape" : (3, 4),
- }
- def construct(self):
- self.add_plane()
- self.draw_graph()
- self.emphasize_meaning_of_points()
- self.zoom_in()
- self.show_tiny_step()
- self.ask_about_derivatives()
- self.differentiate_lhs()
- self.differentiate_rhs()
- self.put_step_on_curve()
- self.emphasize_equality()
- self.manipulate_to_find_dy_dx()
-
- def add_plane(self):
- formula = TexMobject("\\sin(x)y^2 = x")
- formula.to_corner(UP+LEFT)
- formula.add_background_rectangle()
-
- plane = NumberPlane(
- space_unit_to_x_unit = 0.75,
- x_radius = 2*SPACE_WIDTH,
- )
- plane.fade()
- plane.add_coordinates()
-
- self.add(formula)
- self.play(Write(plane, run_time = 2), Animation(formula))
- self.dither()
-
- self.plane = plane
- self.formula = formula
- self.lhs = VGroup(*formula[1][:8])
- self.rhs = VGroup(formula[1][-1])
-
- def draw_graph(self):
- graphs = VGroup(*[
- FunctionGraph(
- lambda x : u*np.sqrt(x/np.sin(x)),
- num_steps = 200,
- x_min = x_min+0.1,
- x_max = x_max-0.1,
- )
- for u in [-1, 1]
- for x_min, x_max in [
- (-4*np.pi, -2*np.pi),
- (-np.pi, np.pi),
- (2*np.pi, 4*np.pi),
- ]
- ])
- graphs.stretch(self.plane.space_unit_to_x_unit, dim = 0)
+ faders.save_state()
+ self.play(faders.fade, 0.8)
+ self.dither()
+ self.play(FocusOn(bottom_box_copy))
self.play(
- ShowCreation(
- graphs,
- run_time = 3,
- submobject_mode = "all_at_once"
- ),
- Animation(self.formula)
+ ReplacementTransform(bottom_box_copy, bottom_box_area),
+ other_box_copies.next_to, bottom_box_area, RIGHT
)
self.dither()
+ self.play(faders.restore)
- self.graphs = graphs
-
- def emphasize_meaning_of_points(self):
- graph = self.graphs[4]
- dot = Dot(color = self.example_color)
- label = TexMobject("(x, y)")
- label.add_background_rectangle()
- label.highlight(self.example_color)
-
- def update_dot(dot, alpha):
- prop = interpolate(0.9, 0.1, alpha)
- point = graph.point_from_proportion(prop)
- dot.move_to(point)
- return dot
+ def describe_right_box(self, right_box_area):
+ right_box = self.df_boxes[2]
+ right_box_copy = self.df_boxes_copy[2]
+ right_box_area.next_to(self.df_boxes_copy[1])
+ other_box_copies = VGroup(*self.df_boxes_copy[3:])
+ top_label = self.df_box_labels[0]
+ right_label = self.box_label_group[1][1]
- def update_label(label):
- point = dot.get_center()
- vect = np.array(point)/np.linalg.norm(point)
- vect[0] *= 2
- vect[1] *= -1
- label.move_to(
- point + vect*0.4*label.get_width()
- )
-
- update_dot(dot, 0)
- update_label(label)
+ faders = VGroup(*filter(
+ lambda m : m not in [right_box, top_label, right_label],
+ self.full_box_parts
+ ))
+ faders.save_state()
- self.play(
- ShowCreation(dot),
- Write(label),
- run_time = 1
- )
- self.play(
- UpdateFromAlphaFunc(dot, update_dot),
- UpdateFromFunc(label, update_label),
- run_time = 3,
- )
- self.dither()
- self.play(*[
- ApplyMethod(
- label[1][i].copy().move_to, self.formula[1][j],
- run_time = 3,
- rate_func = squish_rate_func(smooth, count/6., count/6.+2./3)
- )
- for count, (i, j) in enumerate([(1, 4), (1, 9), (3, 6)])
- ])
- movers = self.get_mobjects_from_last_animation()
+ self.play(faders.fade, 0.8)
self.dither()
+ self.play(FocusOn(right_box_copy))
self.play(
- UpdateFromAlphaFunc(dot, update_dot),
- UpdateFromFunc(label, update_label),
- run_time = 3,
- rate_func = lambda t : 1-smooth(t)
+ ReplacementTransform(right_box_copy, right_box_area),
+ other_box_copies.next_to, right_box_area, DOWN,
+ MED_SMALL_BUFF, RIGHT,
+
)
self.dither()
- self.play(*[
- ApplyMethod(mover.set_fill, None, 0, remover = True)
- for mover in movers
- ])
+ self.play(faders.restore)
- self.dot = dot
- self.label = label
+ def ignore_corner(self):
+ corner = self.df_boxes[1]
+ corner.save_state()
+ corner_copy = VGroup(*self.df_boxes_copy[-2:])
+ words = TextMobject("Ignore")
+ words.highlight(RED)
+ words.next_to(corner_copy, LEFT, buff = LARGE_BUFF)
+ words.shift(MED_SMALL_BUFF*DOWN)
+ arrow = Arrow(words, corner_copy, buff = SMALL_BUFF, color = RED)
- def zoom_in(self):
- dot = self.dot
- label = self.label
-
- self.activate_zooming()
- self.little_rectangle.scale(self.zoom_factor)
- self.little_rectangle.move_to(dot)
- self.dither()
- for mob in VGroup(dot, label), self.little_rectangle:
+ self.play(
+ corner.highlight, RED,
+ corner_copy.highlight, RED,
+ )
+ self.dither()
+ self.play(Write(words), ShowCreation(arrow))
+ self.dither()
+ self.play(*map(FadeOut, [words, arrow, corner_copy]))
+ self.dither()
+ corner_copy.highlight(BLACK)
+
+ def show_thinner_dx(self):
+ self.transition_to_alt_config(dx = self.tiny_dx)
+
+ def expand_derivative(self):
+ # self.play(
+ # self.deriv.next_to, self.f_def, DOWN, MED_LARGE_BUFF,
+ # self.deriv.shift_onto_screen
+ # )
+ # self.dither()
+
+ expanded_deriv = TexMobject(
+ "df", "=",
+ self.top_func_label,
+ self.side_func_derivative,
+ "\\,dx",
+ "+",
+ self.side_func_label,
+ self.top_func_derivative,
+ "\\,dx"
+ )
+ final_deriv = TexMobject(
+ "{df \\over ", "dx}", "=",
+ self.top_func_label,
+ self.side_func_derivative,
+ "+",
+ self.side_func_label,
+ self.top_func_derivative,
+ )
+ color = self.deriv[0].get_color()
+ for new_deriv in expanded_deriv, final_deriv:
+ for submob, tex in zip(new_deriv, new_deriv.expression_parts):
+ for substr in "df", "dx", self.top_func_derivative, self.side_func_derivative:
+ if substr in tex:
+ submob.highlight(color)
+ new_deriv.scale(0.9)
+ new_deriv.next_to(self.deriv, DOWN, buff = MED_LARGE_BUFF)
+ new_deriv.shift_onto_screen()
+
+ def indicate(mob):
self.play(
- ApplyMethod(
- mob.scale, 1./self.zoom_factor,
- method_kwargs = {"about_point" : dot.get_center()},
- run_time = 1,
- )
+ mob.scale_in_place, 1.2,
+ mob.highlight, YELLOW,
+ rate_func = there_and_back
)
- self.dither()
- def show_tiny_step(self):
- dot = self.dot
- label = self.label
- point = dot.get_center()
- step_vect = 1.2*(UP+LEFT)/float(self.zoom_factor)
- new_point = point + step_vect
- interim_point = new_point[0]*RIGHT + point[1]*UP
-
- dx_line = Line(point, interim_point, color = GREEN)
- dy_line = Line(interim_point, new_point, color = RED)
- for line, tex, vect in (dx_line, "dx", DOWN), (dy_line, "dy", LEFT):
- label = TexMobject(tex)
- label.next_to(line, vect, buff = SMALL_BUFF)
- label.highlight(line.get_color())
- label.scale(1./self.zoom_factor, about_point = line.get_center())
- label.add_background_rectangle()
- line.label = label
- arrow = Arrow(
- point, new_point, buff = 0,
- tip_length = 0.15/self.zoom_factor,
- color = WHITE
- )
+ for index in 6, 3:
+ self.deriv.submobjects.insert(
+ index+1, self.deriv[index].copy()
+ )
+ non_deriv_indices = range(len(expanded_deriv))
+ for indices in [(3, 4), (7, 8)]:
+ top_part = VGroup()
+ bottom_part = VGroup()
+ for i in indices:
+ non_deriv_indices.remove(i)
+ top_part.add(self.deriv[i].copy())
+ bottom_part.add(expanded_deriv[i])
+ self.play(top_part.move_to, bottom_part)
+ self.dither()
+ indicate(top_part)
+ self.dither()
+ self.play(ReplacementTransform(top_part, bottom_part))
+ self.dither()
+ top_part = VGroup()
+ bottom_part = VGroup()
+ for i in non_deriv_indices:
+ top_part.add(self.deriv[i].copy())
+ bottom_part.add(expanded_deriv[i])
+ self.play(ReplacementTransform(
+ top_part, bottom_part
+ ))
- self.play(ShowCreation(arrow))
- for line in dx_line, dy_line:
- self.play(ShowCreation(line), Animation(arrow))
- self.play(Write(line.label, run_time = 1))
self.dither()
-
- self.step_group = VGroup(
- arrow, dx_line, dx_line.label, dy_line, dy_line.label
- )
-
- def ask_about_derivatives(self):
- formula = self.formula
- lhs, rhs = self.lhs, self.rhs
-
- word = TextMobject("Change?")
- word.add_background_rectangle()
- word.next_to(
- Line(lhs.get_center(), rhs.get_center()),
- DOWN, buff = 1.5*LARGE_BUFF
- )
-
- arrows = VGroup(*[
- Arrow(word, part)
- for part in lhs, rhs
+ self.play(*[
+ ReplacementTransform(
+ expanded_deriv[i], final_deriv[j],
+ path_arc = -np.pi/2
+ )
+ for i, j in [
+ (0, 0),
+ (1, 2),
+ (2, 3),
+ (3, 4),
+ (4, 1),
+ (5, 5),
+ (6, 6),
+ (7, 7),
+ (8, 1),
+ ]
])
+ self.dither()
+ for index in 0, 1, 3, 4, 6, 7:
+ indicate(final_deriv[index])
+ self.dither()
- self.play(FocusOn(formula))
- self.play(
- Write(word),
- ShowCreation(arrows)
+ def write_derivative_abstractly(self):
+ self.transition_to_alt_config(
+ return_to_original_configuration = False,
+ top_func_label = "g(x)",
+ top_func_nudge_label = "dg",
+ top_func_derivative = "\\frac{dg}{dx}",
+ side_func_label = "h(x)",
+ side_func_nudge_label = "dh",
+ side_func_derivative = "\\frac{dh}{dx}",
)
self.dither()
- self.play(*map(FadeOut, [word, arrows]))
-
- def differentiate_lhs(self):
- formula = self.formula
- lhs = self.lhs
- brace = Brace(lhs, DOWN, buff = SMALL_BUFF)
- sine_x = VGroup(*lhs[:6])
- sine_rect = BackgroundRectangle(sine_x)
- y_squared = VGroup(*lhs[6:])
- mnemonic = TextMobject(
- "``",
- "Left", " d-Right", " + ",
- "Right", " d-Left"
- "''",
+ def write_mneumonic(self):
+ morty = Mortimer()
+ morty.scale(0.7)
+ morty.to_edge(DOWN)
+ morty.shift(2*LEFT)
+ words = TextMobject(
+ "``Left ", "d(Right) ", "+", " Right ", "d(Left)", "''",
arg_separator = ""
)
- mnemonic.highlight_by_tex("d-Right", RED)
- mnemonic.highlight_by_tex("d-Left", GREEN)
- mnemonic.add_background_rectangle()
- mnemonic.scale_to_fit_width(SPACE_WIDTH-2*MED_LARGE_BUFF)
- mnemonic.next_to(ORIGIN, UP)
- mnemonic.to_edge(LEFT)
-
- derivative = TexMobject(
- "\\sin(x)", "(2y\\,dy)", "+",
- "y^2", "(\\cos(x)\\,dx)",
- )
- derivative.highlight_by_tex("dx", GREEN)
- derivative.highlight_by_tex("dy", RED)
- derivative.scale_to_fit_width(SPACE_WIDTH - 2*MED_LARGE_BUFF)
- derivative.next_to(
- brace, DOWN,
- buff = MED_LARGE_BUFF,
- aligned_edge = LEFT
- )
- derivative_rects = [
- BackgroundRectangle(VGroup(*subset))
- for subset in derivative[:2], derivative[2:]
- ]
- derivative_rects[1].stretch(1.05, dim = 0)
+ VGroup(words[1], words[4]).highlight(self.df_boxes[0].get_color())
+ words.scale(0.7)
+ words.next_to(morty.get_corner(UP+LEFT), UP)
+ words.shift_onto_screen()
- self.play(GrowFromCenter(brace))
- self.play(Write(mnemonic))
- self.dither()
- pairs = [
- (sine_rect, derivative_rects[0]),
- (sine_x, derivative[0]),
- (y_squared, derivative[1]),
- (sine_rect, derivative_rects[1]),
- (y_squared, derivative[2]),
- (y_squared, derivative[3]),
- (sine_x, derivative[4]),
- ]
- for pairs_subset in pairs[:3], pairs[3:]:
- self.play(*[
- ReplacementTransform(m1.copy(), m2, path_arc = np.pi/2)
- for m1, m2 in pairs_subset
- ])
- self.dither()
- self.play(Indicate(pairs_subset[-1][1]))
- self.dither()
+ self.play(FadeIn(morty))
+ self.play(
+ morty.change_mode, "raise_right_hand",
+ Write(words)
+ )
self.dither()
- self.play(FadeOut(mnemonic))
- self.lhs_derivative = VGroup(*derivative_rects+[derivative])
- self.lhs_brace = brace
+ ###############
- def differentiate_rhs(self):
- lhs_derivative = self.lhs_derivative
- lhs_brace = self.lhs_brace
- rhs = self.rhs
+ def animate_x_change(
+ self, target_x,
+ box_label_group = None,
+ x_slider = None,
+ **kwargs
+ ):
+ box_label_group = box_label_group or self.box_label_group
+ x_slider = x_slider or self.x_slider
+ kwargs["run_time"] = kwargs.get("run_time", 2)
+ added_anims = kwargs.get("added_anims", [])
- equals, dx = equals_dx = TexMobject("=", "dx")
- equals_dx.scale(0.9)
- equals_dx.highlight_by_tex("dx", GREEN)
- equals_dx.add_background_rectangle()
- equals_dx.next_to(lhs_derivative, RIGHT, buff = SMALL_BUFF)
+ start_x = x_slider.x_val
+ def update_box_label_group(box_label_group, alpha):
+ new_x = interpolate(start_x, target_x, alpha)
+ new_box_label_group = self.get_box_label_group(new_x)
+ Transform(box_label_group, new_box_label_group).update(1)
+
+ def update_x_slider(x_slider, alpha):
+ new_x = interpolate(start_x, target_x, alpha)
+ new_x_slider = self.get_x_slider(new_x)
+ Transform(x_slider, new_x_slider).update(1)
- circle = Circle(color = GREEN)
- circle.replace(self.rhs)
- circle.scale_in_place(1.7)
+ self.play(
+ UpdateFromAlphaFunc(
+ box_label_group,
+ update_box_label_group
+ ),
+ UpdateFromAlphaFunc(
+ x_slider,
+ update_x_slider
+ ),
+ *added_anims,
+ **kwargs
+ )
+ x_slider.x_val = target_x
+
+ def get_x_slider(self, x):
+ numbers = range(int(self.slider_x_max) + 1)
+ line = NumberLine(
+ x_min = 0,
+ x_max = self.slider_x_max,
+ space_unit_to_num = float(self.slider_width)/self.slider_x_max,
+ color = GREY,
+ numbers_with_elongated_ticks = numbers,
+ tick_frequency = 0.25,
+ )
+ line.add_numbers(*numbers)
+ line.numbers.next_to(line, UP, buff = SMALL_BUFF)
+ for number in line.numbers:
+ number.add_background_rectangle()
+ line.move_to(self.slider_center)
+
+ triangle = RegularPolygon(
+ 3, start_angle = np.pi/2,
+ fill_color = self.slider_handle_color,
+ fill_opacity = 0.8,
+ stroke_width = 0,
+ )
+ triangle.scale_to_fit_height(self.x_slider_handle_height)
+ triangle.move_to(line.number_to_point(x), UP)
- arrow = Arrow(rhs.get_right(), dx.get_top())
- arrow.highlight(GREEN)
+ x_mob = TexMobject("x")
+ x_mob.next_to(triangle, DOWN, buff = SMALL_BUFF)
- self.play(ReplacementTransform(lhs_brace, circle))
- self.play(ShowCreation(arrow))
- self.play(Write(equals_dx))
- self.dither()
- self.play(*map(FadeOut, [circle, arrow]))
+ result = VGroup(line, triangle, x_mob)
+ result.x_val = x
+ return result
- self.equals_dx = equals_dx
+ def get_box_label_group(self, x):
+ box = self.get_box(x)
+ labels = self.get_box_labels(box)
+ return VGroup(box, labels)
+
+ def get_box(self, x):
+ box = Rectangle(
+ width = self.x_unit_to_space_unit * self.top_func(x),
+ height = self.x_unit_to_space_unit * self.side_func(x),
+ **self.box_kwargs
+ )
+ box.move_to(self.box_corner_location, UP+LEFT)
+ return box
+
+ def get_box_labels(self, box):
+ result = VGroup()
+ for label_tex, vect in (self.top_func_label, UP), (self.side_func_label, RIGHT):
+ brace = Brace(box, vect, min_num_quads = 5)
+ label = TexMobject(label_tex)
+ label.next_to(brace, vect, buff = SMALL_BUFF)
+ result.add(VGroup(brace, label))
+ return result
- def put_step_on_curve(self):
- dot = self.dot
- point = dot.get_center()
- graph = self.graphs[4]
- arrow, dx_line, dx_line.label, dy_line, dy_line.label = self.step_group
+class WriteDXSquared(Scene):
+ def construct(self):
+ term = TexMobject("(...)(dx)^2")
+ term.highlight(RED)
+ self.play(Write(term))
+ self.dither()
- #Find graph point at right x_val
- arrow_end = arrow.get_end()
- graph_points = [
- graph.point_from_proportion(alpha)
- for alpha in np.linspace(0, 1, 1000)
- ]
- distances = np.apply_along_axis(
- lambda p : np.abs(p[0] - arrow_end[0]),
- 1, graph_points
+class MneumonicExample(TeacherStudentsScene):
+ def construct(self):
+ d, left, right, rp = deriv_q = TexMobject(
+ "\\frac{d}{dx}(", "\\sin(x)", "x^2", ")"
+ )
+ deriv_q.to_edge(UP)
+
+ words = TextMobject(
+ "Left ", "d(Right) ", "+", " Right ", "d(Left)",
+ arg_separator = ""
)
- index = np.argmin(distances)
- new_end_point = graph_points[index]
+ deriv = TexMobject("\\sin(x)", "2x", "+", "x^2", "\\cos(x)")
+ for mob in words, deriv:
+ VGroup(mob[1], mob[4]).highlight(GREEN)
+ mob.next_to(deriv_q, DOWN, buff = MED_LARGE_BUFF)
+ deriv.shift(words[2].get_center()-deriv[2].get_center())
- lil_rect = self.little_rectangle
+ self.add(words)
self.play(
- arrow.put_start_and_end_on, point, new_end_point,
- dy_line.put_start_and_end_on,
- dy_line.get_start(), new_end_point,
- MaintainPositionRelativeTo(dy_line.label, dy_line),
- lil_rect.shift, lil_rect.get_height()*DOWN/3,
- run_time = 2
+ Write(deriv_q),
+ self.get_teacher().change_mode, "raise_right_hand"
)
- self.dither(2)
+ self.change_student_modes(*["pondering"]*3)
- def emphasize_equality(self):
- self.play(FocusOn(self.lhs))
+ left_words = VGroup(*words[:2])
+ left_terms = VGroup(*deriv[:2])
+ self.play(
+ left_words.next_to, left_terms, DOWN,
+ MED_LARGE_BUFF, RIGHT
+ )
+ self.play(ReplacementTransform(
+ left_words.copy(), left_terms
+ ))
self.dither()
- for mob in self.lhs, self.rhs:
- self.play(Indicate(mob))
+ self.play(*map(Indicate, [left, left_words[0], left_terms[0]]))
+ self.dither()
+ self.play(*map(Indicate, [right, left_words[1], left_terms[1]]))
self.dither()
- def manipulate_to_find_dy_dx(self):
- full_derivative = VGroup(
- self.lhs_derivative, self.equals_dx
- )
- brace = Brace(full_derivative, DOWN, buff = SMALL_BUFF)
- words = brace.get_text(
- "Commonly, solve for", "$dy/dx$",
- buff = SMALL_BUFF
+ right_words = VGroup(*words[2:])
+ right_terms = VGroup(*deriv[2:])
+ self.play(
+ right_words.next_to, right_terms, DOWN,
+ MED_LARGE_BUFF, LEFT
)
- VGroup(*words[1][:2]).highlight(RED)
- VGroup(*words[1][3:]).highlight(GREEN)
- words.add_background_rectangle()
-
- self.play(GrowFromCenter(brace))
- self.play(Write(words))
+ self.play(ReplacementTransform(
+ right_words.copy(), right_terms
+ ))
self.dither()
+ self.play(*map(Indicate, [right, right_words[1], right_terms[1]]))
+ self.dither()
+ self.play(*map(Indicate, [left, right_words[2], right_terms[2]]))
+ self.dither(3)
- randy = Randolph()
- randy.to_corner(DOWN+LEFT)
- randy.look_at(full_derivative)
+ self.play(self.get_teacher().change_mode, "shruggie")
+ self.dither()
+ self.change_student_modes(*["confused"]*3)
+ self.dither(3)
- self.play(FadeIn(randy))
- self.play(randy.change_mode, "confused")
- self.play(Blink(randy))
- self.dither(2)
- self.play(randy.change_mode, "pondering")
- self.play(Blink(randy))
+class ConstantMultiplication(TeacherStudentsScene):
+ def construct(self):
+ question = TextMobject("What about $\\dfrac{d}{dx}(2\\sin(x))$?")
+ answer = TextMobject("2\\cos(x)")
+ self.teacher_says(question)
self.dither()
+ self.student_says(
+ answer, target_mode = "hooray",
+ added_anims = [question.copy().to_edge, UP]
+ )
+ self.play(self.get_teacher().change_mode, "happy")
+ self.change_student_modes("pondering", "hooray", "pondering")
+ self.dither(3)
-class AskAboutNaturalLog(TeacherStudentsScene):
+class ConstantMultiplicationFigure(IntroduceProductAsArea):
+ CONFIG = {
+ "side_func" : lambda x : 1,
+ "side_func_label" : "\\text{Constant}",
+ "side_func_nudge_label" : "",
+ "side_func_derivative" : "",
+ "x_unit_to_space_unit" : 3,
+ "default_x" : 0.5,
+ "dx" : 0.1
+ }
def construct(self):
- exp_deriv = TexMobject("\\frac{d(e^x)}{dx} = e^x")
- for i in 2, 3, 9, 10:
- exp_deriv[i].highlight(BLUE)
- log_deriv = TexMobject("\\frac{d(\\ln(x))}{dx} = ???")
- VGroup(*log_deriv[2:2+5]).highlight(GREEN)
+ self.box_label_group = self.get_box_label_group(self.default_x)
+ self.x_slider = self.get_x_slider(self.default_x)
+ # df_boxes = self.get_df_boxes()
+ # df_box_labels = self.get_df_box_labels(df_boxes)
- for deriv in exp_deriv, log_deriv:
- deriv.next_to(self.get_teacher().get_corner(UP+LEFT), UP)
+ self.add(self.box_label_group, self.x_slider)
+ self.nudge_x()
- self.teacher_says(
- """We can find
- new derivatives""",
- target_mode = "hooray"
- )
- self.change_student_modes(*["happy"]*3)
- self.play(RemovePiCreatureBubble(
- self.get_teacher(),
- target_mode = "raise_right_hand"
- ))
- self.play(Write(exp_deriv))
+class ShoveXSquaredInSine(Scene):
+ def construct(self):
+ title = TextMobject("Function composition")
+ title.to_edge(UP)
+
+ sine = TexMobject("g(", "x", ")", "=", "\\sin(", "x", ")")
+ sine.highlight(SINE_COLOR)
+ x_squared = TexMobject("h(x)", "=", "x^2")
+ x_squared.highlight(X_SQUARED_COLOR)
+ group = VGroup(sine, x_squared)
+ group.arrange_submobjects(buff = LARGE_BUFF)
+ group.shift(UP)
+ composition = TexMobject(
+ "g(", "h(x)", ")", "=", "\\sin(", "x^2", ")"
+ )
+ for i in 0, 2, 4, 6:
+ composition[i].highlight(SINE_COLOR)
+ for i in 1, 5:
+ composition[i].highlight(X_SQUARED_COLOR)
+ composition.next_to(group, DOWN, buff = LARGE_BUFF)
+
+ brace = Brace(VGroup(*composition[-3:]), DOWN)
+ deriv_q = brace.get_text("Derivative?")
+
+ self.add(group)
+ self.play(Write(title))
+ self.dither()
+ triplets = [
+ [sine, (0, 2), (0, 2)],
+ [x_squared, (0,), (1,)],
+ [sine, (3, 4, 6), (3, 4, 6)],
+ [x_squared, (2,), (5,)]
+ ]
+ for premob, pre_indices, comp_indicies in triplets:
+ self.play(*[
+ ReplacementTransform(
+ premob[i].copy(), composition[j]
+ )
+ for i, j in zip(pre_indices, comp_indicies)
+ ])
+ self.dither()
self.dither()
self.play(
- Write(log_deriv),
- exp_deriv.next_to, log_deriv, UP, LARGE_BUFF,
- *[
- ApplyMethod(pi.change_mode, "confused")
- for pi in self.get_pi_creatures()
- ]
+ GrowFromCenter(brace),
+ Write(deriv_q)
)
- self.dither(3)
+ self.dither()
-class DerivativeOfNaturalLog(ZoomedScene):
+class ThreeLinesChainRule(ReconfigurableScene):
CONFIG = {
- "zoom_factor" : 10,
- "zoomed_canvas_corner" : DOWN+RIGHT,
- "example_color" : MAROON_B,
+ "start_x" : 0.5,
+ "top_x" : 3,
+ "example_x" : 1.5,
+ "dx" : 0.1,
+ "line_configs" : [
+ {
+ "func" : lambda x : x,
+ "func_label" : "x",
+ "triangle_color" : WHITE,
+ "center_y" : 3,
+ "x_min" : 0,
+ "x_max" : 3,
+ "numbers_to_show" : range(4),
+ "numbers_with_elongated_ticks" : range(4),
+ "tick_frequency" : 0.25,
+ },
+ {
+ "func" : lambda x : x**2,
+ "func_label" : "x^2",
+ "triangle_color" : X_SQUARED_COLOR,
+ "center_y" : 0.5,
+ "x_min" : 0,
+ "x_max" : 10,
+ "numbers_to_show" : range(0, 11),
+ "numbers_with_elongated_ticks" : range(0, 11, 1),
+ "tick_frequency" : 0.25,
+ },
+ {
+ "func" : lambda x : np.sin(x**2),
+ "func_label" : "\\sin(x^2)",
+ "triangle_color" : SINE_COLOR,
+ "center_y" : -2,
+ "x_min" : -2,
+ "x_max" : 2,
+ "numbers_to_show" : range(-2, 3),
+ "numbers_with_elongated_ticks" : range(-2, 3),
+ "tick_frequency" : 0.25,
+ },
+ ],
+ "line_width" : 8,
+ "triangle_height" : 0.25,
}
def construct(self):
- should_skip_animations = self.skip_animations
- self.skip_animations = True
-
- self.add_plane()
- self.draw_graph()
- self.describe_as_implicit_curve()
- self.slope_gives_derivative()
- self.rearrange_equation()
- self.take_derivative()
- self.show_tiny_nudge()
- self.note_derivatives()
- self.solve_for_dy_dx()
- self.skip_animations = should_skip_animations
- self.show_slope_above_x()
-
- def add_plane(self):
- plane = NumberPlane()
- plane.fade()
- plane.add_coordinates()
- self.add(plane)
- self.plane = plane
-
- def draw_graph(self):
- graph = FunctionGraph(
- np.log,
- x_min = 0.01,
- x_max = SPACE_WIDTH,
- num_steps = 100
- )
- formula = TexMobject("y = \\ln(x)")
- formula.next_to(ORIGIN, LEFT, buff = MED_LARGE_BUFF)
- formula.to_edge(UP)
- formula.add_background_rectangle()
-
- self.add(formula)
- self.play(ShowCreation(graph))
- self.dither()
-
- self.formula = formula
- self.graph = graph
-
- def describe_as_implicit_curve(self):
- formula = self.formula #y = ln(x)
- graph = self.graph
-
- dot = Dot(color = self.example_color)
- label = TexMobject("(x, y)")
- label.add_background_rectangle()
- label.highlight(self.example_color)
-
- def update_dot(dot, alpha):
- prop = interpolate(0.1, 0.7, alpha)
- point = graph.point_from_proportion(prop)
- dot.move_to(point)
- return dot
-
- def update_label(label):
- point = dot.get_center()
- vect = point - SPACE_HEIGHT*(DOWN+RIGHT)
- vect = vect/np.linalg.norm(vect)
- label.move_to(
- point + vect*0.5*label.get_width()
+ self.introduce_line_group()
+ self.draw_function_arrows()
+ self.talk_through_movement()
+ self.nudge_x()
+ self.give_example_of_meaning()
+
+ def introduce_line_group(self):
+ self.line_group = self.get_line_group(self.start_x)
+ lines, labels = self.line_group
+
+ for line in lines:
+ self.play(Write(line, run_time = 2))
+ self.dither()
+ last_label = labels[0].copy()
+ last_label.to_corner(UP+LEFT)
+ last_label.set_fill(opacity = 0)
+ for label in labels:
+ self.play(ReplacementTransform(
+ last_label.copy(), label
+ ))
+ self.dither()
+ last_label = label
+ for x in 1, 0, self.start_x:
+ self.animate_x_change(x, run_time = 1)
+ self.dither()
+
+ def draw_function_arrows(self):
+ lines, line_labels = self.line_group
+ labels = VGroup(*[
+ TexMobject("(\\dots)^2").highlight(X_SQUARED_COLOR),
+ TexMobject("\\sin(\\dots)").highlight(SINE_COLOR)
+ ])
+ arrows = VGroup()
+ for lines_subset, label in zip([lines[:2], lines[1:]], labels):
+ arrow = Arc(start_angle = np.pi/3, angle = -2*np.pi/3)
+ arrow.add_tip()
+ arrow.highlight(label.get_color())
+ arrow.next_to(VGroup(*lines_subset))
+ arrows.add(arrow)
+ label.next_to(arrow, RIGHT)
+
+ self.play(
+ ShowCreation(arrow),
+ Write(label)
)
+ self.dither()
+ self.arrows = arrows
+ self.arrow_labels = labels
- update_dot(dot, 0)
- update_label(label)
+ def talk_through_movement(self):
+ lines, labels = self.line_group
- self.play(*map(FadeIn, [dot, label]))
+ self.animate_x_change(self.top_x, run_time = 4)
+ self.dither()
+ for label in labels[0], labels[1]:
+ oval = Circle(color = YELLOW)
+ oval.replace(label, stretch = True)
+ oval.scale(2.5)
+ oval.move_to(label.get_bottom())
+ self.play(ShowCreation(oval))
+ self.dither()
+ self.play(FadeOut(oval))
+ sine_text = TexMobject("\\sin(9) \\approx 0.412")
+ sine_text.move_to(labels[-1][-1])
+ sine_text.to_edge(DOWN)
+ sine_arrow = Arrow(
+ sine_text.get_top(),
+ labels[-1][0].get_bottom(),
+ buff = SMALL_BUFF,
+ )
self.play(
- UpdateFromAlphaFunc(dot, update_dot),
- UpdateFromFunc(label, update_label),
- run_time = 3,
+ FadeIn(sine_text),
+ ShowCreation(sine_arrow)
+ )
+ self.dither(2)
+ self.play(*map(FadeOut, [sine_text, sine_arrow]))
+ self.animate_x_change(self.example_x, run_time = 3)
+
+ def nudge_x(self):
+ lines, labels = self.line_group
+ def get_value_points():
+ return [
+ label[0].get_bottom()
+ for label in labels
+ ]
+ starts = get_value_points()
+ self.animate_x_change(self.example_x + self.dx, run_time = 0)
+ ends = get_value_points()
+ self.animate_x_change(self.example_x, run_time = 0)
+
+ nudge_lines = VGroup()
+ braces = VGroup()
+ numbers = VGroup()
+ for start, end, line, label, config in zip(starts, ends, lines, labels, self.line_configs):
+ color = label[0].get_color()
+ nudge_line = Line(start, end)
+ nudge_line.set_stroke(color, width = 6)
+ brace = Brace(nudge_line, DOWN, buff = SMALL_BUFF)
+ brace.highlight(color)
+ func_label = config["func_label"]
+ if len(func_label) == 1:
+ text = "$d%s$"%func_label
+ else:
+ text = "$d(%s)$"%func_label
+ brace.text = brace.get_text(text, buff = SMALL_BUFF)
+ brace.text.highlight(color)
+ brace.add(brace.text)
+
+ line.add(nudge_line)
+ nudge_lines.add(nudge_line)
+ braces.add(brace)
+ numbers.add(line.numbers)
+ line.remove(*line.numbers)
+ dx_brace, dx_squared_brace, dsine_brace = braces
+
+ x_value = str(self.example_x)
+ x_value_label = TexMobject("=%s"%x_value)
+ x_value_label.next_to(labels[0][1], RIGHT)
+ dx_squared_value = TexMobject(
+ "= 2x\\,dx ", "\\\\ = 2(%s)dx"%x_value
+ )
+ dx_squared_value.shift(
+ dx_squared_brace.text.get_right()+MED_SMALL_BUFF*RIGHT - \
+ dx_squared_value[0].get_left()
+ )
+ dsine_value = TextMobject(
+ "$=\\cos(%s)$"%self.line_configs[1]["func_label"],
+ dx_squared_brace.text.get_tex_string()
+ )
+ dsine_value.next_to(dsine_brace.text)
+ less_than_zero = TexMobject("<0")
+ less_than_zero.next_to(dsine_brace.text)
+
+ all_x_squared_relevant_labels = VGroup(
+ dx_squared_brace, dsine_brace,
+ labels[1], labels[2],
+ dsine_value,
+ )
+ all_x_squared_relevant_labels.save_state()
+
+ self.play(FadeOut(numbers))
+ self.animate_x_change(
+ self.example_x + self.dx,
+ run_time = 1,
+ added_anims = it.chain(
+ [GrowFromCenter(dx_brace)],
+ map(ShowCreation, nudge_lines)
+ )
)
+ self.animate_x_change(self.example_x)
self.dither()
- xy_start = VGroup(label[1][1], label[1][3]).copy()
- xy_end = VGroup(formula[1][5], formula[1][0]).copy()
- xy_end.highlight(self.example_color)
- self.play(Transform(
- xy_start, xy_end,
- run_time = 2,
- ))
+ self.play(Write(x_value_label))
+ self.dither()
+ self.play(FocusOn(dx_squared_brace))
+ self.play(Write(dx_squared_brace))
+ self.wiggle_by_dx()
+ self.dither()
+ for part in dx_squared_value:
+ self.play(Write(part))
+ self.dither()
+ self.play(FadeOut(dx_squared_value))
+ self.dither()
+ #Needs to be part of everything for the reconfiguraiton
+ dsine_brace.set_fill(opacity = 0)
+ dsine_value.set_fill(opacity = 0)
+ self.add(dsine_brace, dsine_value)
+ self.replace_x_squared_with_h()
+ self.dither()
+ self.play(dsine_brace.set_fill, None, 1)
+ self.discuss_dsine_sign(less_than_zero)
+ self.dither()
+ dsine_value.set_fill(opacity = 1)
+ self.play(Write(dsine_value))
self.dither()
self.play(
- UpdateFromAlphaFunc(dot, update_dot),
- UpdateFromFunc(label, update_label),
+ all_x_squared_relevant_labels.restore,
+ submobject_mode = "lagged_start",
+ lag_factor = 3,
run_time = 3,
- rate_func = lambda t : 1-0.6*smooth(t),
)
- self.play(*map(FadeOut, [xy_start, label]))
-
- self.dot = dot
-
- def slope_gives_derivative(self):
- dot = self.dot
- point = dot.get_center()
- line = Line(LEFT, RIGHT).scale(SPACE_WIDTH)
- slope = 1./point[0]
- line.rotate(np.arctan(slope))
- line.move_to(point)
-
- new_point = line.point_from_proportion(0.6)
- interim_point = point[0]*RIGHT + new_point[1]*UP
- dy_line = Line(point, interim_point, color = RED)
- dx_line = Line(interim_point, new_point, color = GREEN)
-
- equation = TexMobject(
- "\\text{Slope} = ",
- "\\frac{dy}{dx} = ",
- "\\frac{d(\\ln(x))}{dx}",
- )
- VGroup(*equation[1][:2]).highlight(RED)
- VGroup(*equation[2][:8]).highlight(RED)
- VGroup(*equation[1][3:5]).highlight(GREEN)
- VGroup(*equation[2][-2:]).highlight(GREEN)
- for part in equation:
- rect = BackgroundRectangle(part)
- rect.stretch_in_place(1.2, 0)
- part.add_to_back(rect)
- equation.scale(0.8)
- equation.next_to(ORIGIN, RIGHT)
- equation.to_edge(UP, buff = MED_SMALL_BUFF)
-
+ self.__dict__.update(self.__class__.CONFIG)
+ self.dither()
+ for mob in dsine_value:
+ self.play(Indicate(mob))
+ self.dither()
+ two_x_dx = dx_squared_value[0]
+ dx_squared = dsine_value[1]
+ two_x_dx_copy = VGroup(*two_x_dx[1:]).copy()
+ self.play(FocusOn(two_x_dx))
+ self.play(Write(two_x_dx))
self.play(
- GrowFromCenter(line),
- Animation(dot)
+ two_x_dx_copy.move_to, dx_squared, LEFT,
+ dx_squared.next_to, dx_squared, UP,
+ run_time = 2
)
- self.play(ShowCreation(VGroup(dy_line, dx_line)))
- for part in equation:
- self.play(Write(part, run_time = 2))
+ self.play(FadeOut(dx_squared))
+ for sublist in two_x_dx_copy[:2], two_x_dx_copy[2:]:
+ self.play(Indicate(VGroup(*sublist)))
+ self.dither()
+ self.dither(2)
+
+ self.final_derivative = dsine_value
+
+ def discuss_dsine_sign(self, less_than_zero):
+ self.wiggle_by_dx()
+ self.dither()
+ for x in self.example_x+self.dx, self.example_x:
+ self.animate_x_change(x, run_time = 2)
+ self.dither()
+ if less_than_zero not in self.get_mobjects():
+ self.play(Write(less_than_zero))
+ else:
+ self.play(FadeOut(less_than_zero))
+
+ def replace_x_squared_with_h(self):
+ new_config = copy.deepcopy(self.__class__.CONFIG)
+ new_config["line_configs"][1]["func_label"] = "h"
+ new_config["line_configs"][2]["func_label"] = "\\sin(h)"
+ self.transition_to_alt_config(
+ return_to_original_configuration = False,
+ **new_config
+ )
+
+ def give_example_of_meaning(self):
+ words = TextMobject("For example,")
+ expression = TexMobject("\\cos(1.5^2)\\cdot 2(1.5)\\,dx")
+ group = VGroup(words, expression)
+ group.arrange_submobjects(DOWN, aligned_edge = LEFT)
+ group.scale(0.8)
+ group.to_edge(RIGHT)
+ arrow = Arrow(group.get_bottom(), self.final_derivative[0].get_top())
+
+ self.play(*map(FadeOut, [self.arrows, self.arrow_labels]))
+ self.play(FadeIn(group))
+ self.play(ShowCreation(arrow))
+ self.dither()
+ self.wiggle_by_dx()
self.dither()
- self.dx_line, self.dy_line = dx_line, dy_line
- self.slope_equation = equation
- self.tangent_line = line
- def rearrange_equation(self):
- formula = self.formula
- y, eq = formula[1][:2]
- ln = VGroup(*formula[1][2:4])
- x = formula[1][5]
+ ########
- new_formula = TexMobject("e", "^y", "=", "x")
- e, new_y, new_eq, new_x = new_formula
- new_formula.next_to(
- formula, DOWN,
- buff = MED_LARGE_BUFF,
- )
- rect = BackgroundRectangle(new_formula)
+ def wiggle_by_dx(self, **kwargs):
+ kwargs["run_time"] = kwargs.get("run_time", 1)
+ kwargs["rate_func"] = kwargs.get("rate_func", there_and_back)
+ target_x = self.line_group.x_val + self.dx
+ self.animate_x_change(target_x, **kwargs)
- y = new_y.copy().replace(y)
- self.play(Indicate(formula, scale_factor = 1))
- self.play(ReplacementTransform(ln.copy(), e))
- self.play(ReplacementTransform(y, new_y))
- self.play(ReplacementTransform(eq.copy(), new_eq))
+ def animate_x_change(self, target_x, **kwargs):
+ #Assume fixed lines, only update labels
+ kwargs["run_time"] = kwargs.get("run_time", 2)
+ added_anims = kwargs.get("added_anims", [])
+ start_x = self.line_group.x_val
+ def update(line_group, alpha):
+ lines, labels = line_group
+ new_x = interpolate(start_x, target_x, alpha)
+ for line, label, config in zip(lines, labels, self.line_configs):
+ new_label = self.get_line_label(
+ line, new_x, **config
+ )
+ Transform(label, new_label).update(1)
+ line_group.x_val = new_x
self.play(
- FadeIn(rect),
- Animation(VGroup(e, new_y, new_eq)),
- ReplacementTransform(x.copy(), new_x)
+ UpdateFromAlphaFunc(self.line_group, update),
+ *added_anims,
+ **kwargs
)
- self.dither(2)
- for mob in e, new_y, new_x:
- self.play(Indicate(mob))
- self.dither()
- self.new_formula = new_formula
+ def get_line_group(self, x):
+ group = VGroup()
+ group.lines, group.labels = VGroup(), VGroup()
+ for line_config in self.line_configs:
+ number_line = self.get_number_line(**line_config)
+ label = self.get_line_label(number_line, x, **line_config)
+ group.lines.add(number_line)
+ group.labels.add(label)
+ group.add(group.lines, group.labels)
+ group.x_val = x
+ return group
+
+ def get_number_line(
+ self, center_y, **number_line_config
+ ):
+ number_line = NumberLine(color = GREY, **number_line_config)
+ number_line.stretch_to_fit_width(self.line_width)
+ number_line.add_numbers()
+ number_line.shift(center_y*UP)
+ number_line.to_edge(LEFT, buff = LARGE_BUFF)
+
+ return number_line
+
+ def get_line_label(
+ self, number_line, x, func, func_label, triangle_color,
+ **spillover_kwargs
+ ):
+ triangle = RegularPolygon(
+ n=3, start_angle = -np.pi/2,
+ fill_color = triangle_color,
+ fill_opacity = 0.75,
+ stroke_width = 0,
+ )
+ triangle.scale_to_fit_height(self.triangle_height)
+ triangle.move_to(
+ number_line.number_to_point(func(x)), DOWN
+ )
- def take_derivative(self):
- new_formula = self.new_formula
- e, y, eq, x = new_formula
- derivative = TexMobject("e", "^y", "\\,dy", "=", "dx")
- new_e, new_y, dy, new_eq, dx = derivative
- derivative.next_to(new_formula, DOWN, MED_LARGE_BUFF)
- derivative.add_background_rectangle()
- dx.highlight(GREEN)
- dy.highlight(RED)
+ label_mob = TexMobject(func_label)
+ label_mob.next_to(triangle, UP, buff = SMALL_BUFF, aligned_edge = LEFT)
- pairs = [
- (VGroup(e, y), VGroup(new_e, new_y)),
- (new_y, dy),
- (eq, new_eq),
- (x, dx)
- ]
- for start, target in pairs:
- self.play(
- ReplacementTransform(start.copy(), target)
- )
- self.play(FadeIn(derivative[0]), Animation(derivative[1]))
- self.remove(derivative, pairs[0][1])
- self.add(derivative)
- self.dither()
-
- self.derivative = derivative
-
- def show_tiny_nudge(self):
- dot = self.dot
- point = dot.get_center()
- dx_line = self.dx_line
- dy_line = self.dy_line
- group = VGroup(dot, dx_line, dy_line)
- self.play(group.scale, 1./self.zoom_factor, point)
- for line, tex, vect in (dx_line, "dx", UP), (dy_line, "dy", LEFT):
- label = TexMobject(tex)
- label.add_background_rectangle()
- label.next_to(line, vect, buff = SMALL_BUFF)
- label.highlight(line.get_color())
- label.scale(
- 1./self.zoom_factor,
- about_point = line.get_center()
- )
- line.label = label
+ return VGroup(triangle, label_mob)
- self.activate_zooming()
- lil_rect = self.little_rectangle
- lil_rect.move_to(group)
- lil_rect.scale_in_place(self.zoom_factor)
- self.play(lil_rect.scale_in_place, 1./self.zoom_factor)
- self.play(Write(dx_line.label))
- self.play(Write(dy_line.label))
+class GeneralizeChainRule(Scene):
+ def construct(self):
+ example = TexMobject(
+ "\\frac{d}{dx}", "\\sin(", "x^2", ")", "=",
+ "\\cos(", "x^2", ")", "\\,2x",
+ )
+ general = TexMobject(
+ "\\frac{d}{dx}", "g(", "h(x)", ")", "=",
+ "{dg \\over ", " dh}", "(", "h(x)", ")", "{dh \\over", " dx}", "(x)"
+ )
+ example.to_edge(UP, buff = LARGE_BUFF)
+ example.shift(RIGHT)
+ general.next_to(example, DOWN, buff = 1.5*LARGE_BUFF)
+ for mob in example, general:
+ mob.highlight(SINE_COLOR)
+ mob[0].highlight(WHITE)
+ for tex in "x^2", "2x", "(x)", "{dh", " dx}":
+ mob.highlight_by_tex(tex, X_SQUARED_COLOR, substring = True)
+
+ example_outer = VGroup(*example[1:4])
+ example_inner = example[2]
+ d_example_outer = VGroup(*example[5:8])
+ d_example_inner = example[6]
+ d_example_d_inner = example[8]
+
+ general_outer = VGroup(*general[1:4])
+ general_inner = general[2]
+ d_general_outer = VGroup(*general[5:10])
+ d_general_inner = general[8]
+ d_general_d_inner = VGroup(*general[10:13])
+
+ example_outer_brace = Brace(example_outer)
+ example_inner_brace = Brace(example_inner, UP, buff = SMALL_BUFF)
+ d_example_outer_brace = Brace(d_example_outer)
+ d_example_inner_brace = Brace(d_example_inner, buff = SMALL_BUFF)
+ d_example_d_inner_brace = Brace(d_example_d_inner, UP, buff = SMALL_BUFF)
+
+ general_outer_brace = Brace(general_outer)
+ general_inner_brace = Brace(general_inner, UP, buff = SMALL_BUFF)
+ d_general_outer_brace = Brace(d_general_outer)
+ d_general_inner_brace = Brace(d_general_inner, buff = SMALL_BUFF)
+ d_general_d_inner_brace = Brace(d_general_d_inner, UP, buff = SMALL_BUFF)
+
+ for brace in example_outer_brace, general_outer_brace:
+ brace.text = brace.get_text("Outer")
+ for brace in example_inner_brace, general_inner_brace:
+ brace.text = brace.get_text("Inner")
+ for brace in d_example_outer_brace, d_general_outer_brace:
+ brace.text = brace.get_text("d(Outer)")
+ brace.text.shift(SMALL_BUFF*LEFT)
+ for brace in d_example_d_inner_brace, d_general_d_inner_brace:
+ brace.text = brace.get_text("d(Inner)", buff = SMALL_BUFF)
+
+ #d(out)d(in) for example
+ self.add(example)
+ braces = VGroup(
+ example_outer_brace,
+ example_inner_brace,
+ d_example_outer_brace
+ )
+ for brace in braces:
+ self.play(GrowFromCenter(brace))
+ self.play(Write(brace.text, run_time = 1))
+ self.dither()
self.dither()
-
- def note_derivatives(self):
- e, y, dy, eq, dx = self.derivative[1]
-
- self.play(FocusOn(e))
- self.play(Indicate(VGroup(e, y, dy)))
+ self.play(*it.chain(*[
+ [mob.scale_in_place, 1.2, mob.highlight, YELLOW]
+ for mob in example_inner, d_example_inner
+ ]), rate_func = there_and_back)
+ self.play(Transform(
+ example_inner.copy(), d_example_inner,
+ path_arc = -np.pi/2,
+ remover = True
+ ))
self.dither()
- self.play(Indicate(dx))
+ self.play(
+ GrowFromCenter(d_example_d_inner_brace),
+ Write(d_example_d_inner_brace.text)
+ )
+ self.play(Transform(
+ VGroup(*reversed(example_inner.copy())),
+ d_example_d_inner,
+ path_arc = -np.pi/2,
+ run_time = 2,
+ remover = True
+ ))
self.dither()
- def solve_for_dy_dx(self):
- e, y, dy, eq, dx = self.derivative[1]
- ey_group = VGroup(e, y)
- original_rect = self.derivative[0]
-
- rearranged = TexMobject(
- "{dy \\over ", " dx}", "=", "{1 \\over ", "e", "^y}"
+ #Generalize
+ self.play(*map(FadeIn, general[:5]))
+ self.dither()
+ self.play(
+ Transform(example_outer_brace, general_outer_brace),
+ Transform(example_outer_brace.text, general_outer_brace.text),
+ Transform(example_inner_brace, general_inner_brace),
+ Transform(example_inner_brace.text, general_inner_brace.text),
)
- new_dy, new_dx, new_eq, one_over, new_e, new_y = rearranged
- new_ey_group = VGroup(new_e, new_y)
- new_dx.highlight(GREEN)
- new_dy.highlight(RED)
- rearranged.shift(eq.get_center() - new_eq.get_center())
- rearranged.shift(MED_SMALL_BUFF*DOWN)
- new_rect = BackgroundRectangle(rearranged)
-
- self.play(*[
- ReplacementTransform(
- m1, m2,
- run_time = 2,
- path_arc = -np.pi/2,
- )
- for m1, m2 in [
- (original_rect, new_rect),
- (dx, new_dx),
- (dy, new_dy),
- (eq, new_eq),
- (ey_group, new_ey_group),
- (e.copy(), one_over)
- ]
- ])
self.dither()
-
- #Change denominator
- e, y, eq, x = self.new_formula
- ey_group = VGroup(e, y).copy()
- ey_group.highlight(YELLOW)
- x_copy = x.copy()
-
- self.play(new_ey_group.highlight, YELLOW)
- self.play(Transform(new_ey_group, ey_group))
self.play(
- new_ey_group.highlight, WHITE,
- x_copy.highlight, YELLOW
+ Transform(d_example_outer_brace, d_general_outer_brace),
+ Transform(d_example_outer_brace.text, d_general_outer_brace.text),
+ )
+ self.play(Write(d_general_outer))
+ self.dither(2)
+ self.play(
+ Transform(d_example_d_inner_brace, d_general_d_inner_brace),
+ Transform(d_example_d_inner_brace.text, d_general_d_inner_brace.text),
)
- self.play(x_copy.next_to, one_over, DOWN, MED_SMALL_BUFF)
+ self.play(Write(d_general_d_inner))
self.dither(2)
- equals_one_over_x = VGroup(
- new_eq, one_over, x_copy
- ).copy()
- rect = BackgroundRectangle(equals_one_over_x)
- rect.stretch_in_place(1.1, dim = 0)
- equals_one_over_x.add_to_back(rect)
+ #Name chain rule
+ name = TextMobject("``Chain rule''")
+ name.scale(1.2)
+ name.highlight(YELLOW)
+ name.to_corner(UP+LEFT)
+ self.play(Write(name))
+ self.dither()
+ #Point out dh bottom
+ morty = Mortimer().flip()
+ morty.to_corner(DOWN+LEFT)
+ d_general_outer_copy = d_general_outer.copy()
+ morty.set_fill(opacity = 0)
self.play(
- equals_one_over_x.next_to,
- self.slope_equation, RIGHT, 0,
- run_time = 2
+ morty.set_fill, None, 1,
+ morty.change_mode, "raise_left_hand",
+ morty.look, UP+LEFT,
+ d_general_outer_copy.next_to,
+ morty.get_corner(UP+LEFT), UP, MED_LARGE_BUFF,
+ d_general_outer_copy.shift_onto_screen
)
+ self.dither()
+ circle = Circle(color = YELLOW)
+ circle.replace(d_general_outer_copy[1])
+ circle.scale_in_place(1.4)
+ self.play(ShowCreation(circle))
+ self.play(Blink(morty))
self.dither()
-
- def show_slope_above_x(self):
- line = self.tangent_line
- start_x = line.get_center()[0]
- target_x = 0.2
- graph = FunctionGraph(
- lambda x : 1./x,
- x_min = 0.1,
- x_max = SPACE_WIDTH,
- num_steps = 100,
- color = PINK,
+ inner = d_general_outer_copy[3]
+ self.play(
+ morty.change_mode, "hooray",
+ morty.look_at, inner,
+ inner.shift, UP
)
+ self.play(inner.shift, DOWN)
+ self.dither()
+ self.play(morty.change_mode, "pondering")
+ self.play(Blink(morty))
+ self.dither()
+ self.play(*map(FadeOut, [
+ d_general_outer_copy, inner, circle
+ ]))
- def update_line(line, alpha):
- x = interpolate(start_x, target_x, alpha)
- point = x*RIGHT + np.log(x)*UP
- angle = np.arctan(1./x)
- line.rotate(angle - line.get_angle())
- line.move_to(point)
-
- self.play(UpdateFromAlphaFunc(
- line, update_line,
- rate_func = there_and_back,
- run_time = 6
+ #Show cancelation
+ braces = [
+ d_example_d_inner_brace,
+ d_example_outer_brace,
+ example_inner_brace,
+ example_outer_brace,
+ ]
+ texts = [brace.text for brace in braces]
+ self.play(*map(FadeOut, braces+texts))
+
+ to_collapse = VGroup(VGroup(*general[7:10]), general[12])
+ dg_dh = VGroup(*general[5:7])
+ dh_dx = VGroup(*general[10:12])
+ to_collapse.generate_target()
+ points = VGroup(*map(VectorizedPoint,
+ [m.get_left() for m in to_collapse]
))
+ self.play(
+ Transform(to_collapse, points),
+ dh_dx.next_to, dg_dh,
+ morty.look_at, dg_dh,
+ )
self.dither()
- self.play(ShowCreation(graph, run_time = 3))
+ for mob in list(dg_dh)+list(dh_dx):
+ circle = Circle(color = YELLOW)
+ circle.replace(mob)
+ circle.scale_in_place(1.3)
+ self.play(ShowCreation(circle))
+ self.dither()
+ self.play(FadeOut(circle))
+
+ strikes = VGroup()
+ for dh in dg_dh[1], dh_dx[0]:
+ strike = TexMobject("/")
+ strike.stretch(2, dim = 0)
+ strike.rotate(-np.pi/12)
+ strike.move_to(dh)
+ strike.highlight(RED)
+ strikes.add(strike)
+ self.play(Write(strikes))
+ self.play(morty.change_mode, "hooray")
+ equals_dg_dx = TexMobject("= \\frac{dg}{dx}")
+ equals_dg_dx.next_to(dh_dx)
+ self.play(Write(equals_dg_dx))
+ self.play(Blink(morty))
+ self.dither(2)
+
+ ##More than a notational trick
+ self.play(
+ PiCreatureSays(morty, """
+ This is more than a
+ notational trick
+ """),
+ VGroup(
+ dg_dh, dh_dx, equals_dg_dx, strikes,
+ *general[:5]
+ ).shift, DOWN,
+ FadeOut(example)
+ )
self.dither()
- self.play(UpdateFromAlphaFunc(
- line, update_line,
- rate_func = there_and_back,
- run_time = 6
- ))
+ self.play(Blink(morty))
self.dither()
-class FinalWords(TeacherStudentsScene):
+class WatchingVideo(PiCreatureScene):
def construct(self):
- words = TextMobject(
- "This is a peek into \\\\",
- "Multivariable", "calculus"
+ laptop = Laptop()
+ laptop.scale(2)
+ laptop.to_corner(UP+RIGHT)
+ randy = self.get_primary_pi_creature()
+ randy.move_to(laptop, DOWN+LEFT)
+ randy.shift(MED_SMALL_BUFF*UP)
+ randy.look_at(laptop.screen)
+
+
+ formulas = VGroup(*[
+ TexMobject("\\frac{d}{dx}\\left( %s \\right)"%s)
+ for s in [
+ "e^x \\sin(x)",
+ "\\sin(x) \\cdot \\frac{1}{\\cos(x)}",
+ "\\cos(3x)^2",
+ "e^x(x^2 + 3x + 2)",
+ ]
+ ])
+ formulas.arrange_submobjects(
+ DOWN,
+ buff = MED_LARGE_BUFF,
+ aligned_edge = LEFT
)
- mvc = VGroup(*words[1:])
- words.highlight_by_tex("Multivariable", YELLOW)
- formula = TexMobject("f(x, y) = \\sin(x)y^2")
- formula.next_to(self.get_teacher().get_corner(UP+LEFT), UP)
+ formulas.next_to(randy, LEFT, buff = MED_LARGE_BUFF)
+ formulas.shift_onto_screen()
- self.teacher_says(words)
- self.change_student_modes("erm", "hooray", "sassy")
- self.play(
- FadeOut(self.teacher.bubble),
- FadeOut(VGroup(*words[:1])),
- mvc.to_corner, UP+LEFT,
- self.teacher.change_mode, "raise_right_hand",
- self.teacher.look_at, formula,
- Write(formula, run_time = 2),
- )
- self.change_student_modes("pondering", "confused", "thinking")
- self.dither(3)
+ self.add(randy, laptop)
+ self.dither()
+ self.play(randy.change_mode, "erm")
+ self.play(Blink(randy))
+ self.dither()
+ self.play(randy.change_mode, "maybe")
+ self.dither()
+ self.play(Blink(randy))
+ for formula in formulas:
+ self.play(
+ Write(formula, run_time = 2),
+ randy.change_mode, "thinking"
+ )
+ self.dither()
+
+ def create_pi_creatures(self):
+ return [Randolph().shift(DOWN+RIGHT)]
- ##Show series
+class NextVideo(TeacherStudentsScene):
+ def construct(self):
series = VideoSeries()
series.to_edge(UP)
- video = series[5]
- lim = TexMobject("\\lim_{h \\to 0} \\frac{f(x+h)-f(x)}{h}")
+ next_video = series[4]
+
+ pre_expression = TexMobject(
+ "x", "^2", "+", "y", "^2", "=", "1"
+ )
+ d_expression = TexMobject(
+ "2", "x", "\\,dx", "+", "2", "y", "\\,dy", "=", "0"
+ )
+ expression_to_d_expression_indices = [
+ 1, 0, 0, 2, 4, 3, 3, 5, 6
+ ]
+ expression = VGroup()
+ for i, j in enumerate(expression_to_d_expression_indices):
+ submob = pre_expression[j].copy()
+ if d_expression.expression_parts[i] == "2":
+ two = TexMobject("2")
+ two.replace(submob)
+ expression.add(two)
+ else:
+ expression.add(submob)
+
+ for mob in expression, d_expression:
+ mob.scale(1.2)
+ mob.next_to(
+ self.get_teacher().get_corner(UP+LEFT), UP,
+ buff = MED_LARGE_BUFF
+ )
+ mob.shift_onto_screen()
+
+ axes = Axes(x_min = -3, x_max = 3, color = GREY)
+ axes.add(Circle(color = YELLOW))
+ line = Line(np.sqrt(2)*UP, np.sqrt(2)*RIGHT)
+ line.scale_in_place(1.5)
+ axes.add(line)
+
+ axes.scale(0.5)
+ axes.next_to(d_expression, LEFT)
+
+ self.add(series)
self.play(
- FadeOut(mvc),
- FadeOut(formula),
- self.teacher.change_mode, "plain",
- FadeIn(
- series, run_time = 2,
- submobject_mode = "lagged_start",
- ),
+ next_video.shift, 0.5*DOWN,
+ next_video.highlight, YELLOW,
+ self.get_teacher().change_mode, "raise_right_hand"
)
+ self.dither()
self.play(
- video.highlight, YELLOW,
- video.shift, video.get_height()*DOWN/2
+ Write(expression),
+ *[
+ ApplyMethod(pi.change_mode, "pondering")
+ for pi in self.get_students()
+ ]
)
- lim.next_to(video, DOWN)
+ self.play(FadeIn(axes))
+ self.dither()
+ self.remove(expression)
+ self.play(Transform(expression, d_expression, path_arc = np.pi/2))
+ self.dither()
self.play(
- Write(lim),
- *it.chain(*[
- [pi.change_mode, "pondering", pi.look_at, lim]
- for pi in self.get_pi_creatures()
- ])
+ Rotate(
+ line, np.pi/4,
+ about_point = axes.get_center(),
+ rate_func = wiggle,
+ run_time = 3
+ )
)
- self.dither(3)
+ self.dither(2)
-class Chapter5PatreonThanks(PatreonThanks):
+class Chapter4Thanks(PatreonThanks):
CONFIG = {
"specific_patrons" : [
"Ali Yahya",
"Meshal Alshammari",
"CrypticSwarm ",
- "Nathan Pellegrin",
- "Karan Bhargava",
- "Justin Helps",
"Ankit Agarwal",
"Yu Jun",
+ "Shelby Doolittle",
"Dave Nicponski",
"Damion Kistler",
"Juan Benet",
@@ -2661,11 +2256,7 @@ class Chapter5PatreonThanks(PatreonThanks):
"Derek Dai",
"Joseph John Cox",
"Luc Ritchie",
- "Daan Smedinga",
- "Jonathan Eppele",
"Nils Schneider",
- "Albert Nguyen",
- "Mustafa Mahdi",
"Mathew Bramson",
"Guido Gambardella",
"Jerry Ling",
@@ -2680,25 +2271,36 @@ class Chapter5PatreonThanks(PatreonThanks):
]
}
-class Thumbnail(AlternateExample):
+class Thumbnail(IntroduceProductAsArea):
+ CONFIG = {
+ "default_x" : 0.8,
+ "dx" : 0.05
+ }
def construct(self):
- title = VGroup(*map(TextMobject, [
- "Implicit", "Differentiation"
- ]))
- title.arrange_submobjects(DOWN)
- title.scale(3)
- title.next_to(ORIGIN, UP)
+ self.x_slider = self.get_x_slider(self.default_x)
+ blg = self.box_label_group = self.get_box_label_group(
+ self.default_x
+ )
+ df_boxes = self.get_df_boxes()
+ df_boxes.space_out_submobjects(1.1)
+ df_boxes.move_to(blg[0], UP+LEFT)
+ blg[1][1].next_to(df_boxes[-1], RIGHT)
+ df_box_labels = self.get_df_box_labels(df_boxes)
+ blg.add(df_boxes, df_box_labels)
+ blg.scale_to_fit_height(2*SPACE_HEIGHT-2*MED_LARGE_BUFF)
+ blg.center()
+ self.add(blg)
+
+
+
+
+
+
+
- for word in title:
- word.add_background_rectangle()
- self.add_plane()
- self.draw_graph()
- self.graphs.set_stroke(width = 8)
- self.remove(self.formula)
- self.add(title)
@@ -2707,37 +2309,6 @@ class Thumbnail(AlternateExample):
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/eoc/chapter6.py b/eoc/chapter6.py
new file mode 100644
index 000000000..f33cc99e7
--- /dev/null
+++ b/eoc/chapter6.py
@@ -0,0 +1,2755 @@
+from helpers import *
+
+from mobject.tex_mobject import TexMobject
+from mobject import Mobject
+from mobject.image_mobject import ImageMobject
+from mobject.vectorized_mobject import *
+
+from animation.animation import Animation
+from animation.transform import *
+from animation.simple_animations import *
+from animation.playground import *
+from topics.geometry import *
+from topics.characters import *
+from topics.functions import *
+from topics.fractals import *
+from topics.number_line import *
+from topics.combinatorics import *
+from topics.numerals import *
+from topics.three_dimensions import *
+from topics.objects import *
+from scene import Scene
+from scene.zoomed_scene import ZoomedScene
+from scene.reconfigurable_scene import ReconfigurableScene
+from camera import Camera
+from mobject.svg_mobject import *
+from mobject.tex_mobject import *
+
+from topics.common_scenes import *
+from eoc.graph_scene import *
+
+SPACE_UNIT_TO_PLANE_UNIT = 0.75
+
+class Chapter6OpeningQuote(OpeningQuote):
+ CONFIG = {
+ "quote" : [
+ "Do not ask whether a ",
+ "statement is true until",
+ "you know what it means."
+ ],
+ "author" : "Errett Bishop"
+ }
+
+class ThisWasConfusing(TeacherStudentsScene):
+ def construct(self):
+ words = TextMobject("Implicit differentiation")
+ words.move_to(self.get_teacher().get_corner(UP+LEFT), DOWN+RIGHT)
+ words.set_fill(opacity = 0)
+
+ self.play(
+ self.get_teacher().change_mode, "raise_right_hand",
+ words.set_fill, None, 1,
+ words.shift, 0.5*UP
+ )
+ self.change_student_modes(
+ *["confused"]*3,
+ look_at_arg = words,
+ added_anims = [Animation(self.get_teacher())]
+ )
+ self.dither()
+ self.play(
+ self.get_teacher().change_mode, "confused",
+ self.get_teacher().look_at, words,
+ )
+ self.dither(3)
+
+class SlopeOfCircleExample(ZoomedScene):
+ CONFIG = {
+ "plane_kwargs" : {
+ "x_radius" : SPACE_WIDTH/SPACE_UNIT_TO_PLANE_UNIT,
+ "y_radius" : SPACE_HEIGHT/SPACE_UNIT_TO_PLANE_UNIT,
+ "space_unit_to_x_unit" : SPACE_UNIT_TO_PLANE_UNIT,
+ "space_unit_to_y_unit" : SPACE_UNIT_TO_PLANE_UNIT,
+ },
+ "example_point" : (3, 4),
+ "circle_radius" : 5,
+ "circle_color" : YELLOW,
+ "example_color" : MAROON_B,
+ "zoom_factor" : 20,
+ "zoomed_canvas_corner" : UP+LEFT,
+ "zoomed_canvas_corner_buff" : MED_SMALL_BUFF,
+ }
+ def construct(self):
+ self.setup_plane()
+ self.introduce_circle()
+ self.talk_through_pythagorean_theorem()
+ self.draw_example_slope()
+ self.show_perpendicular_radius()
+ self.show_dx_and_dy()
+ self.write_slope_as_dy_dx()
+ self.point_out_this_is_not_a_graph()
+ self.perform_implicit_derivative()
+ self.show_final_slope()
+
+ def setup_plane(self):
+ self.plane = NumberPlane(**self.plane_kwargs)
+ self.plane.main_lines.fade()
+ self.plane.add(self.plane.get_axis_labels())
+ self.plane.add_coordinates()
+
+ self.add(self.plane)
+
+ def introduce_circle(self):
+ circle = Circle(
+ radius = self.circle_radius*SPACE_UNIT_TO_PLANE_UNIT,
+ color = self.circle_color,
+ )
+ equation = TexMobject("x^2 + y^2 = 5^2")
+ equation.add_background_rectangle()
+ equation.next_to(
+ circle.point_from_proportion(1./8),
+ UP+RIGHT
+ )
+ equation.to_edge(RIGHT)
+
+ self.play(ShowCreation(circle, run_time = 2))
+ self.play(Write(equation))
+ self.dither()
+
+ self.circle = circle
+ self.circle_equation = equation
+
+ def talk_through_pythagorean_theorem(self):
+ point = self.plane.num_pair_to_point(self.example_point)
+ x_axis_point = point[0]*RIGHT
+ dot = Dot(point, color = self.example_color)
+
+ x_line = Line(ORIGIN, x_axis_point, color = GREEN)
+ y_line = Line(x_axis_point, point, color = RED)
+ radial_line = Line(ORIGIN, point, color = self.example_color)
+ lines = VGroup(radial_line, x_line, y_line)
+ labels = VGroup()
+
+ self.play(ShowCreation(dot))
+ for line, tex in zip(lines, "5xy"):
+ label = TexMobject(tex)
+ label.highlight(line.get_color())
+ label.add_background_rectangle()
+ label.next_to(
+ line.get_center(),
+ rotate_vector(UP, line.get_angle()),
+ buff = SMALL_BUFF
+ )
+ self.play(
+ ShowCreation(line),
+ Write(label)
+ )
+ labels.add(label)
+
+ full_group = VGroup(dot, lines, labels)
+ start_angle = angle_of_vector(point)
+ end_angle = np.pi/12
+ spatial_radius = np.linalg.norm(point)
+ def update_full_group(group, alpha):
+ dot, lines, labels = group
+ angle = interpolate(start_angle, end_angle, alpha)
+ new_point = spatial_radius*rotate_vector(RIGHT, angle)
+ new_x_axis_point = new_point[0]*RIGHT
+ dot.move_to(new_point)
+
+ radial_line, x_line, y_line = lines
+ x_line.put_start_and_end_on(ORIGIN, new_x_axis_point)
+ y_line.put_start_and_end_on(new_x_axis_point, new_point)
+ radial_line.put_start_and_end_on(ORIGIN, new_point)
+ for line, label in zip(lines, labels):
+ label.next_to(
+ line.get_center(),
+ rotate_vector(UP, line.get_angle()),
+ buff = SMALL_BUFF
+ )
+ return group
+
+ self.play(UpdateFromAlphaFunc(
+ full_group, update_full_group,
+ rate_func = there_and_back,
+ run_time = 5,
+ ))
+ self.dither(2)
+
+ #Move labels to equation
+ movers = labels.copy()
+ pairs = zip(
+ [movers[1], movers[2], movers[0]],
+ self.circle_equation[1][0:-1:3]
+ )
+ self.play(*[
+ ApplyMethod(m1.replace, m2)
+ for m1, m2 in pairs
+ ])
+ self.dither()
+
+ self.play(*map(FadeOut, [lines, labels, movers]))
+ self.remove(full_group)
+ self.add(dot)
+ self.dither()
+
+ self.example_point_dot = dot
+
+ def draw_example_slope(self):
+ point = self.example_point_dot.get_center()
+ line = Line(ORIGIN, point)
+ line.highlight(self.example_color)
+ line.rotate(np.pi/2)
+ line.scale(2)
+ line.move_to(point)
+
+ word = TextMobject("Slope?")
+ word.next_to(line.get_start(), UP, aligned_edge = LEFT)
+ word.add_background_rectangle()
+
+ coords = TexMobject("(%d, %d)"%self.example_point)
+ coords.add_background_rectangle()
+ coords.scale(0.7)
+ coords.next_to(point, LEFT)
+ coords.shift(SMALL_BUFF*DOWN)
+ coords.highlight(self.example_color)
+
+ self.play(GrowFromCenter(line))
+ self.play(Write(word))
+ self.dither()
+ self.play(Write(coords))
+ self.dither()
+
+ self.tangent_line = line
+ self.slope_word = word
+ self.example_point_coords_mob = coords
+
+ def show_perpendicular_radius(self):
+ point = self.example_point_dot.get_center()
+ radial_line = Line(ORIGIN, point, color = RED)
+
+ perp_mark = VGroup(
+ Line(UP, UP+RIGHT),
+ Line(UP+RIGHT, RIGHT),
+ )
+ perp_mark.scale(0.2)
+ perp_mark.set_stroke(width = 2)
+ perp_mark.rotate(radial_line.get_angle()+np.pi)
+ perp_mark.shift(point)
+
+ self.play(ShowCreation(radial_line))
+ self.play(ShowCreation(perp_mark))
+ self.dither()
+ self.play(Indicate(perp_mark))
+ self.dither()
+
+ morty = Mortimer().flip().to_corner(DOWN+LEFT)
+ self.play(FadeIn(morty))
+ self.play(PiCreatureBubbleIntroduction(
+ morty, "Suppose you \\\\ don't know this.",
+ ))
+ to_fade =self.get_mobjects_from_last_animation()
+ self.play(Blink(morty))
+ self.dither()
+
+ self.play(*map(FadeOut, to_fade))
+ self.play(*map(FadeOut, [radial_line, perp_mark]))
+ self.dither()
+
+ def show_dx_and_dy(self):
+ dot = self.example_point_dot
+ point = dot.get_center()
+ step_vect = rotate_vector(point, np.pi/2)
+ step_length = 1./self.zoom_factor
+ step_vect *= step_length/np.linalg.norm(step_vect)
+
+ step_line = Line(ORIGIN, LEFT)
+ step_line.highlight(WHITE)
+ brace = Brace(step_line, DOWN)
+ step_text = brace.get_text("Step", buff = SMALL_BUFF)
+ step_group = VGroup(step_line, brace, step_text)
+ step_group.rotate(angle_of_vector(point) - np.pi/2)
+ step_group.scale(1./self.zoom_factor)
+ step_group.shift(point)
+
+ interim_point = step_line.get_corner(UP+RIGHT)
+ dy_line = Line(point, interim_point)
+ dx_line = Line(interim_point, point+step_vect)
+ dy_line.highlight(RED)
+ dx_line.highlight(GREEN)
+ for line, tex in (dx_line, "dx"), (dy_line, "dy"):
+ label = TexMobject(tex)
+ label.scale(1./self.zoom_factor)
+ next_to_vect = np.round(
+ rotate_vector(DOWN, line.get_angle())
+ )
+ label.next_to(
+ line, next_to_vect,
+ buff = MED_SMALL_BUFF/self.zoom_factor
+ )
+ label.highlight(line.get_color())
+ line.label = label
+
+ self.activate_zooming()
+ self.little_rectangle.move_to(step_line.get_center())
+ self.little_rectangle.save_state()
+ self.little_rectangle.scale_in_place(self.zoom_factor)
+ self.dither()
+ self.play(
+ self.little_rectangle.restore,
+ dot.scale_in_place, 1./self.zoom_factor,
+ run_time = 2
+ )
+ self.dither()
+ self.play(ShowCreation(step_line))
+ self.play(GrowFromCenter(brace))
+ self.play(Write(step_text))
+ self.dither()
+ for line in dy_line, dx_line:
+ self.play(ShowCreation(line))
+ self.play(Write(line.label))
+ self.dither()
+ self.dither()
+
+ self.step_group = step_group
+ self.dx_line = dx_line
+ self.dy_line = dy_line
+
+ def write_slope_as_dy_dx(self):
+ slope_word = self.slope_word
+ new_slope_word = TextMobject("Slope =")
+ new_slope_word.add_background_rectangle()
+ new_slope_word.next_to(ORIGIN, RIGHT)
+ new_slope_word.shift(slope_word.get_center()[1]*UP)
+
+ dy_dx = TexMobject("\\frac{dy}{dx}")
+ VGroup(*dy_dx[:2]).highlight(RED)
+ VGroup(*dy_dx[-2:]).highlight(GREEN)
+ dy_dx.next_to(new_slope_word, RIGHT)
+ dy_dx.add_background_rectangle()
+
+ self.play(Transform(slope_word, new_slope_word))
+ self.play(Write(dy_dx))
+ self.dither()
+
+ self.dy_dx = dy_dx
+
+ def point_out_this_is_not_a_graph(self):
+ equation = self.circle_equation
+ x = equation[1][0]
+ y = equation[1][3]
+ brace = Brace(equation, DOWN)
+ brace_text = brace.get_text(
+ "Not $y = f(x)$",
+ buff = SMALL_BUFF
+ )
+ brace_text.highlight(RED)
+ alt_brace_text = brace.get_text("Implicit curve")
+ for text in brace_text, alt_brace_text:
+ text.add_background_rectangle()
+ text.to_edge(RIGHT, buff = MED_SMALL_BUFF)
+
+ new_circle = self.circle.copy()
+ new_circle.highlight(BLUE)
+
+ self.play(
+ GrowFromCenter(brace),
+ Write(brace_text)
+ )
+ self.dither()
+ self.play(Indicate(x))
+ self.dither()
+ self.play(Indicate(y))
+ self.dither()
+ self.play(Transform(brace_text, alt_brace_text))
+ self.dither()
+ self.play(
+ ShowCreation(new_circle, run_time = 2),
+ Animation(brace_text)
+ )
+ self.play(new_circle.set_stroke, None, 0)
+ self.dither()
+ self.play(*map(FadeOut, [brace, brace_text]))
+ self.dither()
+
+ def perform_implicit_derivative(self):
+ equation = self.circle_equation
+ morty = Mortimer()
+ morty.flip()
+ morty.next_to(ORIGIN, LEFT)
+ morty.to_edge(DOWN, buff = SMALL_BUFF)
+ q_marks = TexMobject("???")
+ q_marks.next_to(morty, UP)
+
+ rect = Rectangle(
+ width = SPACE_WIDTH - SMALL_BUFF,
+ height = SPACE_HEIGHT - SMALL_BUFF,
+ stroke_width = 0,
+ fill_color = BLACK,
+ fill_opacity = 0.8,
+ )
+ rect.to_corner(DOWN+RIGHT, buff = 0)
+
+ derivative = TexMobject("2x\\,dx + 2y\\,dy = 0")
+ dx = VGroup(*derivative[2:4])
+ dy = VGroup(*derivative[7:9])
+ dx.highlight(GREEN)
+ dy.highlight(RED)
+
+
+
+ self.play(
+ FadeIn(rect),
+ FadeIn(morty),
+ equation.next_to, ORIGIN, DOWN, MED_LARGE_BUFF,
+ equation.shift, SPACE_WIDTH*RIGHT/2,
+ )
+ self.play(
+ morty.change_mode, "confused",
+ morty.look_at, equation
+ )
+ self.play(Blink(morty))
+ derivative.next_to(equation, DOWN)
+ derivative.shift(
+ equation[1][-3].get_center()[0]*RIGHT - \
+ derivative[-2].get_center()[0]*RIGHT
+ )
+
+
+ #Differentiate
+ self.play(
+ morty.look_at, derivative[0],
+ *[
+ ReplacementTransform(
+ equation[1][i].copy(),
+ derivative[j],
+ )
+ for i, j in (1, 0), (0, 1)
+ ]
+ )
+ self.play(Write(dx, run_time = 1))
+ self.dither()
+ self.play(*[
+ ReplacementTransform(
+ equation[1][i].copy(),
+ derivative[j],
+ )
+ for i, j in (2, 4), (3, 6), (4, 5)
+ ])
+ self.play(Write(dy, run_time = 1))
+ self.play(Blink(morty))
+ self.play(*[
+ ReplacementTransform(
+ equation[1][i].copy(),
+ derivative[j],
+ )
+ for i, j in (-3, -2), (-2, -1), (-1, -1)
+ ])
+ self.dither()
+
+ #React
+ self.play(morty.change_mode, "erm")
+ self.play(Blink(morty))
+ self.play(Write(q_marks))
+ self.dither()
+ self.play(Indicate(dx), morty.look_at, dx)
+ self.play(Indicate(dy), morty.look_at, dy)
+ self.dither()
+ self.play(
+ morty.change_mode, "shruggie",
+ FadeOut(q_marks)
+ )
+ self.play(Blink(morty))
+ self.play(
+ morty.change_mode, "pondering",
+ morty.look_at, derivative,
+ )
+
+ #Rearrange
+ x, y, eq = np.array(derivative)[[1, 6, 9]]
+ final_form = TexMobject(
+ "\\frac{dy}{dx} = \\frac{-x}{y}"
+ )
+ new_dy = VGroup(*final_form[:2])
+ new_dx = VGroup(*final_form[3:5])
+ new_dy.highlight(dy.get_color())
+ new_dx.highlight(dx.get_color())
+ new_dy.add(final_form[2])
+ new_x = VGroup(*final_form[6:8])
+ new_y = VGroup(*final_form[8:10])
+ new_eq = final_form[5]
+
+ final_form.next_to(derivative, DOWN)
+ final_form.shift((eq.get_center()[0]-new_eq.get_center()[0])*RIGHT)
+
+
+ self.play(*[
+ ReplacementTransform(
+ mover.copy(), target,
+ run_time = 2,
+ path_arc = np.pi/2,
+ )
+ for mover, target in [
+ (dy, new_dy),
+ (dx, new_dx),
+ (eq, new_eq),
+ (x, new_x),
+ (y, new_y)
+ ]
+ ] + [
+ morty.look_at, final_form
+ ])
+ self.dither(2)
+
+ self.morty = morty
+ self.neg_x_over_y = VGroup(*final_form[6:])
+
+ def show_final_slope(self):
+ morty = self.morty
+ dy_dx = self.dy_dx
+ coords = self.example_point_coords_mob
+ x, y = coords[1][1].copy(), coords[1][3].copy()
+
+ frac = self.neg_x_over_y.copy()
+ frac.generate_target()
+ eq = TexMobject("=")
+ eq.add_background_rectangle()
+ eq.next_to(dy_dx, RIGHT)
+ frac.target.next_to(eq, RIGHT)
+ frac.target.shift(SMALL_BUFF*DOWN)
+ rect = BackgroundRectangle(frac.target)
+
+ self.play(
+ FadeIn(rect),
+ MoveToTarget(frac),
+ Write(eq),
+ morty.look_at, rect,
+ run_time = 2,
+ )
+ self.dither()
+ self.play(FocusOn(coords), morty.look_at, coords)
+ self.play(Indicate(coords))
+ scale_factor = 1.4
+ self.play(
+ x.scale, scale_factor,
+ x.highlight, GREEN,
+ x.move_to, frac[1],
+ FadeOut(frac[1]),
+ y.scale, scale_factor,
+ y.highlight, RED,
+ y.move_to, frac[3], DOWN,
+ y.shift, SMALL_BUFF*UP,
+ FadeOut(frac[3]),
+ morty.look_at, frac,
+ run_time = 2
+ )
+ self.dither()
+ self.play(Blink(morty))
+
+class NameImplicitDifferentation(TeacherStudentsScene):
+ def construct(self):
+ title = TextMobject("``Implicit differentiation''")
+
+ equation = TexMobject("x^2", "+", "y^2", "=", "5^2")
+ derivative = TexMobject(
+ "2x\\,dx", "+", "2y\\,dy", "=", "0"
+ )
+ VGroup(*derivative[0][2:]).highlight(GREEN)
+ VGroup(*derivative[2][2:]).highlight(RED)
+ arrow = Arrow(ORIGIN, DOWN, buff = SMALL_BUFF)
+ group = VGroup(title, equation, arrow, derivative)
+ group.arrange_submobjects(DOWN)
+ group.to_edge(UP)
+
+ self.add(title, equation)
+ self.play(
+ self.get_teacher().change_mode, "raise_right_hand",
+ ShowCreation(arrow)
+ )
+ self.change_student_modes(
+ *["confused"]*3,
+ look_at_arg = derivative,
+ added_anims = [ReplacementTransform(equation.copy(), derivative)]
+ )
+ self.dither(2)
+ self.teacher_says(
+ "Don't worry...",
+ added_anims = [
+ group.scale, 0.7,
+ group.to_corner, UP+LEFT,
+ ]
+ )
+ self.change_student_modes(*["happy"]*3)
+ self.dither(3)
+
+class Ladder(VMobject):
+ CONFIG = {
+ "height" : 4,
+ "width" : 1,
+ "n_rungs" : 7,
+ }
+ def generate_points(self):
+ left_line, right_line = [
+ Line(ORIGIN, self.height*UP).shift(self.width*vect/2.0)
+ for vect in LEFT, RIGHT
+ ]
+ rungs = [
+ Line(
+ left_line.point_from_proportion(a),
+ right_line.point_from_proportion(a),
+ )
+ for a in np.linspace(0, 1, 2*self.n_rungs+1)[1:-1:2]
+ ]
+ self.add(left_line, right_line, *rungs)
+ self.center()
+
+class RelatedRatesExample(ThreeDScene):
+ CONFIG = {
+ "start_x" : 3.0,
+ "start_y" : 4.0,
+ "wall_dimensions" : [0.3, 5, 5],
+ "wall_color" : color_gradient([GREY_BROWN, BLACK], 4)[1],
+ "wall_center" : 1.5*LEFT+0.5*UP,
+ }
+ def construct(self):
+ self.introduce_ladder()
+ self.write_related_rates()
+ self.measure_ladder()
+ self.slide_ladder()
+ self.ponder_question()
+ self.write_equation()
+ self.isolate_x_of_t()
+ self.discuss_lhs_as_function()
+ self.let_dt_pass()
+ self.take_derivative_of_rhs()
+ self.take_derivative_of_lhs()
+ self.bring_back_velocity_arrows()
+ self.replace_terms_in_final_form()
+ self.write_final_solution()
+
+ def introduce_ladder(self):
+ ladder = Ladder(height = self.get_ladder_length())
+
+ wall = Prism(
+ dimensions = self.wall_dimensions,
+ fill_color = self.wall_color,
+ fill_opacity = 1,
+ )
+ wall.rotate(np.pi/12, UP)
+ wall.shift(self.wall_center)
+
+ ladder.generate_target()
+ ladder.fallen = ladder.copy()
+ ladder.target.rotate(self.get_ladder_angle(), LEFT)
+ ladder.fallen.rotate(np.pi/2, LEFT)
+ for ladder_copy in ladder.target, ladder.fallen:
+ ladder_copy.rotate(-5*np.pi/12, UP)
+ ladder_copy.next_to(wall, LEFT, 0, DOWN)
+ ladder_copy.shift(0.8*RIGHT) ##BAD!
+
+
+ self.play(
+ ShowCreation(ladder, run_time = 2)
+ )
+ self.dither()
+
+ self.play(
+ DrawBorderThenFill(wall),
+ MoveToTarget(ladder),
+ run_time = 2
+ )
+ self.dither()
+
+ self.ladder = ladder
+
+ def write_related_rates(self):
+ words = TextMobject("Related rates")
+ words.to_corner(UP+RIGHT)
+ self.play(Write(words))
+ self.dither()
+
+ self.related_rates_words = words
+
+ def measure_ladder(self):
+ ladder = self.ladder
+ ladder_brace = self.get_ladder_brace(ladder)
+
+ x_and_y_lines = self.get_x_and_y_lines(ladder)
+ x_line, y_line = x_and_y_lines
+
+ y_label = TexMobject("%dm"%int(self.start_y))
+ y_label.next_to(y_line, LEFT, buff = SMALL_BUFF)
+ y_label.highlight(y_line.get_color())
+
+ x_label = TexMobject("%dm"%int(self.start_x))
+ x_label.next_to(x_line, UP)
+ x_label.highlight(x_line.get_color())
+
+ self.play(Write(ladder_brace))
+ self.dither()
+ self.play(ShowCreation(y_line), Write(y_label))
+ self.dither()
+ self.play(ShowCreation(x_line), Write(x_label))
+ self.dither(2)
+ self.play(*map(FadeOut, [x_label, y_label]))
+
+ self.ladder_brace = ladder_brace
+ self.x_and_y_lines = x_and_y_lines
+ self.numerical_x_and_y_labels = VGroup(x_label, y_label)
+
+ def slide_ladder(self):
+ ladder = self.ladder
+ brace = self.ladder_brace
+ x_and_y_lines = self.x_and_y_lines
+ x_line, y_line = x_and_y_lines
+
+ down_arrow, left_arrow = [
+ Arrow(ORIGIN, vect, color = YELLOW, buff = 0)
+ for vect in DOWN, LEFT
+ ]
+ down_arrow.shift(y_line.get_start()+MED_SMALL_BUFF*RIGHT)
+ left_arrow.shift(x_line.get_start()+SMALL_BUFF*DOWN)
+
+ # speed_label = TexMobject("1 \\text{m}/\\text{s}")
+ speed_label = TexMobject("1 \\frac{\\text{m}}{\\text{s}}")
+ speed_label.next_to(down_arrow, RIGHT, buff = SMALL_BUFF)
+
+ q_marks = TexMobject("???")
+ q_marks.next_to(left_arrow, DOWN, buff = SMALL_BUFF)
+
+
+ added_anims = [
+ UpdateFromFunc(brace, self.update_brace),
+ UpdateFromFunc(x_and_y_lines, self.update_x_and_y_lines),
+ Animation(down_arrow),
+ ]
+ self.play(ShowCreation(down_arrow))
+ self.play(Write(speed_label))
+ self.let_ladder_fall(ladder, *added_anims)
+ self.dither()
+ self.reset_ladder(ladder, *added_anims)
+ self.play(ShowCreation(left_arrow))
+ self.play(Write(q_marks))
+ self.dither()
+ self.let_ladder_fall(ladder, *added_anims)
+ self.dither()
+ self.reset_ladder(ladder, *added_anims)
+ self.dither()
+
+ self.dy_arrow = down_arrow
+ self.dy_label = speed_label
+ self.dx_arrow = left_arrow
+ self.dx_label = q_marks
+
+ def ponder_question(self):
+ randy = Randolph(mode = "pondering")
+ randy.flip()
+ randy.to_corner(DOWN+RIGHT)
+
+ self.play(FadeIn(randy))
+ self.play(Blink(randy))
+ self.dither()
+ self.play(
+ randy.change_mode, "confused",
+ randy.look_at, self.ladder.get_top()
+ )
+ self.play(randy.look_at, self.ladder.get_bottom())
+ self.play(randy.look_at, self.ladder.get_top())
+ self.play(Blink(randy))
+ self.dither()
+ self.play(PiCreatureSays(
+ randy, "Give names"
+ ))
+ self.play(Blink(randy))
+ self.play(*map(FadeOut, [
+ randy, randy.bubble, randy.bubble.content
+ ]))
+
+ def write_equation(self):
+ self.x_and_y_labels = self.get_x_and_y_labels()
+ x_label, y_label = self.x_and_y_labels
+
+ equation = TexMobject(
+ "x(t)", "^2", "+", "y(t)", "^2", "=", "5^2"
+ )
+ equation[0].highlight(GREEN)
+ equation[3].highlight(RED)
+ equation.next_to(self.related_rates_words, DOWN, buff = MED_LARGE_BUFF)
+ equation.to_edge(RIGHT, buff = LARGE_BUFF)
+
+ self.play(Write(y_label))
+ self.dither()
+ self.let_ladder_fall(
+ self.ladder,
+ y_label.shift, self.start_y*DOWN/2,
+ *self.get_added_anims_for_ladder_fall()[:-1],
+ rate_func = lambda t : 0.2*there_and_back(t),
+ run_time = 3
+ )
+ self.play(FocusOn(x_label))
+ self.play(Write(x_label))
+ self.dither(2)
+ self.play(
+ ReplacementTransform(x_label.copy(), equation[0]),
+ ReplacementTransform(y_label.copy(), equation[3]),
+ Write(VGroup(*np.array(equation)[[1, 2, 4, 5, 6]]))
+ )
+ self.dither(2)
+ self.let_ladder_fall(
+ self.ladder,
+ *self.get_added_anims_for_ladder_fall(),
+ rate_func = there_and_back,
+ run_time = 6
+ )
+ self.dither()
+
+ self.equation = equation
+
+ def isolate_x_of_t(self):
+ alt_equation = TexMobject(
+ "x(t)", "=", "\\big(5^2", "-", "y(t)", "^2 \\big)", "^{1/2}",
+ )
+ alt_equation[0].highlight(GREEN)
+ alt_equation[4].highlight(RED)
+ alt_equation.next_to(self.equation, DOWN, buff = MED_LARGE_BUFF)
+ alt_equation.to_edge(RIGHT)
+
+ randy = Randolph()
+ randy.next_to(
+ alt_equation, DOWN,
+ buff = MED_LARGE_BUFF,
+ aligned_edge = LEFT,
+ )
+ randy.look_at(alt_equation)
+
+ find_dx_dt = TexMobject("\\text{Find } \\,", "\\frac{dx}{dt}")
+ find_dx_dt.next_to(randy, RIGHT, aligned_edge = UP)
+ find_dx_dt[1].highlight(GREEN)
+
+ self.play(FadeIn(randy))
+ self.play(
+ randy.change_mode, "raise_right_hand",
+ randy.look_at, alt_equation,
+ *[
+ ReplacementTransform(
+ self.equation[i].copy(),
+ alt_equation[j],
+ path_arc = np.pi/2,
+ run_time = 3,
+ rate_func = squish_rate_func(
+ smooth, j/12.0, (j+6)/12.0
+ )
+ )
+ for i, j in enumerate([0, 6, 3, 4, 5, 1, 2])
+ ]
+ )
+ self.play(Blink(randy))
+ self.dither()
+ self.play(
+ Write(find_dx_dt),
+ randy.change_mode, "pondering",
+ randy.look_at, find_dx_dt,
+ )
+ self.let_ladder_fall(
+ self.ladder, *self.get_added_anims_for_ladder_fall(),
+ run_time = 8,
+ rate_func = there_and_back
+ )
+ self.play(*map(FadeOut, [
+ randy, find_dx_dt, alt_equation
+ ]))
+ self.dither()
+
+ def discuss_lhs_as_function(self):
+ equation = self.equation
+ lhs = VGroup(*equation[:5])
+ brace = Brace(lhs, DOWN)
+ function_of_time = brace.get_text(
+ "Function of time"
+ )
+ constant_words = TextMobject(
+ """that happens to
+ be constant"""
+ )
+ constant_words.highlight(YELLOW)
+ constant_words.next_to(function_of_time, DOWN)
+
+ derivative = TexMobject(
+ "\\frac{d\\left(x(t)^2 + y(t)^2 \\right)}{dt}"
+ )
+ derivative.next_to(equation, DOWN, buff = MED_LARGE_BUFF)
+ derivative.shift( ##Align x terms
+ equation[0][0].get_center()[0]*RIGHT-\
+ derivative[2].get_center()[0]*RIGHT
+ )
+ derivative_interior = lhs.copy()
+ derivative_interior.move_to(VGroup(*derivative[2:13]))
+ derivative_scaffold = VGroup(
+ *list(derivative[:2])+list(derivative[13:])
+ )
+
+ self.play(
+ GrowFromCenter(brace),
+ Write(function_of_time)
+ )
+ self.dither()
+ self.play(Write(constant_words))
+ self.let_ladder_fall(
+ self.ladder, *self.get_added_anims_for_ladder_fall(),
+ run_time = 6,
+ rate_func = lambda t : 0.5*there_and_back(t)
+ )
+ self.dither()
+ self.play(*map(FadeOut, [
+ brace, constant_words, function_of_time
+ ]))
+ self.play(
+ ReplacementTransform(lhs.copy(), derivative_interior),
+ Write(derivative_scaffold),
+ )
+ self.dither()
+
+ self.derivative = VGroup(
+ derivative_scaffold, derivative_interior
+ )
+
+ def let_dt_pass(self):
+ dt_words = TextMobject("After", "$dt$", "seconds...")
+ dt_words.to_corner(UP+LEFT)
+ dt = dt_words[1]
+ dt.highlight(YELLOW)
+ dt_brace = Brace(dt, buff = SMALL_BUFF)
+ dt_brace_text = dt_brace.get_text("Think 0.01", buff = SMALL_BUFF)
+ dt_brace_text.highlight(dt.get_color())
+
+ shadow_ladder = self.ladder.copy()
+ shadow_ladder.fade(0.5)
+
+ x_line, y_line = self.x_and_y_lines
+ y_top = y_line.get_start()
+ x_left = x_line.get_start()
+
+ self.play(Write(dt_words, run_time = 2))
+ self.play(
+ GrowFromCenter(dt_brace),
+ Write(dt_brace_text, run_time = 2)
+ )
+ self.play(*map(FadeOut, [
+ self.dy_arrow, self.dy_label,
+ self.dx_arrow, self.dx_label,
+ ]))
+ self.add(shadow_ladder)
+ self.let_ladder_fall(
+ self.ladder, *self.get_added_anims_for_ladder_fall(),
+ rate_func = lambda t : 0.1*smooth(t),
+ run_time = 1
+ )
+
+ new_y_top = y_line.get_start()
+ new_x_left = x_line.get_start()
+
+ dy_line = Line(y_top, new_y_top)
+ dy_brace = Brace(dy_line, RIGHT, buff = SMALL_BUFF)
+ dy_label = dy_brace.get_text("$dy$", buff = SMALL_BUFF)
+ dy_label.highlight(RED)
+
+ dx_line = Line(x_left, new_x_left)
+ dx_brace = Brace(dx_line, DOWN, buff = SMALL_BUFF)
+ dx_label = dx_brace.get_text("$dx$")
+ dx_label.highlight(GREEN)
+
+ VGroup(dy_line, dx_line).highlight(YELLOW)
+
+ for line, brace, label in (dy_line, dy_brace, dy_label), (dx_line, dx_brace, dx_label):
+ self.play(
+ ShowCreation(line),
+ GrowFromCenter(brace),
+ Write(label),
+ run_time = 1
+ )
+ self.dither()
+ self.play(Indicate(self.derivative[1]))
+ self.dither()
+
+ self.dy_group = VGroup(dy_line, dy_brace, dy_label)
+ self.dx_group = VGroup(dx_line, dx_brace, dx_label)
+ self.shadow_ladder = shadow_ladder
+
+ def take_derivative_of_rhs(self):
+ derivative = self.derivative
+ equals_zero = TexMobject("= 0")
+ equals_zero.next_to(derivative)
+
+ rhs = self.equation[-1]
+
+ self.play(Write(equals_zero))
+ self.dither()
+ self.play(FocusOn(rhs))
+ self.play(Indicate(rhs))
+ self.dither()
+ self.reset_ladder(
+ self.ladder,
+ *self.get_added_anims_for_ladder_fall()+[
+ Animation(self.dy_group),
+ Animation(self.dx_group),
+ ],
+ rate_func = there_and_back,
+ run_time = 3
+ )
+ self.dither()
+
+ self.equals_zero = equals_zero
+
+ def take_derivative_of_lhs(self):
+ derivative_scaffold, equation = self.derivative
+ equals_zero_copy = self.equals_zero.copy()
+
+ lhs_derivative = TexMobject(
+ "2", "x(t)", "\\frac{dx}{dt}", "+",
+ "2", "y(t)", "\\frac{dy}{dt}",
+ )
+ lhs_derivative[1].highlight(GREEN)
+ VGroup(*lhs_derivative[2][:2]).highlight(GREEN)
+ lhs_derivative[5].highlight(RED)
+ VGroup(*lhs_derivative[6][:2]).highlight(RED)
+ lhs_derivative.next_to(
+ derivative_scaffold, DOWN,
+ aligned_edge = RIGHT,
+ buff = MED_LARGE_BUFF
+ )
+ equals_zero_copy.next_to(lhs_derivative, RIGHT)
+
+ pairs = [
+ (0, 1), (1, 0), #x^2 -> 2x
+ (2, 3), (3, 5), (4, 4), #+y^2 -> +2y
+ ]
+ def perform_replacement(index_pairs):
+ self.play(*[
+ ReplacementTransform(
+ equation[i].copy(), lhs_derivative[j],
+ path_arc = np.pi/2,
+ run_time = 2
+ )
+ for i, j in index_pairs
+ ])
+
+ perform_replacement(pairs[:2])
+ self.play(Write(lhs_derivative[2]))
+ self.dither()
+ self.play(Indicate(
+ VGroup(
+ *list(lhs_derivative[:2])+\
+ list(lhs_derivative[2][:2])
+ ),
+ run_time = 2
+ ))
+ self.play(Indicate(VGroup(*lhs_derivative[2][3:])))
+ self.dither(2)
+ perform_replacement(pairs[2:])
+ self.play(Write(lhs_derivative[6]))
+ self.dither()
+
+ self.play(FocusOn(self.equals_zero))
+ self.play(ReplacementTransform(
+ self.equals_zero.copy(),
+ equals_zero_copy
+ ))
+ self.dither(2)
+
+ lhs_derivative.add(equals_zero_copy)
+ self.lhs_derivative = lhs_derivative
+
+ def bring_back_velocity_arrows(self):
+ dx_dy_group = VGroup(self.dx_group, self.dy_group)
+ arrow_group = VGroup(
+ self.dy_arrow, self.dy_label,
+ self.dx_arrow, self.dx_label,
+ )
+ ladder_fall_args = [self.ladder] + self.get_added_anims_for_ladder_fall()
+
+
+ self.reset_ladder(*ladder_fall_args + [
+ FadeOut(dx_dy_group),
+ FadeOut(self.derivative),
+ FadeOut(self.equals_zero),
+ self.lhs_derivative.shift, 2*UP,
+ ])
+ self.remove(self.shadow_ladder)
+ self.play(FadeIn(arrow_group))
+ self.let_ladder_fall(*ladder_fall_args)
+ self.dither()
+ self.reset_ladder(*ladder_fall_args)
+ self.dither()
+
+ def replace_terms_in_final_form(self):
+ x_label, y_label = self.x_and_y_labels
+ num_x_label, num_y_label = self.numerical_x_and_y_labels
+
+ new_lhs_derivative = TexMobject(
+ "2", "(%d)"%int(self.start_x), "\\frac{dx}{dt}", "+",
+ "2", "(%d)"%int(self.start_y), "(-1)",
+ "= 0"
+ )
+ new_lhs_derivative[1].highlight(GREEN)
+ VGroup(*new_lhs_derivative[2][:2]).highlight(GREEN)
+ new_lhs_derivative[5].highlight(RED)
+ new_lhs_derivative.next_to(
+ self.lhs_derivative, DOWN,
+ buff = MED_LARGE_BUFF,
+ aligned_edge = RIGHT
+ )
+ def fill_in_equation_part(*indices):
+ self.play(*[
+ ReplacementTransform(
+ self.lhs_derivative[i].copy(),
+ new_lhs_derivative[i],
+ run_time = 2
+ )
+ for i in indices
+ ])
+
+ self.play(FadeOut(y_label), FadeIn(num_y_label))
+ fill_in_equation_part(3, 4, 5)
+ self.play(FadeOut(x_label), FadeIn(num_x_label))
+ for indices in [(0, 1), (6,), (2, 7)]:
+ fill_in_equation_part(*indices)
+ self.dither()
+ self.dither()
+
+ self.new_lhs_derivative = new_lhs_derivative
+
+ def write_final_solution(self):
+ solution = TexMobject(
+ "\\frac{dx}{dt} = \\frac{4}{3}"
+ )
+ for i in 0, 1, -1:
+ solution[i].highlight(GREEN)
+ solution[-3].highlight(RED)
+ solution.next_to(
+ self.new_lhs_derivative, DOWN,
+ buff = MED_LARGE_BUFF,
+ aligned_edge = RIGHT
+ )
+
+ box = Rectangle(color = YELLOW)
+ box.replace(solution)
+ box.scale_in_place(1.5)
+
+ self.play(Write(solution))
+ self.dither()
+ self.play(ShowCreation(box))
+ self.dither()
+
+ #########
+
+ def get_added_anims_for_ladder_fall(self):
+ return [
+ UpdateFromFunc(self.ladder_brace, self.update_brace),
+ UpdateFromFunc(self.x_and_y_lines, self.update_x_and_y_lines),
+ UpdateFromFunc(self.x_and_y_labels, self.update_x_and_y_labels),
+ ]
+
+ def let_ladder_fall(self, ladder, *added_anims, **kwargs):
+ kwargs["run_time"] = kwargs.get("run_time", self.start_y)
+ kwargs["rate_func"] = kwargs.get("rate_func", None)
+ self.play(
+ Transform(ladder, ladder.fallen),
+ *added_anims,
+ **kwargs
+ )
+
+ def reset_ladder(self, ladder, *added_anims, **kwargs):
+ kwargs["run_time"] = kwargs.get("run_time", 2)
+ self.play(
+ Transform(ladder, ladder.target),
+ *added_anims,
+ **kwargs
+ )
+
+ def update_brace(self, brace):
+ Transform(
+ brace, self.get_ladder_brace(self.ladder)
+ ).update(1)
+ return brace
+
+ def update_x_and_y_lines(self, x_and_y_lines):
+ Transform(
+ x_and_y_lines,
+ self.get_x_and_y_lines(self.ladder)
+ ).update(1)
+ return x_and_y_lines
+
+ def update_x_and_y_labels(self, x_and_y_labels):
+ Transform(
+ x_and_y_labels,
+ self.get_x_and_y_labels()
+ ).update(1)
+ return x_and_y_labels
+
+ def get_ladder_brace(self, ladder):
+ vect = rotate_vector(LEFT, -self.get_ladder_angle())
+ brace = Brace(ladder, vect)
+ length_string = "%dm"%int(self.get_ladder_length())
+ length_label = brace.get_text(
+ length_string, use_next_to = False
+ )
+ brace.add(length_label)
+ brace.length_label = length_label
+ return brace
+
+ def get_x_and_y_labels(self):
+ x_line, y_line = self.x_and_y_lines
+
+ x_label = TexMobject("x(t)")
+ x_label.highlight(x_line.get_color())
+ x_label.next_to(x_line, DOWN, buff = SMALL_BUFF)
+
+ y_label = TexMobject("y(t)")
+ y_label.highlight(y_line.get_color())
+ y_label.next_to(y_line, LEFT, buff = SMALL_BUFF)
+
+ return VGroup(x_label, y_label)
+
+ def get_x_and_y_lines(self, ladder):
+ bottom_point, top_point = np.array(ladder[1].get_start_and_end())
+ interim_point = top_point[0]*RIGHT + bottom_point[1]*UP
+ interim_point += SMALL_BUFF*DOWN
+ y_line = Line(top_point, interim_point)
+ y_line.highlight(RED)
+ x_line = Line(bottom_point, interim_point)
+ x_line.highlight(GREEN)
+
+ return VGroup(x_line, y_line)
+
+ def get_ladder_angle(self):
+ if hasattr(self, "ladder"):
+ c1 = self.ladder.get_corner(UP+RIGHT)
+ c2 = self.ladder.get_corner(DOWN+LEFT)
+ vect = c1-c2
+ return np.pi/2 - angle_of_vector(vect)
+ else:
+ return np.arctan(self.start_x/self.start_y)
+
+ def get_ladder_length(self):
+ return np.linalg.norm([self.start_x, self.start_y])
+
+class LightweightLadderScene(RelatedRatesExample):
+ CONFIG = {
+ "skip_animations" : True
+ }
+ def construct(self):
+ self.introduce_ladder()
+ self.measure_ladder()
+ self.add(self.numerical_x_and_y_labels)
+
+class LightweightCircleExample(SlopeOfCircleExample):
+ CONFIG = {
+ "skip_animations" : True,
+ "plane_kwargs" : {
+ "x_radius" : 5,
+ "y_radius" : 5,
+ "space_unit_to_x_unit" : SPACE_UNIT_TO_PLANE_UNIT,
+ "space_unit_to_y_unit" : SPACE_UNIT_TO_PLANE_UNIT,
+ },
+ }
+ def construct(self):
+ self.setup_plane()
+ self.introduce_circle()
+ self.talk_through_pythagorean_theorem()
+ self.draw_example_slope()
+
+ self.remove(self.circle_equation)
+ self.remove(self.slope_word)
+ self.example_point_coords_mob.scale(
+ 1.5, about_point = self.example_point_coords_mob.get_corner(UP+RIGHT)
+ )
+ self.plane.axis_labels[0].shift(3*LEFT)
+
+class CompareLadderAndCircle(PiCreatureScene, ThreeDScene):
+ def construct(self):
+ self.introduce_both_scenes()
+ self.show_derivatives()
+ self.comment_on_ladder_derivative()
+ self.comment_on_circle_derivative()
+
+ def introduce_both_scenes(self):
+ ladder_scene = LightweightLadderScene()
+ ladder_mobs = VGroup(*ladder_scene.get_top_level_mobjects())
+ circle_scene = LightweightCircleExample()
+ circle_mobs = VGroup(*circle_scene.get_top_level_mobjects())
+ for mobs, vect in (ladder_mobs, LEFT), (circle_mobs, RIGHT):
+ mobs.scale_to_fit_height(SPACE_HEIGHT-MED_LARGE_BUFF)
+ mobs.next_to(
+ self.pi_creature.get_corner(UP+vect), UP,
+ buff = SMALL_BUFF,
+ aligned_edge = -vect
+ )
+
+ ladder_mobs.save_state()
+ ladder_mobs.fade(1)
+ ladder_mobs.rotate_in_place(np.pi/3, UP)
+ self.play(
+ self.pi_creature.change_mode, "raise_right_hand",
+ self.pi_creature.look_at, ladder_mobs,
+ ApplyMethod(ladder_mobs.restore, run_time = 2)
+ )
+ self.play(
+ self.pi_creature.change_mode, "raise_left_hand",
+ self.pi_creature.look_at, circle_mobs,
+ Write(circle_mobs, run_time = 2)
+ )
+ self.dither(2)
+ self.play(
+ circle_mobs.to_edge, RIGHT,
+ ladder_mobs.to_edge, LEFT,
+ )
+
+ def show_derivatives(self):
+ equation = TexMobject(
+ "x", "^2", "+", "y", "^2", "= 5^2"
+ )
+ derivative = TexMobject(
+ "2", "x", "dx", "+", "2", "y", "dy", "=0"
+ )
+ self.color_equations(equation, derivative)
+ equation.to_edge(UP)
+ equation.shift(MED_LARGE_BUFF*LEFT)
+ derivative.next_to(equation, DOWN, buff = MED_LARGE_BUFF)
+
+ self.play(
+ Write(equation),
+ self.pi_creature.change_mode, "plain",
+ self.pi_creature.look_at, equation
+ )
+ self.dither()
+ self.play(*[
+ ReplacementTransform(
+ equation[i].copy(), derivative[j],
+ path_arc = np.pi/2
+ )
+ for i, j in enumerate([1, 0, 3, 5, 4, 7])
+ ]+[
+ Write(derivative[j])
+ for j in 2, 6
+ ])
+ self.play(
+ self.pi_creature.change_mode, "pondering",
+ self.pi_creature.look_at, derivative
+ )
+ self.dither()
+
+ self.equation = equation
+ self.derivative = derivative
+
+ def comment_on_ladder_derivative(self):
+ equation = self.equation
+ derivative = self.derivative
+
+ time_equation = TexMobject(
+ "x(t)", "^2", "+", "y(t)", "^2", "= 5^2"
+ )
+ time_derivative = TexMobject(
+ "2", "x(t)", "\\frac{dx}{dt}", "+",
+ "2", "y(t)", "\\frac{dy}{dt}", "=0"
+ )
+ self.color_equations(time_equation, time_derivative)
+ time_equation.move_to(equation)
+ time_derivative.move_to(derivative, UP)
+
+ brace = Brace(time_derivative)
+ brace_text = brace.get_text("A rate")
+
+ equation.save_state()
+ derivative.save_state()
+
+ self.play(Transform(equation, time_equation))
+ self.dither()
+ self.play(Transform(derivative, time_derivative))
+ self.dither()
+ self.play(GrowFromCenter(brace))
+ self.play(Write(brace_text))
+ self.change_mode("hooray")
+ self.dither(2)
+ self.play(
+ equation.restore,
+ derivative.restore,
+ FadeOut(brace),
+ FadeOut(brace_text),
+ self.pi_creature.change_mode, "confused"
+ )
+ self.dither()
+
+ def comment_on_circle_derivative(self):
+ derivative = self.derivative
+ dx = derivative.get_part_by_tex("dx")
+ dy = derivative.get_part_by_tex("dy")
+
+ for mob in dx, dy:
+ brace = Brace(mob)
+ brace.next_to(mob[0], DOWN, buff = SMALL_BUFF, aligned_edge = LEFT)
+ text = brace.get_text("No $dt$", buff = SMALL_BUFF)
+ text.highlight(YELLOW)
+
+ self.play(
+ GrowFromCenter(brace),
+ Write(text)
+ )
+ self.dither()
+
+ self.play(
+ self.pi_creature.change_mode, "pondering",
+ self.pi_creature.look, DOWN+LEFT
+ )
+ self.dither(2)
+
+ #######
+
+ def create_pi_creature(self):
+ self.pi_creature = Mortimer().to_edge(DOWN)
+ return self.pi_creature
+
+ def color_equations(self, equation, derivative):
+ for mob in equation[0], derivative[1]:
+ mob.highlight(GREEN)
+ for mob in equation[3], derivative[5]:
+ mob.highlight(RED)
+
+class TwoVariableFunctionAndDerivative(SlopeOfCircleExample):
+ CONFIG = {
+ "zoomed_canvas_corner" : DOWN+RIGHT,
+ "zoomed_canvas_space_shape" : (3, 4),
+ }
+ def construct(self):
+ self.setup_plane()
+ self.write_equation()
+ self.show_example_point()
+ self.shift_example_point((4, 4))
+ self.shift_example_point((3, 3))
+ self.shift_example_point(self.example_point)
+ self.take_derivative_symbolically()
+ self.show_dx_dy_step()
+ self.plug_in_example_values()
+ self.ask_about_equalling_zero()
+ self.show_tangent_step()
+ self.point_out_equalling_zero()
+ self.show_tangent_line()
+
+ def write_equation(self):
+ equation = TexMobject("x", "^2", "+", "y", "^2")
+ equation.add_background_rectangle()
+
+ brace = Brace(equation, UP, buff = SMALL_BUFF)
+ s_expression = self.get_s_expression("x", "y")
+ s_rect, s_of_xy = s_expression
+ s, xy = s_of_xy
+ s_expression.next_to(brace, UP, buff = SMALL_BUFF)
+
+ group = VGroup(equation, s_expression, brace)
+ group.shift(2*SPACE_WIDTH*LEFT/3)
+ group.to_edge(UP, buff = MED_SMALL_BUFF)
+
+ s.save_state()
+ s.next_to(brace, UP)
+
+
+ self.play(Write(equation))
+ self.play(GrowFromCenter(brace))
+ self.play(Write(s))
+ self.dither()
+ self.play(
+ FadeIn(s_rect),
+ s.restore,
+ GrowFromCenter(xy)
+ )
+ self.dither()
+
+ self.equation = equation
+ self.s_expression = s_expression
+
+ def show_example_point(self):
+ point = self.plane.num_pair_to_point(self.example_point)
+ dot = Dot(point, color = self.example_color)
+ new_s_expression = self.get_s_expression(*self.example_point)
+ new_s_expression.next_to(dot, UP+RIGHT, buff = 0)
+ new_s_expression.highlight(self.example_color)
+ equals_25 = TexMobject("=%d"%int(np.linalg.norm(self.example_point)**2))
+ equals_25.highlight(YELLOW)
+ equals_25.next_to(new_s_expression, RIGHT, align_using_submobjects = True)
+ equals_25.add_background_rectangle()
+
+ circle = Circle(
+ radius = self.circle_radius*self.plane.space_unit_to_x_unit,
+ color = self.circle_color,
+ )
+
+ self.play(
+ ReplacementTransform(
+ self.s_expression.copy(),
+ new_s_expression
+ ),
+ ShowCreation(dot)
+ )
+ self.play(ShowCreation(circle), Animation(dot))
+ self.play(Write(equals_25))
+ self.dither()
+
+ self.example_point_dot = dot
+ self.example_point_label = VGroup(
+ new_s_expression, equals_25
+ )
+
+ def shift_example_point(self, coords):
+ point = self.plane.num_pair_to_point(coords)
+ s_expression = self.get_s_expression(*coords)
+ s_expression.next_to(point, UP+RIGHT, buff = SMALL_BUFF)
+ s_expression.highlight(self.example_color)
+ result = coords[0]**2 + coords[1]**2
+ rhs = TexMobject("=%d"%int(result))
+ rhs.add_background_rectangle()
+ rhs.highlight(YELLOW)
+ rhs.next_to(s_expression, RIGHT, align_using_submobjects = True)
+ point_label = VGroup(s_expression, rhs)
+
+ self.play(
+ self.example_point_dot.move_to, point,
+ Transform(self.example_point_label, point_label)
+ )
+ self.dither(2)
+
+ def take_derivative_symbolically(self):
+ equation = self.equation
+ derivative = TexMobject(
+ "dS =", "2", "x", "\\,dx", "+", "2", "y", "\\,dy",
+ )
+ derivative[2].highlight(GREEN)
+ derivative[6].highlight(RED)
+ derivative.next_to(equation, DOWN, buff = MED_LARGE_BUFF)
+ derivative.add_background_rectangle()
+ derivative.to_edge(LEFT)
+
+ self.play(*[
+ FadeIn(derivative[0])
+ ]+[
+ ReplacementTransform(
+ self.s_expression[1][0].copy(),
+ derivative[1][0],
+ )
+ ]+[
+ Write(derivative[1][j])
+ for j in 3, 7
+ ])
+ self.play(*[
+ ReplacementTransform(
+ equation[1][i].copy(), derivative[1][j],
+ path_arc = np.pi/2,
+ run_time = 2,
+ rate_func = squish_rate_func(smooth, (j-1)/12., (j+6)/12.)
+ )
+ for i, j in enumerate([2, 1, 4, 6, 5])
+ ])
+ self.dither(2)
+
+ self.derivative = derivative
+
+ def show_dx_dy_step(self):
+ dot = self.example_point_dot
+ s_label = self.example_point_label
+ rhs = s_label[-1]
+ s_label.remove(rhs)
+
+ point = dot.get_center()
+ vect = 2*LEFT + DOWN
+ new_point = point + vect*0.6/self.zoom_factor
+ interim_point = new_point[0]*RIGHT + point[1]*UP
+
+ dx_line = Line(point, interim_point, color = GREEN)
+ dy_line = Line(interim_point, new_point, color = RED)
+ for line, tex, vect in (dx_line, "dx", UP), (dy_line, "dy", LEFT):
+ label = TexMobject(tex)
+ label.highlight(line.get_color())
+ label.next_to(line, vect, buff = SMALL_BUFF)
+ label.add_background_rectangle()
+ label.scale(
+ 1./self.zoom_factor,
+ about_point = line.get_center()
+ )
+ line.label = label
+
+ self.activate_zooming()
+ lil_rect = self.little_rectangle
+ lil_rect.move_to(dot)
+ lil_rect.shift(0.05*lil_rect.get_width()*LEFT)
+ lil_rect.shift(0.2*lil_rect.get_height()*DOWN)
+ lil_rect.save_state()
+ lil_rect.scale_to_fit_height(SPACE_HEIGHT - MED_LARGE_BUFF)
+ lil_rect.move_to(s_label, UP)
+ lil_rect.shift(MED_SMALL_BUFF*UP)
+ self.dither()
+ self.play(
+ FadeOut(rhs),
+ dot.scale, 1./self.zoom_factor, point,
+ s_label.scale, 1./self.zoom_factor, point,
+ lil_rect.restore,
+ run_time = 2
+ )
+ self.dither()
+ for line in dx_line, dy_line:
+ self.play(ShowCreation(line))
+ self.play(Write(line.label, run_time = 1))
+ self.dither()
+
+ new_dot = Dot(color = dot.get_color())
+ new_s_label = self.get_s_expression(
+ "%d + dx"%int(self.example_point[0]),
+ "%d + dy"%int(self.example_point[1]),
+ )
+ new_dot.scale_to_fit_height(dot.get_height())
+ new_dot.move_to(new_point)
+ new_s_label.scale_to_fit_height(s_label.get_height())
+ new_s_label.scale(0.8)
+ new_s_label.next_to(
+ new_dot, DOWN,
+ buff = SMALL_BUFF/self.zoom_factor,
+ aligned_edge = LEFT
+ )
+ new_s_label.shift(MED_LARGE_BUFF*LEFT/self.zoom_factor)
+ new_s_label.highlight(self.example_color)
+ VGroup(*new_s_label[1][1][3:5]).highlight(GREEN)
+ VGroup(*new_s_label[1][1][-3:-1]).highlight(RED)
+
+ self.play(ShowCreation(new_dot))
+ self.play(Write(new_s_label))
+ self.dither()
+
+ ds = self.derivative[1][0]
+ self.play(FocusOn(ds))
+ self.play(Indicate(ds))
+ self.dither()
+
+ self.tiny_step_group = VGroup(
+ dx_line, dx_line.label,
+ dy_line, dy_line.label,
+ s_label, new_s_label, new_dot
+ )
+
+ def plug_in_example_values(self):
+ deriv_example = TexMobject(
+ "dS =", "2", "(3)", "\\,(-0.02)", "+", "2", "(4)", "\\,(-0.01)",
+ )
+
+ deriv_example[2].highlight(GREEN)
+ deriv_example[6].highlight(RED)
+ deriv_example.add_background_rectangle()
+ deriv_example.scale(0.8)
+ deriv_example.next_to(ORIGIN, UP, buff = SMALL_BUFF)
+ deriv_example.to_edge(LEFT, buff = MED_SMALL_BUFF)
+
+ def add_example_parts(*indices):
+ self.play(*[
+ ReplacementTransform(
+ self.derivative[1][i].copy(),
+ deriv_example[1][i],
+ run_time = 2
+ )
+ for i in indices
+ ])
+
+ self.play(FadeIn(deriv_example[0]))
+ add_example_parts(0)
+ self.dither()
+ add_example_parts(1, 2, 4, 5, 6)
+ self.dither(2)
+ add_example_parts(3)
+ self.dither()
+ add_example_parts(7)
+ self.dither()
+
+ #React
+ randy = Randolph()
+ randy.next_to(ORIGIN, LEFT)
+ randy.to_edge(DOWN)
+
+ self.play(FadeIn(randy))
+ self.play(
+ randy.change_mode, "pondering",
+ randy.look_at, deriv_example.get_left()
+ )
+ self.play(Blink(randy))
+ self.play(randy.look_at, deriv_example.get_right())
+ self.dither()
+ self.play(
+ Indicate(self.equation),
+ randy.look_at, self.equation
+ )
+ self.play(Blink(randy))
+ self.play(
+ randy.change_mode, "thinking",
+ randy.look_at, self.big_rectangle
+ )
+ self.dither(2)
+ self.play(PiCreatureSays(
+ randy, "Approximately",
+ target_mode = "sassy"
+ ))
+ self.dither()
+ self.play(RemovePiCreatureBubble(randy))
+ self.play(randy.look_at, deriv_example)
+ self.play(FadeOut(deriv_example))
+ self.dither()
+
+ self.randy = randy
+
+ def ask_about_equalling_zero(self):
+ dot = self.example_point_dot
+ randy = self.randy
+
+ equals_zero = TexMobject("=0")
+ equals_zero.highlight(YELLOW)
+ equals_zero.add_background_rectangle()
+ equals_zero.next_to(self.derivative, RIGHT)
+
+ self.play(
+ Write(equals_zero),
+ randy.change_mode, "confused",
+ randy.look_at, equals_zero
+ )
+ self.dither()
+ self.play(Blink(randy))
+ self.play(
+ randy.change_mode, "plain",
+ randy.look_at, self.big_rectangle,
+ )
+ self.play(
+ FadeOut(self.tiny_step_group),
+ self.little_rectangle.move_to, dot,
+ )
+ self.dither()
+
+ self.equals_zero = equals_zero
+
+ def show_tangent_step(self):
+ dot = self.example_point_dot
+ randy = self.randy
+
+ point = dot.get_center()
+ step_vect = rotate_vector(point, np.pi/2)/np.linalg.norm(point)
+ new_point = point + step_vect/self.zoom_factor
+ interim_point = point[0]*RIGHT + new_point[1]*UP
+ new_dot = dot.copy().move_to(new_point)
+
+ step_line = Line(point, new_point, color = WHITE)
+ dy_line = Line(point, interim_point, color = RED)
+ dx_line = Line(interim_point, new_point, color = GREEN)
+
+ s_label = TexMobject("S = 25")
+ s_label.highlight(self.example_color)
+ s_label.next_to(
+ point, DOWN,
+ buff = MED_LARGE_BUFF,
+ aligned_edge = RIGHT
+ )
+ s_label.scale(1./self.zoom_factor, about_point = point)
+ arrow1, arrow2 = [
+ Arrow(
+ s_label.get_top(), mob,
+ preserve_tip_size_when_scaling = False,
+ color = self.example_color,
+ buff = SMALL_BUFF/self.zoom_factor,
+ tip_length = 0.15/self.zoom_factor
+ )
+ for mob in dot, new_dot
+ ]
+
+ for line, tex, vect in (dy_line, "dy", RIGHT), (dx_line, "dx", UP):
+ label = TexMobject(tex)
+ label.highlight(line.get_color())
+ label.next_to(line, vect)
+ label.scale(
+ 1./self.zoom_factor,
+ about_point = line.get_center()
+ )
+ line.label = label
+
+ self.play(ShowCreation(line))
+ self.play(Write(label))
+ self.play(ShowCreation(new_dot))
+ self.play(
+ randy.change_mode, "pondering",
+ randy.look_at, self.big_rectangle
+ )
+ self.play(Blink(randy))
+ self.dither()
+
+ self.play(Write(s_label))
+ self.play(ShowCreation(arrow1))
+ self.dither()
+ self.play(ReplacementTransform(arrow1.copy(), arrow2))
+ self.dither(2)
+
+ def point_out_equalling_zero(self):
+ derivative = self.derivative
+ equals_zero = self.equals_zero
+ randy = self.randy
+
+ self.play(
+ FocusOn(equals_zero),
+ self.randy.look_at, equals_zero
+ )
+ self.play(Indicate(equals_zero, color = RED))
+ self.play(Blink(randy))
+ self.play(randy.change_mode, "happy")
+ self.play(randy.look_at, self.big_rectangle)
+ self.dither(2)
+
+ def show_tangent_line(self):
+ randy = self.randy
+ point = self.example_point_dot.get_center()
+ line = Line(ORIGIN, 5*RIGHT)
+ line.rotate(angle_of_vector(point)+np.pi/2)
+ line.move_to(point)
+
+ self.play(PiCreatureSays(
+ randy, "Approximately...",
+ ))
+ self.play(Blink(randy))
+ self.play(RemovePiCreatureBubble(randy))
+ self.play(
+ GrowFromCenter(line),
+ randy.look_at, line
+ )
+ self.dither(2)
+ self.play(
+ self.little_rectangle.scale_in_place, self.zoom_factor/2,
+ run_time = 4,
+ rate_func = there_and_back
+ )
+ self.dither(2)
+
+ ############
+
+ def get_s_expression(self, x, y):
+ result = TexMobject("S", "(%s, %s)"%(str(x), str(y)))
+ result.add_background_rectangle()
+ return result
+
+class TryOtherExamples(TeacherStudentsScene):
+ def construct(self):
+ formula = TexMobject("\\sin(x)y^2 = x")
+ formula.next_to(
+ self.get_teacher().get_corner(UP+LEFT), UP,
+ buff = MED_LARGE_BUFF,
+ aligned_edge = RIGHT
+ )
+
+
+ self.teacher_says(
+ """Nothing special
+ about $x^2 + y^2 = 25$"""
+ )
+ self.dither()
+ self.play(RemovePiCreatureBubble(
+ self.get_teacher(),
+ target_mode = "raise_right_hand"
+ ))
+ self.play(Write(formula, run_time = 1))
+ self.change_student_modes(*["pondering"]*3)
+ self.dither(2)
+ self.play(formula.to_corner, UP+LEFT)
+ self.dither()
+
+class AlternateExample(ZoomedScene):
+ CONFIG = {
+ "example_color" : MAROON_B,
+ "zoom_factor" : 10,
+ "zoomed_canvas_corner" : DOWN+RIGHT,
+ "zoomed_canvas_space_shape" : (3, 4),
+ }
+ def construct(self):
+ self.add_plane()
+ self.draw_graph()
+ self.emphasize_meaning_of_points()
+ self.zoom_in()
+ self.show_tiny_step()
+ self.ask_about_derivatives()
+ self.differentiate_lhs()
+ self.differentiate_rhs()
+ self.put_step_on_curve()
+ self.emphasize_equality()
+ self.manipulate_to_find_dy_dx()
+
+ def add_plane(self):
+ formula = TexMobject("\\sin(x)y^2 = x")
+ formula.to_corner(UP+LEFT)
+ formula.add_background_rectangle()
+
+ plane = NumberPlane(
+ space_unit_to_x_unit = 0.75,
+ x_radius = 2*SPACE_WIDTH,
+ )
+ plane.fade()
+ plane.add_coordinates()
+
+ self.add(formula)
+ self.play(Write(plane, run_time = 2), Animation(formula))
+ self.dither()
+
+ self.plane = plane
+ self.formula = formula
+ self.lhs = VGroup(*formula[1][:8])
+ self.rhs = VGroup(formula[1][-1])
+
+ def draw_graph(self):
+ graphs = VGroup(*[
+ FunctionGraph(
+ lambda x : u*np.sqrt(x/np.sin(x)),
+ num_steps = 200,
+ x_min = x_min+0.1,
+ x_max = x_max-0.1,
+ )
+ for u in [-1, 1]
+ for x_min, x_max in [
+ (-4*np.pi, -2*np.pi),
+ (-np.pi, np.pi),
+ (2*np.pi, 4*np.pi),
+ ]
+ ])
+ graphs.stretch(self.plane.space_unit_to_x_unit, dim = 0)
+
+ self.play(
+ ShowCreation(
+ graphs,
+ run_time = 3,
+ submobject_mode = "all_at_once"
+ ),
+ Animation(self.formula)
+ )
+ self.dither()
+
+ self.graphs = graphs
+
+ def emphasize_meaning_of_points(self):
+ graph = self.graphs[4]
+ dot = Dot(color = self.example_color)
+ label = TexMobject("(x, y)")
+ label.add_background_rectangle()
+ label.highlight(self.example_color)
+
+ def update_dot(dot, alpha):
+ prop = interpolate(0.9, 0.1, alpha)
+ point = graph.point_from_proportion(prop)
+ dot.move_to(point)
+ return dot
+
+ def update_label(label):
+ point = dot.get_center()
+ vect = np.array(point)/np.linalg.norm(point)
+ vect[0] *= 2
+ vect[1] *= -1
+ label.move_to(
+ point + vect*0.4*label.get_width()
+ )
+
+ update_dot(dot, 0)
+ update_label(label)
+
+ self.play(
+ ShowCreation(dot),
+ Write(label),
+ run_time = 1
+ )
+ self.play(
+ UpdateFromAlphaFunc(dot, update_dot),
+ UpdateFromFunc(label, update_label),
+ run_time = 3,
+ )
+ self.dither()
+ self.play(*[
+ ApplyMethod(
+ label[1][i].copy().move_to, self.formula[1][j],
+ run_time = 3,
+ rate_func = squish_rate_func(smooth, count/6., count/6.+2./3)
+ )
+ for count, (i, j) in enumerate([(1, 4), (1, 9), (3, 6)])
+ ])
+ movers = self.get_mobjects_from_last_animation()
+ self.dither()
+ self.play(
+ UpdateFromAlphaFunc(dot, update_dot),
+ UpdateFromFunc(label, update_label),
+ run_time = 3,
+ rate_func = lambda t : 1-smooth(t)
+ )
+ self.dither()
+ self.play(*[
+ ApplyMethod(mover.set_fill, None, 0, remover = True)
+ for mover in movers
+ ])
+
+ self.dot = dot
+ self.label = label
+
+ def zoom_in(self):
+ dot = self.dot
+ label = self.label
+
+ self.activate_zooming()
+ self.little_rectangle.scale(self.zoom_factor)
+ self.little_rectangle.move_to(dot)
+ self.dither()
+ for mob in VGroup(dot, label), self.little_rectangle:
+ self.play(
+ ApplyMethod(
+ mob.scale, 1./self.zoom_factor,
+ method_kwargs = {"about_point" : dot.get_center()},
+ run_time = 1,
+ )
+ )
+ self.dither()
+
+ def show_tiny_step(self):
+ dot = self.dot
+ label = self.label
+ point = dot.get_center()
+ step_vect = 1.2*(UP+LEFT)/float(self.zoom_factor)
+ new_point = point + step_vect
+ interim_point = new_point[0]*RIGHT + point[1]*UP
+
+ dx_line = Line(point, interim_point, color = GREEN)
+ dy_line = Line(interim_point, new_point, color = RED)
+ for line, tex, vect in (dx_line, "dx", DOWN), (dy_line, "dy", LEFT):
+ label = TexMobject(tex)
+ label.next_to(line, vect, buff = SMALL_BUFF)
+ label.highlight(line.get_color())
+ label.scale(1./self.zoom_factor, about_point = line.get_center())
+ label.add_background_rectangle()
+ line.label = label
+
+ arrow = Arrow(
+ point, new_point, buff = 0,
+ tip_length = 0.15/self.zoom_factor,
+ color = WHITE
+ )
+
+ self.play(ShowCreation(arrow))
+ for line in dx_line, dy_line:
+ self.play(ShowCreation(line), Animation(arrow))
+ self.play(Write(line.label, run_time = 1))
+ self.dither()
+
+ self.step_group = VGroup(
+ arrow, dx_line, dx_line.label, dy_line, dy_line.label
+ )
+
+ def ask_about_derivatives(self):
+ formula = self.formula
+ lhs, rhs = self.lhs, self.rhs
+
+ word = TextMobject("Change?")
+ word.add_background_rectangle()
+ word.next_to(
+ Line(lhs.get_center(), rhs.get_center()),
+ DOWN, buff = 1.5*LARGE_BUFF
+ )
+
+ arrows = VGroup(*[
+ Arrow(word, part)
+ for part in lhs, rhs
+ ])
+
+ self.play(FocusOn(formula))
+ self.play(
+ Write(word),
+ ShowCreation(arrows)
+ )
+ self.dither()
+ self.play(*map(FadeOut, [word, arrows]))
+
+ def differentiate_lhs(self):
+ formula = self.formula
+ lhs = self.lhs
+ brace = Brace(lhs, DOWN, buff = SMALL_BUFF)
+ sine_x = VGroup(*lhs[:6])
+ sine_rect = BackgroundRectangle(sine_x)
+ y_squared = VGroup(*lhs[6:])
+
+ mnemonic = TextMobject(
+ "``",
+ "Left", " d-Right", " + ",
+ "Right", " d-Left"
+ "''",
+ arg_separator = ""
+ )
+ mnemonic.highlight_by_tex("d-Right", RED)
+ mnemonic.highlight_by_tex("d-Left", GREEN)
+ mnemonic.add_background_rectangle()
+ mnemonic.scale_to_fit_width(SPACE_WIDTH-2*MED_LARGE_BUFF)
+ mnemonic.next_to(ORIGIN, UP)
+ mnemonic.to_edge(LEFT)
+
+ derivative = TexMobject(
+ "\\sin(x)", "(2y\\,dy)", "+",
+ "y^2", "(\\cos(x)\\,dx)",
+ )
+ derivative.highlight_by_tex("dx", GREEN)
+ derivative.highlight_by_tex("dy", RED)
+ derivative.scale_to_fit_width(SPACE_WIDTH - 2*MED_LARGE_BUFF)
+ derivative.next_to(
+ brace, DOWN,
+ buff = MED_LARGE_BUFF,
+ aligned_edge = LEFT
+ )
+ derivative_rects = [
+ BackgroundRectangle(VGroup(*subset))
+ for subset in derivative[:2], derivative[2:]
+ ]
+ derivative_rects[1].stretch(1.05, dim = 0)
+
+ self.play(GrowFromCenter(brace))
+ self.play(Write(mnemonic))
+ self.dither()
+ pairs = [
+ (sine_rect, derivative_rects[0]),
+ (sine_x, derivative[0]),
+ (y_squared, derivative[1]),
+ (sine_rect, derivative_rects[1]),
+ (y_squared, derivative[2]),
+ (y_squared, derivative[3]),
+ (sine_x, derivative[4]),
+ ]
+ for pairs_subset in pairs[:3], pairs[3:]:
+ self.play(*[
+ ReplacementTransform(m1.copy(), m2, path_arc = np.pi/2)
+ for m1, m2 in pairs_subset
+ ])
+ self.dither()
+ self.play(Indicate(pairs_subset[-1][1]))
+ self.dither()
+ self.dither()
+ self.play(FadeOut(mnemonic))
+
+ self.lhs_derivative = VGroup(*derivative_rects+[derivative])
+ self.lhs_brace = brace
+
+ def differentiate_rhs(self):
+ lhs_derivative = self.lhs_derivative
+ lhs_brace = self.lhs_brace
+ rhs = self.rhs
+
+ equals, dx = equals_dx = TexMobject("=", "dx")
+ equals_dx.scale(0.9)
+ equals_dx.highlight_by_tex("dx", GREEN)
+ equals_dx.add_background_rectangle()
+ equals_dx.next_to(lhs_derivative, RIGHT, buff = SMALL_BUFF)
+
+ circle = Circle(color = GREEN)
+ circle.replace(self.rhs)
+ circle.scale_in_place(1.7)
+
+ arrow = Arrow(rhs.get_right(), dx.get_top())
+ arrow.highlight(GREEN)
+
+ self.play(ReplacementTransform(lhs_brace, circle))
+ self.play(ShowCreation(arrow))
+ self.play(Write(equals_dx))
+ self.dither()
+ self.play(*map(FadeOut, [circle, arrow]))
+
+ self.equals_dx = equals_dx
+
+ def put_step_on_curve(self):
+ dot = self.dot
+ point = dot.get_center()
+ graph = self.graphs[4]
+ arrow, dx_line, dx_line.label, dy_line, dy_line.label = self.step_group
+
+ #Find graph point at right x_val
+ arrow_end = arrow.get_end()
+ graph_points = [
+ graph.point_from_proportion(alpha)
+ for alpha in np.linspace(0, 1, 1000)
+ ]
+ distances = np.apply_along_axis(
+ lambda p : np.abs(p[0] - arrow_end[0]),
+ 1, graph_points
+ )
+ index = np.argmin(distances)
+ new_end_point = graph_points[index]
+
+ lil_rect = self.little_rectangle
+ self.play(
+ arrow.put_start_and_end_on, point, new_end_point,
+ dy_line.put_start_and_end_on,
+ dy_line.get_start(), new_end_point,
+ MaintainPositionRelativeTo(dy_line.label, dy_line),
+ lil_rect.shift, lil_rect.get_height()*DOWN/3,
+ run_time = 2
+ )
+ self.dither(2)
+
+ def emphasize_equality(self):
+ self.play(FocusOn(self.lhs))
+ self.dither()
+ for mob in self.lhs, self.rhs:
+ self.play(Indicate(mob))
+ self.dither()
+
+ def manipulate_to_find_dy_dx(self):
+ full_derivative = VGroup(
+ self.lhs_derivative, self.equals_dx
+ )
+ brace = Brace(full_derivative, DOWN, buff = SMALL_BUFF)
+ words = brace.get_text(
+ "Commonly, solve for", "$dy/dx$",
+ buff = SMALL_BUFF
+ )
+ VGroup(*words[1][:2]).highlight(RED)
+ VGroup(*words[1][3:]).highlight(GREEN)
+ words.add_background_rectangle()
+
+ self.play(GrowFromCenter(brace))
+ self.play(Write(words))
+ self.dither()
+
+ randy = Randolph()
+ randy.to_corner(DOWN+LEFT)
+ randy.look_at(full_derivative)
+
+ self.play(FadeIn(randy))
+ self.play(randy.change_mode, "confused")
+ self.play(Blink(randy))
+ self.dither(2)
+ self.play(randy.change_mode, "pondering")
+ self.play(Blink(randy))
+ self.dither()
+
+class AskAboutNaturalLog(TeacherStudentsScene):
+ def construct(self):
+ exp_deriv = TexMobject("\\frac{d(e^x)}{dx} = e^x")
+ for i in 2, 3, 9, 10:
+ exp_deriv[i].highlight(BLUE)
+ log_deriv = TexMobject("\\frac{d(\\ln(x))}{dx} = ???")
+ VGroup(*log_deriv[2:2+5]).highlight(GREEN)
+
+ for deriv in exp_deriv, log_deriv:
+ deriv.next_to(self.get_teacher().get_corner(UP+LEFT), UP)
+
+ self.teacher_says(
+ """We can find
+ new derivatives""",
+ target_mode = "hooray"
+ )
+ self.change_student_modes(*["happy"]*3)
+ self.play(RemovePiCreatureBubble(
+ self.get_teacher(),
+ target_mode = "raise_right_hand"
+ ))
+ self.play(Write(exp_deriv))
+ self.dither()
+ self.play(
+ Write(log_deriv),
+ exp_deriv.next_to, log_deriv, UP, LARGE_BUFF,
+ *[
+ ApplyMethod(pi.change_mode, "confused")
+ for pi in self.get_pi_creatures()
+ ]
+ )
+ self.dither(3)
+
+class DerivativeOfNaturalLog(ZoomedScene):
+ CONFIG = {
+ "zoom_factor" : 10,
+ "zoomed_canvas_corner" : DOWN+RIGHT,
+ "example_color" : MAROON_B,
+ }
+ def construct(self):
+ should_skip_animations = self.skip_animations
+ self.skip_animations = True
+
+ self.add_plane()
+ self.draw_graph()
+ self.describe_as_implicit_curve()
+ self.slope_gives_derivative()
+ self.rearrange_equation()
+ self.take_derivative()
+ self.show_tiny_nudge()
+ self.note_derivatives()
+ self.solve_for_dy_dx()
+ self.skip_animations = should_skip_animations
+ self.show_slope_above_x()
+
+ def add_plane(self):
+ plane = NumberPlane()
+ plane.fade()
+ plane.add_coordinates()
+ self.add(plane)
+ self.plane = plane
+
+ def draw_graph(self):
+ graph = FunctionGraph(
+ np.log,
+ x_min = 0.01,
+ x_max = SPACE_WIDTH,
+ num_steps = 100
+ )
+ formula = TexMobject("y = \\ln(x)")
+ formula.next_to(ORIGIN, LEFT, buff = MED_LARGE_BUFF)
+ formula.to_edge(UP)
+ formula.add_background_rectangle()
+
+ self.add(formula)
+ self.play(ShowCreation(graph))
+ self.dither()
+
+ self.formula = formula
+ self.graph = graph
+
+ def describe_as_implicit_curve(self):
+ formula = self.formula #y = ln(x)
+ graph = self.graph
+
+ dot = Dot(color = self.example_color)
+ label = TexMobject("(x, y)")
+ label.add_background_rectangle()
+ label.highlight(self.example_color)
+
+ def update_dot(dot, alpha):
+ prop = interpolate(0.1, 0.7, alpha)
+ point = graph.point_from_proportion(prop)
+ dot.move_to(point)
+ return dot
+
+ def update_label(label):
+ point = dot.get_center()
+ vect = point - SPACE_HEIGHT*(DOWN+RIGHT)
+ vect = vect/np.linalg.norm(vect)
+ label.move_to(
+ point + vect*0.5*label.get_width()
+ )
+
+ update_dot(dot, 0)
+ update_label(label)
+
+ self.play(*map(FadeIn, [dot, label]))
+ self.play(
+ UpdateFromAlphaFunc(dot, update_dot),
+ UpdateFromFunc(label, update_label),
+ run_time = 3,
+ )
+ self.dither()
+ xy_start = VGroup(label[1][1], label[1][3]).copy()
+ xy_end = VGroup(formula[1][5], formula[1][0]).copy()
+ xy_end.highlight(self.example_color)
+ self.play(Transform(
+ xy_start, xy_end,
+ run_time = 2,
+ ))
+ self.dither()
+ self.play(
+ UpdateFromAlphaFunc(dot, update_dot),
+ UpdateFromFunc(label, update_label),
+ run_time = 3,
+ rate_func = lambda t : 1-0.6*smooth(t),
+ )
+ self.play(*map(FadeOut, [xy_start, label]))
+
+ self.dot = dot
+
+ def slope_gives_derivative(self):
+ dot = self.dot
+ point = dot.get_center()
+ line = Line(LEFT, RIGHT).scale(SPACE_WIDTH)
+ slope = 1./point[0]
+ line.rotate(np.arctan(slope))
+ line.move_to(point)
+
+ new_point = line.point_from_proportion(0.6)
+ interim_point = point[0]*RIGHT + new_point[1]*UP
+ dy_line = Line(point, interim_point, color = RED)
+ dx_line = Line(interim_point, new_point, color = GREEN)
+
+ equation = TexMobject(
+ "\\text{Slope} = ",
+ "\\frac{dy}{dx} = ",
+ "\\frac{d(\\ln(x))}{dx}",
+ )
+ VGroup(*equation[1][:2]).highlight(RED)
+ VGroup(*equation[2][:8]).highlight(RED)
+ VGroup(*equation[1][3:5]).highlight(GREEN)
+ VGroup(*equation[2][-2:]).highlight(GREEN)
+ for part in equation:
+ rect = BackgroundRectangle(part)
+ rect.stretch_in_place(1.2, 0)
+ part.add_to_back(rect)
+ equation.scale(0.8)
+ equation.next_to(ORIGIN, RIGHT)
+ equation.to_edge(UP, buff = MED_SMALL_BUFF)
+
+
+ self.play(
+ GrowFromCenter(line),
+ Animation(dot)
+ )
+ self.play(ShowCreation(VGroup(dy_line, dx_line)))
+ for part in equation:
+ self.play(Write(part, run_time = 2))
+ self.dither()
+
+ self.dx_line, self.dy_line = dx_line, dy_line
+ self.slope_equation = equation
+ self.tangent_line = line
+
+ def rearrange_equation(self):
+ formula = self.formula
+ y, eq = formula[1][:2]
+ ln = VGroup(*formula[1][2:4])
+ x = formula[1][5]
+
+ new_formula = TexMobject("e", "^y", "=", "x")
+ e, new_y, new_eq, new_x = new_formula
+ new_formula.next_to(
+ formula, DOWN,
+ buff = MED_LARGE_BUFF,
+ )
+ rect = BackgroundRectangle(new_formula)
+
+ y = new_y.copy().replace(y)
+ self.play(Indicate(formula, scale_factor = 1))
+ self.play(ReplacementTransform(ln.copy(), e))
+ self.play(ReplacementTransform(y, new_y))
+ self.play(ReplacementTransform(eq.copy(), new_eq))
+ self.play(
+ FadeIn(rect),
+ Animation(VGroup(e, new_y, new_eq)),
+ ReplacementTransform(x.copy(), new_x)
+ )
+ self.dither(2)
+ for mob in e, new_y, new_x:
+ self.play(Indicate(mob))
+ self.dither()
+
+ self.new_formula = new_formula
+
+ def take_derivative(self):
+ new_formula = self.new_formula
+ e, y, eq, x = new_formula
+ derivative = TexMobject("e", "^y", "\\,dy", "=", "dx")
+ new_e, new_y, dy, new_eq, dx = derivative
+ derivative.next_to(new_formula, DOWN, MED_LARGE_BUFF)
+ derivative.add_background_rectangle()
+ dx.highlight(GREEN)
+ dy.highlight(RED)
+
+ pairs = [
+ (VGroup(e, y), VGroup(new_e, new_y)),
+ (new_y, dy),
+ (eq, new_eq),
+ (x, dx)
+ ]
+ for start, target in pairs:
+ self.play(
+ ReplacementTransform(start.copy(), target)
+ )
+ self.play(FadeIn(derivative[0]), Animation(derivative[1]))
+ self.remove(derivative, pairs[0][1])
+ self.add(derivative)
+ self.dither()
+
+ self.derivative = derivative
+
+ def show_tiny_nudge(self):
+ dot = self.dot
+ point = dot.get_center()
+ dx_line = self.dx_line
+ dy_line = self.dy_line
+ group = VGroup(dot, dx_line, dy_line)
+ self.play(group.scale, 1./self.zoom_factor, point)
+ for line, tex, vect in (dx_line, "dx", UP), (dy_line, "dy", LEFT):
+ label = TexMobject(tex)
+ label.add_background_rectangle()
+ label.next_to(line, vect, buff = SMALL_BUFF)
+ label.highlight(line.get_color())
+ label.scale(
+ 1./self.zoom_factor,
+ about_point = line.get_center()
+ )
+ line.label = label
+
+ self.activate_zooming()
+ lil_rect = self.little_rectangle
+ lil_rect.move_to(group)
+ lil_rect.scale_in_place(self.zoom_factor)
+ self.play(lil_rect.scale_in_place, 1./self.zoom_factor)
+ self.play(Write(dx_line.label))
+ self.play(Write(dy_line.label))
+ self.dither()
+
+ def note_derivatives(self):
+ e, y, dy, eq, dx = self.derivative[1]
+
+ self.play(FocusOn(e))
+ self.play(Indicate(VGroup(e, y, dy)))
+ self.dither()
+ self.play(Indicate(dx))
+ self.dither()
+
+ def solve_for_dy_dx(self):
+ e, y, dy, eq, dx = self.derivative[1]
+ ey_group = VGroup(e, y)
+ original_rect = self.derivative[0]
+
+ rearranged = TexMobject(
+ "{dy \\over ", " dx}", "=", "{1 \\over ", "e", "^y}"
+ )
+ new_dy, new_dx, new_eq, one_over, new_e, new_y = rearranged
+ new_ey_group = VGroup(new_e, new_y)
+ new_dx.highlight(GREEN)
+ new_dy.highlight(RED)
+ rearranged.shift(eq.get_center() - new_eq.get_center())
+ rearranged.shift(MED_SMALL_BUFF*DOWN)
+ new_rect = BackgroundRectangle(rearranged)
+
+ self.play(*[
+ ReplacementTransform(
+ m1, m2,
+ run_time = 2,
+ path_arc = -np.pi/2,
+ )
+ for m1, m2 in [
+ (original_rect, new_rect),
+ (dx, new_dx),
+ (dy, new_dy),
+ (eq, new_eq),
+ (ey_group, new_ey_group),
+ (e.copy(), one_over)
+ ]
+ ])
+ self.dither()
+
+ #Change denominator
+ e, y, eq, x = self.new_formula
+ ey_group = VGroup(e, y).copy()
+ ey_group.highlight(YELLOW)
+ x_copy = x.copy()
+
+ self.play(new_ey_group.highlight, YELLOW)
+ self.play(Transform(new_ey_group, ey_group))
+ self.play(
+ new_ey_group.highlight, WHITE,
+ x_copy.highlight, YELLOW
+ )
+ self.play(x_copy.next_to, one_over, DOWN, MED_SMALL_BUFF)
+ self.dither(2)
+
+ equals_one_over_x = VGroup(
+ new_eq, one_over, x_copy
+ ).copy()
+ rect = BackgroundRectangle(equals_one_over_x)
+ rect.stretch_in_place(1.1, dim = 0)
+ equals_one_over_x.add_to_back(rect)
+
+ self.play(
+ equals_one_over_x.next_to,
+ self.slope_equation, RIGHT, 0,
+ run_time = 2
+ )
+ self.dither()
+
+ def show_slope_above_x(self):
+ line = self.tangent_line
+ start_x = line.get_center()[0]
+ target_x = 0.2
+ graph = FunctionGraph(
+ lambda x : 1./x,
+ x_min = 0.1,
+ x_max = SPACE_WIDTH,
+ num_steps = 100,
+ color = PINK,
+ )
+
+ def update_line(line, alpha):
+ x = interpolate(start_x, target_x, alpha)
+ point = x*RIGHT + np.log(x)*UP
+ angle = np.arctan(1./x)
+ line.rotate(angle - line.get_angle())
+ line.move_to(point)
+
+ self.play(UpdateFromAlphaFunc(
+ line, update_line,
+ rate_func = there_and_back,
+ run_time = 6
+ ))
+ self.dither()
+ self.play(ShowCreation(graph, run_time = 3))
+ self.dither()
+ self.play(UpdateFromAlphaFunc(
+ line, update_line,
+ rate_func = there_and_back,
+ run_time = 6
+ ))
+ self.dither()
+
+class FinalWords(TeacherStudentsScene):
+ def construct(self):
+ words = TextMobject(
+ "This is a peek into \\\\",
+ "Multivariable", "calculus"
+ )
+ mvc = VGroup(*words[1:])
+ words.highlight_by_tex("Multivariable", YELLOW)
+ formula = TexMobject("f(x, y) = \\sin(x)y^2")
+ formula.next_to(self.get_teacher().get_corner(UP+LEFT), UP)
+
+ self.teacher_says(words)
+ self.change_student_modes("erm", "hooray", "sassy")
+ self.play(
+ FadeOut(self.teacher.bubble),
+ FadeOut(VGroup(*words[:1])),
+ mvc.to_corner, UP+LEFT,
+ self.teacher.change_mode, "raise_right_hand",
+ self.teacher.look_at, formula,
+ Write(formula, run_time = 2),
+ )
+ self.change_student_modes("pondering", "confused", "thinking")
+ self.dither(3)
+
+ ##Show series
+ series = VideoSeries()
+ series.to_edge(UP)
+ video = series[5]
+ lim = TexMobject("\\lim_{h \\to 0} \\frac{f(x+h)-f(x)}{h}")
+ self.play(
+ FadeOut(mvc),
+ FadeOut(formula),
+ self.teacher.change_mode, "plain",
+ FadeIn(
+ series, run_time = 2,
+ submobject_mode = "lagged_start",
+ ),
+ )
+ self.play(
+ video.highlight, YELLOW,
+ video.shift, video.get_height()*DOWN/2
+ )
+ lim.next_to(video, DOWN)
+ self.play(
+ Write(lim),
+ *it.chain(*[
+ [pi.change_mode, "pondering", pi.look_at, lim]
+ for pi in self.get_pi_creatures()
+ ])
+ )
+ self.dither(3)
+
+class Chapter5PatreonThanks(PatreonThanks):
+ CONFIG = {
+ "specific_patrons" : [
+ "Ali Yahya",
+ "Meshal Alshammari",
+ "CrypticSwarm ",
+ "Nathan Pellegrin",
+ "Karan Bhargava",
+ "Justin Helps",
+ "Ankit Agarwal",
+ "Yu Jun",
+ "Dave Nicponski",
+ "Damion Kistler",
+ "Juan Benet",
+ "Othman Alikhan",
+ "Justin Helps",
+ "Markus Persson",
+ "Dan Buchoff",
+ "Derek Dai",
+ "Joseph John Cox",
+ "Luc Ritchie",
+ "Daan Smedinga",
+ "Jonathan Eppele",
+ "Nils Schneider",
+ "Albert Nguyen",
+ "Mustafa Mahdi",
+ "Mathew Bramson",
+ "Guido Gambardella",
+ "Jerry Ling",
+ "Mark Govea",
+ "Vecht",
+ "Shimin Kuang",
+ "Rish Kundalia",
+ "Achille Brighton",
+ "Kirk Werklund",
+ "Ripta Pasay",
+ "Felipe Diniz",
+ ]
+ }
+
+class Thumbnail(AlternateExample):
+ def construct(self):
+ title = VGroup(*map(TextMobject, [
+ "Implicit", "Differentiation"
+ ]))
+ title.arrange_submobjects(DOWN)
+ title.scale(3)
+ title.next_to(ORIGIN, UP)
+
+ for word in title:
+ word.add_background_rectangle()
+
+ self.add_plane()
+ self.draw_graph()
+ self.graphs.set_stroke(width = 8)
+ self.remove(self.formula)
+
+
+ self.add(title)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/eoc/chapter7.py b/eoc/chapter7.py
new file mode 100644
index 000000000..abc1af87b
--- /dev/null
+++ b/eoc/chapter7.py
@@ -0,0 +1,350 @@
+from helpers import *
+
+from mobject.tex_mobject import TexMobject
+from mobject import Mobject
+from mobject.image_mobject import ImageMobject
+from mobject.vectorized_mobject import *
+
+from animation.animation import Animation
+from animation.transform import *
+from animation.simple_animations import *
+from animation.playground import *
+from topics.geometry import *
+from topics.characters import *
+from topics.functions import *
+from topics.fractals import *
+from topics.number_line import *
+from topics.combinatorics import *
+from topics.numerals import *
+from topics.three_dimensions import *
+from topics.objects import *
+from scene import Scene
+from scene.zoomed_scene import ZoomedScene
+from scene.reconfigurable_scene import ReconfigurableScene
+from camera import Camera
+from mobject.svg_mobject import *
+from mobject.tex_mobject import *
+
+from topics.common_scenes import OpeningQuote, PatreonThanks
+
+from eoc.graph_scene import *
+
+class Chapter7OpeningQuote(OpeningQuote):
+ CONFIG = {
+ "quote" : [
+ " Calculus required ",
+ "continuity",
+ ", and ",
+ "continuity ",
+ "was supposed to require the ",
+ "infinitely little",
+ "; but nobody could discover what the ",
+ "infinitely little",
+ " might be. ",
+ ],
+ "quote_arg_separator" : "",
+ "highlighted_quote_terms" : {
+ "continuity" : BLUE,
+ "infinitely" : GREEN,
+ },
+ "author" : "Bertrand Russell",
+ }
+
+class ThisVideo(TeacherStudentsScene):
+ def construct(self):
+ series = VideoSeries()
+ series.to_edge(UP)
+ deriv_videos = VGroup(*series[1:6])
+ this_video = series[6]
+ integral_videos = VGroup(*series[7:9])
+ video_groups = [deriv_videos, this_video, integral_videos]
+
+ braces = map(Brace, video_groups)
+ deriv_brace, this_brace, integral_brace = braces
+
+ tex_mobs = [
+ TexMobject(*args)
+ for args in [
+ ("{df ", " \\over \\, ", " dx}"),
+ ("\\lim_{h \\to 0}",),
+ ("\\int ", "f(x)", "\\,dx"),
+ ]
+ ]
+ deriv_tex, this_tex, integral_tex = tex_mobs
+ for tex_mob, brace in zip(tex_mobs, braces):
+ tex_mob.highlight_by_tex("f", GREEN)
+ tex_mob.highlight_by_tex("dx", YELLOW)
+ tex_mob.next_to(brace, DOWN)
+ integral_tex.shift(LARGE_BUFF*RIGHT)
+
+ lim_to_deriv_arrow = Arrow(this_tex, deriv_tex, color = WHITE)
+
+ self.add(series)
+ for index in 0, 2:
+ videos = video_groups[index]
+ brace = braces[index]
+ tex_mob = tex_mobs[index]
+ self.play(ApplyWave(
+ videos,
+ apply_function_kwargs = {"maintain_smoothness" : False}
+ ))
+ self.play(
+ GrowFromCenter(brace),
+ Write(tex_mob, run_time = 2)
+ )
+ self.dither()
+ self.play(self.get_teacher().change_mode, "raise_right_hand")
+ self.play(
+ this_video.highlight, YELLOW,
+ GrowFromCenter(this_brace)
+ )
+ self.play(Write(this_tex))
+ self.dither()
+ self.play(ShowCreation(lim_to_deriv_arrow))
+ self.change_student_modes(*["happy"]*3)
+ self.dither(2)
+
+class ApproachWordToLim(PiCreatureScene):
+ CONFIG = {
+ "dx_color" : GREEN
+ }
+ def construct(self):
+ limit_expression = self.get_limit_expression()
+ limit_expression.next_to(
+ self.pi_creature, LEFT, aligned_edge = UP
+ )
+
+ evaluated_expressions = self.get_evaluated_expressions()
+ evaluated_expressions.to_edge(UP)
+ brace = Brace(evaluated_expressions[0][-1], DOWN)
+ question = TextMobject("What does this ``approach''?")
+ question.next_to(brace, DOWN)
+
+ expression = evaluated_expressions[0]
+ self.add(expression, brace, question)
+ self.change_mode("raise_right_hand")
+ for next_expression in evaluated_expressions[1:]:
+ next_expression.move_to(expression, RIGHT)
+ self.play(Transform(expression, next_expression))
+ self.dither(0.5)
+ self.play(
+ Write(limit_expression),
+ self.pi_creature.change_mode, "pondering"
+ )
+ self.play(Indicate(limit_expression[0]))
+ self.dither(2)
+
+ def get_limit_expression(self):
+ lim = TexMobject("\\lim_", "{dx", " \\to 0}")
+ lim.highlight_by_tex("dx", self.dx_color)
+ ratio = self.get_expression("dx")
+ ratio.next_to(lim, RIGHT)
+ limit_expression = VGroup(lim, ratio)
+ return limit_expression
+
+ def get_evaluated_expressions(self):
+ result = VGroup()
+ for num_zeros in range(1, 6):
+ dx_str = "0." + "0"*num_zeros + "1"
+ expression = self.get_expression(dx_str)
+ dx = float(dx_str)
+ ratio = ((2+dx)**3-2**3)/dx
+ ratio_mob = TexMobject("%.6f\\dots"%ratio)
+ group = VGroup(expression, TexMobject("="), ratio_mob)
+ group.arrange_submobjects(RIGHT)
+ result.add(group)
+ return result
+
+ def get_expression(self, dx):
+ result = TexMobject(
+ "{(2 + ", str(dx), ")^3 - 2^3 \\over", str(dx)
+ )
+ result.highlight_by_tex(dx, self.dx_color)
+ return result
+
+class RefreshOnDerivativeDefinition(GraphScene):
+ CONFIG = {
+ "start_x" : 2,
+ "dx" : 0.7,
+ "df_color" : YELLOW,
+ "dx_color" : GREEN,
+ "secant_line_color" : MAROON_B,
+ }
+ def construct(self):
+ self.setup_axes()
+ def func(x):
+ u = 0.3*x - 1.5
+ return -u**3 + 5*u + 7
+ graph = self.get_graph(func)
+ graph_label = self.get_graph_label(graph)
+ start_x_v_line, nudged_x_v_line = [
+ self.get_vertical_line_to_graph(
+ self.start_x + nudge, graph,
+ line_class = DashedLine,
+ color = RED
+ )
+ for nudge in 0, self.dx
+ ]
+ ss_group = self.get_secant_slope_group(
+ self.start_x, graph,
+ dx = self.dx,
+ dx_label = "dx",
+ df_label = "df",
+ df_line_color = self.df_color,
+ dx_line_color = self.dx_color,
+ secant_line_color = self.secant_line_color,
+ )
+ derivative = TexMobject(
+ "{df", "\\over \\,", "dx}", "(", str(self.start_x), ")"
+ )
+ derivative.highlight_by_tex("df", self.df_color)
+ derivative.highlight_by_tex("dx", self.dx_color)
+ derivative.highlight_by_tex(str(self.start_x), RED)
+ df = derivative.get_part_by_tex("df")
+ dx = derivative.get_part_by_tex("dx")
+ input_x = derivative.get_part_by_tex(str(self.start_x))
+ derivative.move_to(self.coords_to_point(7, 4))
+ deriv_brace = Brace(derivative)
+ dx_to_0 = TexMobject("dx", "\\to 0")
+ dx_to_0.highlight_by_tex("dx", self.dx_color)
+ dx_to_0.next_to(deriv_brace, DOWN)
+
+ #Introduce graph
+ self.play(ShowCreation(graph))
+ self.play(Write(graph_label, run_time = 1))
+ self.play(Write(derivative))
+ self.dither()
+ input_copy = input_x.copy()
+ self.play(
+ input_copy.next_to,
+ self.coords_to_point(self.start_x, 0),
+ DOWN
+ )
+ self.play(ShowCreation(start_x_v_line))
+ self.dither()
+
+ #ss_group_development
+ self.play(
+ ShowCreation(ss_group.dx_line),
+ ShowCreation(ss_group.dx_label),
+ )
+ self.dither()
+ self.play(ShowCreation(ss_group.df_line))
+ self.play(Write(ss_group.df_label))
+ self.dither(2)
+ self.play(
+ ReplacementTransform(ss_group.dx_label.copy(), dx),
+ ReplacementTransform(ss_group.df_label.copy(), df),
+ run_time = 2
+ )
+ self.play(ShowCreation(ss_group.secant_line))
+ self.dither()
+
+ #Let dx approach 0
+ self.play(
+ GrowFromCenter(deriv_brace),
+ Write(dx_to_0),
+ )
+ self.animate_secant_slope_group_change(
+ ss_group,
+ target_dx = 0.01,
+ run_time = 5,
+ )
+ self.dither()
+
+ #Write out fuller limit
+ new_deriv = TexMobject(
+ "{f", "(", str(self.start_x), "+", "dx", ")",
+ "-", "f", "(", str(self.start_x), ")",
+ "\\over \\,", "dx"
+ )
+ new_deriv.highlight_by_tex("dx", self.dx_color)
+ new_deriv.highlight_by_tex("f", self.df_color)
+ new_deriv.highlight_by_tex(str(self.start_x), RED)
+ deriv_to_new_deriv = dict([
+ (
+ VGroup(derivative.get_part_by_tex(s)),
+ VGroup(*new_deriv.get_parts_by_tex(s))
+ )
+ for s in ["f", "over", "dx", "(", str(self.start_x), ")"]
+ ])
+ covered_new_deriv_parts = list(it.chain(*deriv_to_new_deriv.values()))
+ uncovered_new_deriv_parts = filter(
+ lambda part : part not in covered_new_deriv_parts,
+ new_deriv
+ )
+ new_deriv.move_to(derivative)
+ new_brace = Brace(new_deriv, DOWN)
+
+ self.animate_secant_slope_group_change(
+ ss_group,
+ target_dx = self.dx,
+ run_time = 2
+ )
+ self.play(ShowCreation(nudged_x_v_line))
+ self.dither()
+ self.play(*[
+ ReplacementTransform(*pair, run_time = 2)
+ for pair in deriv_to_new_deriv.items()
+ ]+[
+ Transform(deriv_brace, new_brace),
+ dx_to_0.next_to, new_brace, DOWN
+ ])
+ self.play(Write(VGroup(*uncovered_new_deriv_parts), run_time = 2))
+ self.dither()
+
+ #Introduce limit notation
+ lim = TexMobject("\\lim").scale(1.3)
+ dx_to_0.generate_target()
+ dx_to_0.target.scale(0.7)
+ dx_to_0.target.next_to(lim, DOWN, buff = SMALL_BUFF)
+ lim_group = VGroup(lim, dx_to_0.target)
+ lim_group.move_to(new_deriv, LEFT)
+
+ self.play(
+ ReplacementTransform(deriv_brace, lim),
+ MoveToTarget(dx_to_0),
+ new_deriv.next_to, lim_group, RIGHT,
+ run_time = 2
+ )
+ for sf, color in (1.2, YELLOW), (1/1.2, WHITE):
+ self.play(
+ lim.scale_in_place, sf,
+ lim.highlight, color,
+ submobject_mode = "lagged_start"
+ )
+ self.dither(2)
+ self.animate_secant_slope_group_change(
+ ss_group, target_dx = 0.01,
+ run_time = 5,
+ added_anims = [
+ Transform(nudged_x_v_line, start_x_v_line, run_time = 5)
+ ]
+ )
+ self.dither(2)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/eoc/exp_footnote.py b/eoc/exp_footnote.py
deleted file mode 100644
index 42699fab1..000000000
--- a/eoc/exp_footnote.py
+++ /dev/null
@@ -1,1221 +0,0 @@
-from helpers import *
-
-from mobject.tex_mobject import TexMobject
-from mobject import Mobject
-from mobject.image_mobject import ImageMobject
-from mobject.vectorized_mobject import *
-
-from animation.animation import Animation
-from animation.transform import *
-from animation.simple_animations import *
-from animation.playground import *
-from topics.geometry import *
-from topics.characters import *
-from topics.functions import *
-from topics.fractals import *
-from topics.number_line import *
-from topics.combinatorics import *
-from topics.numerals import *
-from topics.three_dimensions import *
-from topics.objects import *
-from scene import Scene
-from scene.zoomed_scene import ZoomedScene
-from scene.reconfigurable_scene import ReconfigurableScene
-from camera import Camera
-from mobject.svg_mobject import *
-from mobject.tex_mobject import *
-
-from topics.common_scenes import OpeningQuote, PatreonThanks
-
-from eoc.graph_scene import *
-
-class ExpFootnoteOpeningQuote(OpeningQuote):
- CONFIG = {
- "quote" : [
- "Who has not be amazed to learn that the function",
- "$y = e^x$,", "like a phoenix rising again from its own",
- "ashes, is its own derivative?",
- ],
- "highlighted_quote_terms" : {
- "$y = e^x$" : MAROON_B
- },
- "author" : "Francois le Lionnais"
- }
-
-class LastVideo(TeacherStudentsScene):
- def construct(self):
- series = VideoSeries()
- series.to_edge(UP)
- last_video = series[2]
- last_video.save_state()
- this_video = series[3]
-
- known_formulas = VGroup(*map(TexMobject, [
- "\\frac{d(x^n)}{dx} = nx^{n-1}",
- "\\frac{d(\\sin(x))}{dx} = \\cos(x)",
- ]))
- known_formulas.arrange_submobjects(
- DOWN, buff = MED_LARGE_BUFF,
- )
- known_formulas.scale_to_fit_height(2.5)
- exp_question = TexMobject("2^x", ", 7^x", ", e^x", " ???")
-
- last_video_brace = Brace(last_video)
- known_formulas.next_to(last_video_brace, DOWN)
- last_video_brace.save_state()
- last_video_brace.shift(3*LEFT)
- last_video_brace.set_fill(opacity = 0)
-
- self.add(series)
- self.play(
- last_video_brace.restore,
- last_video.highlight, YELLOW,
- self.get_teacher().change_mode, "raise_right_hand",
- )
- self.play(Write(known_formulas))
- self.dither()
- self.student_says(
- exp_question, student_index = -1,
- added_anims = [self.get_teacher().change_mode, "pondering"]
- )
- self.dither(2)
- self.play(known_formulas.replace, last_video)
- self.play(last_video_brace.next_to, this_video, DOWN)
- self.play(
- last_video.restore,
- this_video.highlight, YELLOW
- )
- self.play(
- exp_question.next_to, last_video_brace, DOWN,
- FadeOut(self.get_students()[-1].bubble),
- )
- self.change_student_modes(
- *["pondering"]*3,
- look_at_arg = exp_question
- )
- self.dither()
-
-class PopulationSizeGraphVsPopulationMassGraph(Scene):
- def construct(self):
- pass
-
-class DoublingPopulation(PiCreatureScene):
- CONFIG = {
- "time_color" : YELLOW,
- "pi_creature_grid_dimensions" : (8, 8),
- "pi_creature_grid_height" : 6,
- }
-
- def construct(self):
- self.remove(self.get_pi_creatures())
- self.introduce_expression()
- self.introduce_pi_creatures()
- self.count_through_days()
- self.ask_about_dM_dt()
- self.growth_per_day()
- self.relate_growth_rate_to_pop_size()
-
- def introduce_expression(self):
- f_x = TexMobject("f(x)", "=", "2^x")
- f_t = TexMobject("f(t)", "=", "2^t")
- P_t = TexMobject("P(t)", "=", "2^t")
- M_t = TexMobject("M(t)", "=", "2^t")
- functions = VGroup(f_x, f_t, P_t, M_t)
- for function in functions:
- function.scale(1.2)
- function.to_corner(UP+LEFT)
- for function in functions[1:]:
- for i, j in (0, 2), (2, 1):
- function[i][j].highlight(self.time_color)
-
- t_expression = TexMobject("t", "=", "\\text{Time (in days)}")
- t_expression.to_corner(UP+RIGHT)
- t_expression[0].highlight(self.time_color)
-
- pop_brace, mass_brace = [
- Brace(function[0], DOWN)
- for function in P_t, M_t
- ]
- for brace, word in (pop_brace, "size"), (mass_brace, "mass"):
- text = brace.get_text("Population %s"%word)
- text.to_edge(LEFT)
- brace.text = text
-
- self.play(Write(f_x))
- self.dither()
- self.play(
- Transform(f_x, f_t),
- FadeIn(
- t_expression,
- run_time = 2,
- submobject_mode = "lagged_start"
- )
- )
- self.play(Transform(f_x, P_t))
- self.play(
- GrowFromCenter(pop_brace),
- Write(pop_brace.text, run_time = 2)
- )
- self.dither(2)
-
- self.function = f_x
- self.pop_brace = pop_brace
- self.t_expression = t_expression
- self.mass_function = M_t
- self.mass_brace = mass_brace
-
- def introduce_pi_creatures(self):
- creatures = self.get_pi_creatures()
- total_num_days = self.get_num_days()
- num_start_days = 4
-
- self.reset()
- for x in range(num_start_days):
- self.let_one_day_pass()
- self.dither()
- self.play(
- Transform(self.function, self.mass_function),
- Transform(self.pop_brace, self.mass_brace),
- Transform(self.pop_brace.text, self.mass_brace.text),
- )
- self.dither()
- for x in range(total_num_days-num_start_days):
- self.let_one_day_pass()
- self.dither()
- self.joint_blink(shuffle = False)
- self.dither()
-
- def count_through_days(self):
- self.reset()
- brace = self.get_population_size_descriptor()
- days_to_let_pass = 3
-
- self.play(GrowFromCenter(brace))
- self.dither()
- for x in range(days_to_let_pass):
- self.let_one_day_pass()
- new_brace = self.get_population_size_descriptor()
- self.play(Transform(brace, new_brace))
- self.dither()
-
- self.population_size_descriptor = brace
-
- def ask_about_dM_dt(self):
- dM_dt_question = TexMobject("{dM", "\\over dt}", "=", "???")
- dM, dt, equals, q_marks = dM_dt_question
- dM_dt_question.next_to(self.function, DOWN, buff = LARGE_BUFF)
- dM_dt_question.to_edge(LEFT)
-
- self.play(
- FadeOut(self.pop_brace),
- FadeOut(self.pop_brace.text),
- Write(dM_dt_question)
- )
- self.dither(3)
- for mob in dM, dt:
- self.play(Indicate(mob))
- self.dither()
-
- self.dM_dt_question = dM_dt_question
-
- def growth_per_day(self):
- day_to_day, frac = self.get_from_day_to_day_label()
-
- self.play(
- FadeOut(self.dM_dt_question),
- FadeOut(self.population_size_descriptor),
- FadeIn(day_to_day)
- )
- rect = self.let_day_pass_and_highlight_new_creatures(frac)
-
- for x in range(2):
- new_day_to_day, new_frac = self.get_from_day_to_day_label()
- self.play(*map(FadeOut, [rect, frac]))
- frac = new_frac
- self.play(Transform(day_to_day, new_day_to_day))
- rect = self.let_day_pass_and_highlight_new_creatures(frac)
- self.play(*map(FadeOut, [rect, frac, day_to_day]))
-
- def let_day_pass_and_highlight_new_creatures(self, frac):
- num_new_creatures = 2**self.get_curr_day()
-
- self.let_one_day_pass()
- new_creatures = VGroup(
- *self.get_on_screen_pi_creatures()[-num_new_creatures:]
- )
- rect = Rectangle(
- color = GREEN,
- fill_color = BLUE,
- fill_opacity = 0.3,
- )
- rect.replace(new_creatures, stretch = True)
- rect.stretch_to_fit_height(rect.get_height()+MED_SMALL_BUFF)
- rect.stretch_to_fit_width(rect.get_width()+MED_SMALL_BUFF)
- self.play(DrawBorderThenFill(rect))
- self.play(Write(frac))
- self.dither()
- return rect
-
- def relate_growth_rate_to_pop_size(self):
- false_deriv = TexMobject(
- "{d(2^t) ", "\\over dt}", "= 2^t"
- )
- difference_eq = TexMobject(
- "{ {2^{t+1} - 2^t} \\over", "1}", "= 2^t"
- )
- real_deriv = TexMobject(
- "{ {2^{t+dt} - 2^t} \\over", "dt}", "= \\, ???"
- )
- VGroup(
- false_deriv[0][3],
- false_deriv[2][-1],
- difference_eq[0][1],
- difference_eq[0][-2],
- difference_eq[2][-1],
- difference_eq[2][-1],
- real_deriv[0][1],
- real_deriv[0][-2],
- ).highlight(YELLOW)
- VGroup(
- difference_eq[0][3],
- difference_eq[1][-1],
- real_deriv[0][3],
- real_deriv[0][4],
- real_deriv[1][-2],
- real_deriv[1][-1],
- ).highlight(GREEN)
-
- expressions = [false_deriv, difference_eq, real_deriv]
- text_arg_list = [
- ("Tempting", "...",),
- ("Rate of change", "\\\\ over one full day"),
- ("Rate of change", "\\\\ in a small time"),
- ]
- for expression, text_args in zip(expressions, text_arg_list):
- expression.next_to(
- self.function, DOWN,
- buff = LARGE_BUFF,
- aligned_edge = LEFT,
- )
- expression.brace = Brace(expression, DOWN)
- expression.brace_text = expression.brace.get_text(*text_args)
-
- time = self.t_expression[-1]
- new_time = TexMobject("3")
- new_time.move_to(time, LEFT)
-
- fading_creatures = VGroup(*self.get_on_screen_pi_creatures()[8:])
-
-
- self.play(*map(FadeIn, [
- false_deriv, false_deriv.brace, false_deriv.brace_text
- ]))
- self.dither()
- self.play(
- Transform(time, new_time),
- FadeOut(fading_creatures)
- )
- self.dither()
- for x in range(3):
- self.let_one_day_pass(run_time = 2)
- self.dither(2)
-
- for expression in difference_eq, real_deriv:
- expression.brace_text[1].highlight(GREEN)
- self.play(
- Transform(false_deriv, expression),
- Transform(false_deriv.brace, expression.brace),
- Transform(false_deriv.brace_text, expression.brace_text),
- )
- self.dither(3)
- self.reset()
- for x in range(self.get_num_days()):
- self.let_one_day_pass()
- self.dither()
-
- rect = Rectangle(color = YELLOW)
- rect.replace(real_deriv)
- rect.stretch_to_fit_width(rect.get_width()+MED_SMALL_BUFF)
- rect.stretch_to_fit_height(rect.get_height()+MED_SMALL_BUFF)
- self.play(*map(FadeOut, [
- false_deriv.brace, false_deriv.brace_text
- ]))
- self.play(ShowCreation(rect))
- self.play(*[
- ApplyFunction(
- lambda pi : pi.change_mode("pondering").look_at(real_deriv),
- pi,
- run_time = 2,
- rate_func = squish_rate_func(smooth, a, a+0.5)
- )
- for pi in self.get_pi_creatures()
- for a in [0.5*random.random()]
- ])
- self.dither(3)
-
- ###########
-
- def create_pi_creatures(self):
- width, height = self.pi_creature_grid_dimensions
- creature_array = VGroup(*[
- VGroup(*[
- PiCreature(mode = "plain")
- for y in range(height)
- ]).arrange_submobjects(UP, buff = MED_LARGE_BUFF)
- for x in range(width)
- ]).arrange_submobjects(RIGHT, buff = MED_LARGE_BUFF)
- creatures = VGroup(*it.chain(*creature_array))
- creatures.scale_to_fit_height(self.pi_creature_grid_height)
- creatures.to_corner(DOWN+RIGHT)
-
- colors = color_gradient([BLUE, GREEN, GREY_BROWN], len(creatures))
- random.shuffle(colors)
- for creature, color in zip(creatures, colors):
- creature.set_color(color)
-
- return creatures
-
- def reset(self):
- time = self.t_expression[-1]
- faders = [time] + list(self.get_on_screen_pi_creatures())
- new_time = TexMobject("0")
- new_time.next_to(self.t_expression[-2], RIGHT)
- first_creature = self.get_pi_creatures()[0]
-
- self.play(*map(FadeOut, faders))
- self.play(*map(FadeIn, [first_creature, new_time]))
- self.t_expression.submobjects[-1] = new_time
-
- def let_one_day_pass(self, run_time = 2):
- all_creatures = self.get_pi_creatures()
- on_screen_creatures = self.get_on_screen_pi_creatures()
- low_i = len(on_screen_creatures)
- high_i = min(2*low_i, len(all_creatures))
- new_creatures = VGroup(*all_creatures[low_i:high_i])
-
- to_children_anims = []
- growing_anims = []
- for old_pi, pi in zip(on_screen_creatures, new_creatures):
- pi.save_state()
- child = pi.copy()
- child.scale(0.25, about_point = child.get_bottom())
- child.eyes.scale(1.5, about_point = child.eyes.get_bottom())
- pi.move_to(old_pi)
- pi.set_fill(opacity = 0)
-
- index = list(new_creatures).index(pi)
- prop = float(index)/len(new_creatures)
- alpha = np.clip(len(new_creatures)/8.0, 0, 0.5)
- rate_func = squish_rate_func(
- smooth, alpha*prop, alpha*prop+(1-alpha)
- )
-
- to_child_anim = Transform(pi, child, rate_func = rate_func)
- to_child_anim.update(1)
- growing_anim = ApplyMethod(pi.restore, rate_func = rate_func)
- to_child_anim.update(0)
-
- to_children_anims.append(to_child_anim)
- growing_anims.append(growing_anim)
-
- time = self.t_expression[-1]
- total_new_creatures = len(on_screen_creatures) + len(new_creatures)
- new_time = TexMobject(str(int(np.log2(total_new_creatures))))
- new_time.move_to(time, LEFT)
-
- growing_anims.append(Transform(time, new_time))
-
- self.play(*to_children_anims, run_time = run_time/2.0)
- self.play(*growing_anims, run_time = run_time/2.0)
-
- def get_num_pi_creatures_on_screen(self):
- mobjects = self.get_mobjects()
- return sum([
- pi in mobjects for pi in self.get_pi_creatures()
- ])
-
- def get_population_size_descriptor(self):
- on_screen_creatures = self.get_on_screen_pi_creatures()
- brace = Brace(on_screen_creatures, LEFT)
- n = len(on_screen_creatures)
- label = brace.get_text(
- "$2^%d$"%int(np.log2(n)),
- "$=%d$"%n,
- )
- brace.add(label)
- return brace
-
- def get_num_days(self):
- x, y = self.pi_creature_grid_dimensions
- return int(np.log2(x*y))
-
- def get_curr_day(self):
- return int(np.log2(len(self.get_on_screen_pi_creatures())))
-
- def get_from_day_to_day_label(self):
- curr_day = self.get_curr_day()
- top_words = TextMobject(
- "From day", str(curr_day),
- "to", str(curr_day+1), ":"
- )
- top_words.scale_to_fit_width(4)
- top_words.next_to(
- self.function, DOWN,
- buff = MED_LARGE_BUFF,
- aligned_edge = LEFT,
- )
- top_words[1].highlight(GREEN)
-
- bottom_words = TexMobject(
- str(2**curr_day),
- "\\text{ creatures}", "\\over {1 \\text{ day}}"
- )
- bottom_words[0].highlight(GREEN)
- bottom_words.next_to(top_words, DOWN, buff = MED_LARGE_BUFF)
-
- return top_words, bottom_words
-
-class GraphOfTwoToT(GraphScene):
- CONFIG = {
- "x_axis_label" : "$t$",
- "y_axis_label" : "$M$",
- "x_labeled_nums" : range(1, 7),
- "y_labeled_nums" : range(8, 40, 8),
- "x_max" : 6,
- "y_min" : 0,
- "y_max" : 32,
- "y_tick_frequency" : 2,
- "graph_origin" : 2.5*DOWN + 5*LEFT,
- }
- def construct(self):
- self.setup_axes()
- example_t = 3
- graph = self.get_graph(lambda t : 2**t, color = BLUE_C)
- self.graph = graph
- graph_label = self.get_graph_label(
- graph, "M(t) = 2^t",
- direction = LEFT,
- )
- label_group = self.get_label_group(example_t)
- v_line, brace, height_label, ss_group, slope_label = label_group
- self.animate_secant_slope_group_change(
- ss_group,
- target_dx = 1,
- run_time = 0
- )
- self.remove(ss_group)
-
- #Draw graph and revert to tangent
- self.play(ShowCreation(graph))
- self.play(Write(graph_label))
- self.dither()
- self.play(Write(ss_group))
- self.dither()
- for target_dx in 0.01, 1, 0.01:
- self.animate_secant_slope_group_change(
- ss_group,
- target_dx = target_dx
- )
- self.dither()
-
- #Mark up with values
-
- self.play(ShowCreation(v_line))
- self.play(
- GrowFromCenter(brace),
- Write(height_label, run_time = 1)
- )
- self.dither()
- self.play(
- FadeIn(
- slope_label,
- run_time = 4,
- submobject_mode = "lagged_start"
- ),
- ReplacementTransform(
- height_label.copy(),
- slope_label.get_part_by_tex("2^")
- )
- )
- self.dither()
-
- #Vary value
- threes = VGroup(height_label[1], slope_label[2][1])
- ts = VGroup(*[
- TexMobject("t").highlight(YELLOW).scale(0.75).move_to(three)
- for three in threes
- ])
- self.play(Transform(threes, ts))
-
- alt_example_t = example_t+1
- def update_label_group(group, alpha):
- t = interpolate(example_t, alt_example_t, alpha)
- new_group = self.get_label_group(t)
- Transform(group, new_group).update(1)
- for t, three in zip(ts, threes):
- t.move_to(three)
- Transform(threes, ts).update(1)
- return group
-
- self.play(UpdateFromAlphaFunc(
- label_group, update_label_group,
- run_time = 3,
- ))
- self.play(UpdateFromAlphaFunc(
- label_group, update_label_group,
- run_time = 3,
- rate_func = lambda t : 1 - 1.5*smooth(t)
- ))
-
- def get_label_group(self, t):
- graph = self.graph
-
- v_line = self.get_vertical_line_to_graph(
- t, graph,
- color = YELLOW,
- )
- brace = Brace(v_line, RIGHT)
- height_label = brace.get_text("$2^%d$"%t)
-
- ss_group = self.get_secant_slope_group(
- t, graph, dx = 0.01,
- df_label = "dM",
- dx_label = "dt",
- dx_line_color = GREEN,
- secant_line_color = RED,
- )
- slope_label = TexMobject(
- "\\text{Slope}", "=",
- "2^%d"%t,
- "(%.7f\\dots)"%np.log(2)
- )
- slope_label.next_to(
- ss_group.secant_line.point_from_proportion(0.65),
- DOWN+RIGHT,
- buff = 0
- )
- slope_label.highlight_by_tex("Slope", RED)
- return VGroup(
- v_line, brace, height_label,
- ss_group, slope_label
- )
-
-class SimpleGraphOfTwoToT(GraphOfTwoToT):
- CONFIG = {
- "x_axis_label" : "",
- "y_axis_label" : "",
- }
- def construct(self):
- self.setup_axes()
- func = lambda t : 2**t
- graph = self.get_graph(func)
- line_pairs = VGroup()
- for x in 1, 2, 3, 4, 5:
- point = self.coords_to_point(x, func(x))
- x_axis_point = self.coords_to_point(x, 0)
- y_axis_point = self.coords_to_point(0, func(x))
- line_pairs.add(VGroup(
- DashedLine(x_axis_point, point),
- DashedLine(y_axis_point, point),
- ))
-
-
- self.play(ShowCreation(graph, run_time = 2))
- for pair in line_pairs:
- self.play(ShowCreation(pair))
- self.dither()
-
-
-class AnalyzeExponentRatio(PiCreatureScene):
- CONFIG = {
- "base" : 2,
- "base_str" : "2",
- }
- def construct(self):
- base_str = self.base_str
-
- func_def = TexMobject("M(", "t", ")", "= ", "%s^"%base_str, "t")
- func_def.to_corner(UP+LEFT)
- self.add(func_def)
-
- ratio = TexMobject(
- "{ {%s^"%base_str, "{t", "+", "dt}", "-",
- "%s^"%base_str, "t}",
- "\\over \\,", "dt}"
- )
- ratio.shift(UP+LEFT)
-
- lhs = TexMobject("{dM", "\\over \\,", "dt}", "(", "t", ")", "=")
- lhs.next_to(ratio, LEFT)
-
-
- two_to_t_plus_dt = VGroup(*ratio[:4])
- two_to_t = VGroup(*ratio[5:7])
- two_to_t_two_to_dt = TexMobject(
- "%s^"%base_str, "t",
- "%s^"%base_str, "{dt}"
- )
- two_to_t_two_to_dt.move_to(two_to_t_plus_dt, DOWN+LEFT)
- exp_prop_brace = Brace(two_to_t_two_to_dt, UP)
-
- one = TexMobject("1")
- one.move_to(ratio[5], DOWN)
- lp, rp = parens = TexMobject("()")
- parens.stretch(1.3, 1)
- parens.scale_to_fit_height(ratio.get_height())
- lp.next_to(ratio, LEFT, buff = 0)
- rp.next_to(ratio, RIGHT, buff = 0)
-
- extracted_two_to_t = TexMobject("%s^"%base_str, "t")
- extracted_two_to_t.next_to(lp, LEFT, buff = SMALL_BUFF)
-
- expressions = [
- ratio, two_to_t_two_to_dt,
- extracted_two_to_t, lhs, func_def
- ]
- for expression in expressions:
- expression.highlight_by_tex("t", YELLOW)
- expression.highlight_by_tex("dt", GREEN)
-
- #Apply exponential property
- self.play(
- Write(ratio), Write(lhs),
- self.pi_creature.change_mode, "raise_right_hand"
- )
- self.dither(2)
- self.play(
- two_to_t_plus_dt.next_to, exp_prop_brace, UP,
- self.pi_creature.change_mode, "pondering"
- )
- self.play(
- ReplacementTransform(
- two_to_t_plus_dt.copy(), two_to_t_two_to_dt,
- run_time = 2,
- path_arc = np.pi,
- ),
- FadeIn(exp_prop_brace)
- )
- self.dither(2)
-
- #Talk about exponential property
- add_exp_rect, mult_rect = rects = [
- Rectangle(
- stroke_color = BLUE,
- stroke_width = 2,
- ).replace(mob).scale_in_place(1.1)
- for mob in [
- VGroup(*two_to_t_plus_dt[1:]),
- two_to_t_two_to_dt
- ]
- ]
- words = VGroup(*[
- TextMobject(s, " ideas")
- for s in "Additive", "Multiplicative"
- ])
- words[0].move_to(words[1], LEFT)
- words.highlight(BLUE)
- words.next_to(two_to_t_plus_dt, RIGHT, buff = 1.5*LARGE_BUFF)
- arrows = VGroup(*[
- Arrow(word.get_left(), rect, color = words.get_color())
- for word, rect in zip(words, rects)
- ])
-
- self.play(ShowCreation(add_exp_rect))
- self.dither()
- self.play(ReplacementTransform(
- add_exp_rect.copy(), mult_rect
- ))
- self.dither()
- self.change_mode("happy")
- self.play(Write(words[0], run_time = 2))
- self.play(ShowCreation(arrows[0]))
- self.dither()
- self.play(
- Transform(*words),
- Transform(*arrows),
- )
- self.dither(2)
- self.play(*map(FadeOut, [
- words[0], arrows[0], add_exp_rect, mult_rect,
- two_to_t_plus_dt, exp_prop_brace,
- ]))
-
- #Factor out 2^t
- self.play(*[
- FadeIn(
- mob,
- run_time = 2,
- rate_func = squish_rate_func(smooth, 0.5, 1)
- )
- for mob in one, lp, rp
- ] + [
- ReplacementTransform(
- mob, extracted_two_to_t,
- path_arc = np.pi/2,
- run_time = 2,
- )
- for mob in two_to_t, VGroup(*two_to_t_two_to_dt[:2])
- ] + [
- lhs.next_to, extracted_two_to_t, LEFT
- ])
- self.change_mode("pondering")
- shifter = VGroup(ratio[4], one, *two_to_t_two_to_dt[2:])
- stretcher = VGroup(lp, ratio[7], rp)
- self.play(
- shifter.next_to, ratio[7], UP,
- stretcher.stretch_in_place, 0.9, 0
- )
- self.dither(2)
-
- #Ask about dt -> 0
- brace = Brace(VGroup(extracted_two_to_t, ratio), DOWN)
- alt_brace = Brace(parens, DOWN)
- dt_to_zero = TexMobject("dt", "\\to 0")
- dt_to_zero.highlight_by_tex("dt", GREEN)
- dt_to_zero.next_to(brace, DOWN)
-
- self.play(GrowFromCenter(brace))
- self.play(Write(dt_to_zero))
- self.dither(2)
-
- #Who cares
- randy = Randolph()
- randy.scale(0.7)
- randy.to_edge(DOWN)
-
- self.play(
- FadeIn(randy),
- self.pi_creature.change_mode, "plain",
- )
- self.play(PiCreatureSays(
- randy, "Who cares?",
- bubble_kwargs = {"direction" : LEFT},
- target_mode = "angry",
- ))
- self.dither(2)
- self.play(
- RemovePiCreatureBubble(randy),
- FadeOut(randy),
- self.pi_creature.change_mode, "hooray",
- self.pi_creature.look_at, parens
- )
- self.play(
- Transform(brace, alt_brace),
- dt_to_zero.next_to, alt_brace, DOWN
- )
- self.dither()
-
- #Highlight separation
- rects = [
- Rectangle(
- stroke_color = color,
- stroke_width = 2,
- ).replace(mob, stretch = True).scale_in_place(1.1)
- for mob, color in [
- (VGroup(parens, dt_to_zero), GREEN),
- (extracted_two_to_t, YELLOW),
- ]
- ]
- self.play(ShowCreation(rects[0]))
- self.dither(2)
- self.play(ReplacementTransform(rects[0].copy(), rects[1]))
- self.change_mode("happy")
- self.dither()
- self.play(*map(FadeOut, rects))
-
- #Plug in specific values
- static_constant = self.try_specific_dt_values()
- constant = static_constant.copy()
-
- #Replace with actual constant
- limit_term = VGroup(
- brace, dt_to_zero, ratio[4], one, rects[0],
- *ratio[7:]+two_to_t_two_to_dt[2:]
- )
- self.play(FadeIn(rects[0]))
- self.play(limit_term.to_corner, DOWN+LEFT)
- self.play(
- lp.stretch, 0.5, 1,
- lp.stretch, 0.8, 0,
- lp.next_to, extracted_two_to_t[0], RIGHT,
- rp.stretch, 0.5, 1,
- rp.stretch, 0.8, 0,
- rp.next_to, lp, RIGHT, SMALL_BUFF,
- rp.shift, constant.get_width()*RIGHT,
- constant.next_to, extracted_two_to_t[0], RIGHT, MED_LARGE_BUFF
- )
- self.dither()
- self.change_mode("confused")
- self.dither()
-
- #Indicate distinction between dt group and t group again
- for mob in limit_term, extracted_two_to_t:
- self.play(FocusOn(mob))
- self.play(Indicate(mob))
- self.dither()
-
- #hold_final_value
- derivative = VGroup(
- lhs, extracted_two_to_t, parens, constant
- )
- func_def_rhs = VGroup(*func_def[-2:]).copy()
- func_lp, func_rp = func_parens = TexMobject("()")
- func_parens.set_fill(opacity = 0)
- func_lp.next_to(func_def_rhs[0], LEFT, buff = 0)
- func_rp.next_to(func_lp, RIGHT, buff = func_def_rhs.get_width())
- func_def_rhs.add(func_parens)
- M = lhs[0][1]
-
- self.play(
- FadeOut(M),
- func_def_rhs.move_to, M, LEFT,
- func_def_rhs.set_fill, None, 1,
- )
- lhs[0].submobjects[1] = func_def_rhs
- self.dither()
- self.play(
- derivative.next_to, self.pi_creature, UP,
- derivative.to_edge, RIGHT,
- self.pi_creature.change_mode, "raise_right_hand"
- )
- self.dither(2)
- for mob in extracted_two_to_t, constant:
- self.play(Indicate(mob))
- self.dither()
- self.dither(2)
-
- def try_specific_dt_values(self):
- expressions = []
- for num_zeros in [1, 2, 4, 7]:
- dt_str = "0." + num_zeros*"0" + "1"
- dt_num = float(dt_str)
- output_num = (self.base**dt_num - 1) / dt_num
- output_str = "%.7f\\dots"%output_num
-
- expression = TexMobject(
- "{%s^"%self.base_str, "{%s}"%dt_str, "-1",
- "\\over \\,", "%s}"%dt_str,
- "=", output_str
- )
- expression.highlight_by_tex(dt_str, GREEN)
- expression.highlight_by_tex(output_str, BLUE)
- expression.to_corner(UP+RIGHT)
- expressions.append(expression)
-
- curr_expression = expressions[0]
- self.play(
- Write(curr_expression),
- self.pi_creature.change_mode, "pondering"
- )
- self.dither(2)
- for expression in expressions[1:]:
- self.play(Transform(curr_expression, expression))
- self.dither(2)
- return curr_expression[-1]
-
-class ExponentRatioWithThree(AnalyzeExponentRatio):
- CONFIG = {
- "base" : 3,
- "base_str" : "3",
- }
-
-class ExponentRatioWithSeven(AnalyzeExponentRatio):
- CONFIG = {
- "base" : 7,
- "base_str" : "7",
- }
-
-class ExponentRatioWithE(AnalyzeExponentRatio):
- CONFIG = {
- "base" : np.exp(1),
- "base_str" : "e",
- }
-
-class AskAboutConstantOne(TeacherStudentsScene):
- def construct(self):
- note = TexMobject(
- "{ d(a^", "t", ")", "\\over \\,", "dt}",
- "=", "a^", "t", "(\\text{Some constant})"
- )
- note.highlight_by_tex("t", YELLOW)
- note.highlight_by_tex("dt", GREEN)
- note.highlight_by_tex("constant", BLUE)
- note.to_corner(UP+LEFT)
- self.add(note)
-
- self.student_says(
- "Is there a base where\\\\",
- "that constant is 1?"
- )
- self.change_student_modes(
- "pondering", "raise_right_hand", "thinking",
- # look_at_arg = self.get_students()[1].bubble
- )
- self.dither(2)
- self.play(FadeOut(note[-1], run_time = 3))
- self.dither()
-
- self.teacher_says(
- "There is!\\\\",
- "$e = 2.71828\\dots$",
- target_mode = "hooray"
- )
- self.change_student_modes(*["confused"]*3)
- self.dither(3)
-
-class NaturalLog(Scene):
- def construct(self):
- expressions = VGroup(*map(self.get_expression, [2, 3, 7]))
- expressions.arrange_submobjects(DOWN, buff = MED_SMALL_BUFF)
- expressions.to_edge(LEFT)
-
- self.play(FadeIn(
- expressions,
- run_time = 3,
- submobject_mode = "lagged_start"
- ))
- self.dither()
- self.play(
- expressions.set_fill, None, 1,
- run_time = 2,
- submobject_mode = "lagged_start"
- )
- self.dither()
- for i in 0, 2, 1:
- self.show_natural_loggedness(expressions[i])
-
- def show_natural_loggedness(self, expression):
- base, constant = expression[1], expression[-3]
-
- log_constant, exp_constant = constant.copy(), constant.copy()
- log_base, exp_base = base.copy(), base.copy()
- log_equals, exp_equals = map(TexMobject, "==")
-
- ln = TexMobject("\\ln(2)")
- log_base.move_to(ln[-2])
- ln.remove(ln[-2])
- log_equals.next_to(ln, LEFT)
- log_constant.next_to(log_equals, LEFT)
- log_expression = VGroup(
- ln, log_constant, log_equals, log_base
- )
-
- e = TexMobject("e")
- exp_constant.scale(0.7)
- exp_constant.next_to(e, UP+RIGHT, buff = 0)
- exp_base.next_to(exp_equals, RIGHT)
- VGroup(exp_base, exp_equals).next_to(
- VGroup(e, exp_constant), RIGHT,
- aligned_edge = DOWN
- )
- exp_expression = VGroup(
- e, exp_constant, exp_equals, exp_base
- )
-
- for group, vect in (log_expression, UP), (exp_expression, DOWN):
- group.to_edge(RIGHT)
- group.shift(vect)
-
- self.play(
- ReplacementTransform(base.copy(), log_base),
- ReplacementTransform(constant.copy(), log_constant),
- run_time = 2
- )
- self.play(Write(ln), Write(log_equals))
- self.dither()
- self.play(
- ReplacementTransform(
- log_expression.copy(),
- exp_expression,
- run_time = 2,
- )
- )
- self.dither(2)
-
- ln_a = expression[-1]
- self.play(
- FadeOut(expression[-2]),
- FadeOut(constant),
- ln_a.move_to, constant, LEFT,
- ln_a.highlight, BLUE
- )
- self.dither()
- self.play(*map(FadeOut, [log_expression, exp_expression]))
- self.dither()
-
- def get_expression(self, base):
- expression = TexMobject(
- "{d(", "%d^"%base, "t", ")", "\\over \\,", "dt}",
- "=", "%d^"%base, "t", "(%.4f\\dots)"%np.log(base),
- )
- expression.highlight_by_tex("t", YELLOW)
- expression.highlight_by_tex("dt", GREEN)
- expression.highlight_by_tex("\\dots", BLUE)
-
- brace = Brace(expression.get_part_by_tex("\\dots"), UP)
- brace_text = brace.get_text("$\\ln(%d)$"%base)
- for mob in brace, brace_text:
- mob.set_fill(opacity = 0)
-
- expression.add(brace, brace_text)
- return expression
-
-class NextVideo(TeacherStudentsScene):
- def construct(self):
- series = VideoSeries()
- series.to_edge(UP)
- this_video = series[3]
- next_video = series[4]
- brace = Brace(this_video, DOWN)
- this_video.save_state()
- this_video.highlight(YELLOW)
-
- this_tex = TexMobject(
- "{d(", "a^t", ") \\over dt} = ", "a^t", "\\ln(a)"
- )
- this_tex[1][1].highlight(YELLOW)
- this_tex[3][1].highlight(YELLOW)
- this_tex.next_to(brace, DOWN)
-
- next_tex = VGroup(*map(TextMobject, [
- "Chain rule", "Product rule", "$\\vdots$"
- ]))
- next_tex.arrange_submobjects(DOWN)
- next_tex.next_to(brace, DOWN)
- next_tex.shift(
- next_video.get_center()[0]*RIGHT\
- -next_tex.get_center()[0]*RIGHT
- )
-
- self.add(series, brace, *this_tex[:3])
- self.change_student_modes(
- "confused", "pondering", "erm",
- look_at_arg = this_tex
- )
- self.play(ReplacementTransform(
- this_tex[1].copy(), this_tex[3]
- ))
- self.dither()
- self.play(
- Write(this_tex[4]),
- ReplacementTransform(
- this_tex[3][0].copy(),
- this_tex[4][3],
- path_arc = np.pi,
- remover = True
- )
- )
- self.dither(2)
- self.play(this_tex.replace, this_video)
- self.play(
- brace.next_to, next_video, DOWN,
- this_video.restore,
- Animation(this_tex),
- next_video.highlight, YELLOW,
- Write(next_tex),
- self.get_teacher().change_mode, "raise_right_hand"
- )
- self.change_student_modes(
- *["pondering"]*3,
- look_at_arg = next_tex
- )
- self.dither(3)
-
-class ExpPatreonThanks(PatreonThanks):
- CONFIG = {
- "specific_patrons" : [
- "Ali Yahya",
- "Meshal Alshammari",
- "CrypticSwarm ",
- "Kathryn Schmiedicke",
- "Nathan Pellegrin",
- "Karan Bhargava",
- "Justin Helps",
- "Ankit Agarwal",
- "Yu Jun",
- "Dave Nicponski",
- "Damion Kistler",
- "Juan Benet",
- "Othman Alikhan",
- "Justin Helps",
- "Markus Persson",
- "Dan Buchoff",
- "Derek Dai",
- "Joseph John Cox",
- "Luc Ritchie",
- "Mustafa Mahdi",
- "Daan Smedinga",
- "Jonathan Eppele",
- "Albert Nguyen",
- "Nils Schneider",
- "Mustafa Mahdi",
- "Mathew Bramson",
- "Guido Gambardella",
- "Jerry Ling",
- "Mark Govea",
- "Vecht",
- "Shimin Kuang",
- "Rish Kundalia",
- "Achille Brighton",
- "Kirk Werklund",
- "Ripta Pasay",
- "Felipe Diniz",
- ]
- }
-
-class Thumbnail(Scene):
- def construct(self):
- derivative = TexMobject(
- "\\frac{d(a^t)}{dt} = a^t \\ln(a)"
- )
- derivative[3].highlight(YELLOW)
- derivative[10].highlight(YELLOW)
- derivative[2].highlight(BLUE)
- derivative[9].highlight(BLUE)
- derivative[14].highlight(BLUE)
- derivative.scale(2)
- derivative.to_edge(UP)
-
- randy = Randolph()
- randy.scale(1.3)
- randy.next_to(ORIGIN, LEFT).to_edge(DOWN)
- randy.change_mode("pondering")
-
- question = TextMobject("What is $e\\,$?")
- e = question[-2]
- e.scale(1.2, about_point = e.get_bottom())
- e.highlight(BLUE)
- question.scale(1.7)
- question.next_to(randy, RIGHT, aligned_edge = UP)
- question.shift(DOWN)
- randy.look_at(question)
-
- self.add(derivative, randy, question)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/eoc/graph_scene.py b/eoc/graph_scene.py
index 4967c1c24..a9f8c7d7f 100644
--- a/eoc/graph_scene.py
+++ b/eoc/graph_scene.py
@@ -251,6 +251,7 @@ class GraphScene(Scene):
df_label, (if applicable)
secant_line, (if applicable)
)
+ with attributes of those names.
"""
kwargs = locals()
kwargs.pop("self")
diff --git a/mobject/tex_mobject.py b/mobject/tex_mobject.py
index 691a1a98b..c6e83f142 100644
--- a/mobject/tex_mobject.py
+++ b/mobject/tex_mobject.py
@@ -110,28 +110,23 @@ class TexMobject(SVGMobject):
self.submobjects = new_submobjects
return self
- def get_part_by_tex(self, tex, substring = True, return_all_parts = False):
+ def get_parts_by_tex(self, tex, substring = True):
def test(tex1, tex2):
return tex1 == tex2 or (substring and tex1 in tex2)
+
if not hasattr(self, "expression_parts"):
if test(tex, self.get_tex_string()):
return self
- return None
- all_parts = [
+ return []
+ return [
submob
for submob, part_tex in zip(self.split(), self.expression_parts)
if test(tex, part_tex)
]
- if return_all_parts:
- return all_parts
- else:
- if len(all_parts) > 0:
- return all_parts[0]
- else:
- return None
- def get_parts_by_tex(self, tex, **kwargs):
- return self.get_part_by_tex(tex, return_all_parts = True, **kwargs)
+ def get_part_by_tex(self, tex, **kwargs):
+ all_parts = self.get_parts_by_tex(tex, **kwargs)
+ return all_parts[0] if all_parts else None
def highlight_by_tex(self, tex, color, **kwargs):
parts_to_color = self.get_parts_by_tex(tex, **kwargs)
diff --git a/topics/common_scenes.py b/topics/common_scenes.py
index 413f1ca7a..1fa196150 100644
--- a/topics/common_scenes.py
+++ b/topics/common_scenes.py
@@ -18,6 +18,7 @@ class OpeningQuote(Scene):
"""that contains all the
germs of generality."""
],
+ "quote_arg_separator" : " ",
"highlighted_quote_terms" : {
"special case" : BLUE
},
@@ -25,7 +26,7 @@ class OpeningQuote(Scene):
"fade_in_kwargs" : {
"submobject_mode" : "lagged_start",
"rate_func" : None,
- "lag_factor" : 3,
+ "lag_factor" : 4,
"run_time" : 5,
},
}
@@ -39,14 +40,15 @@ class OpeningQuote(Scene):
self.dither()
def get_quote(self, max_width = 2*SPACE_WIDTH-1):
+ text_mobject_kwargs = {
+ "alignment" : "",
+ "arg_separator" : self.quote_arg_separator,
+ }
if isinstance(self.quote, str):
- quote = TextMobject(
- "``%s''"%self.quote.strip(),
- alignment = "",
- )
+ quote = TextMobject("``%s''"%self.quote.strip(), **text_mobject_kwargs)
else:
words = ["``"] + list(self.quote) + ["''"]
- quote = TextMobject(*words, alignment = "")
+ quote = TextMobject(*words, **text_mobject_kwargs)
##TODO, make less hacky
quote[0].shift(0.2*RIGHT)
quote[-1].shift(0.2*LEFT)