def construct(self): v_tex = "\\vec{\\textbf{v}}" eq = TexMobject("A", v_tex, "=", "\\lambda", v_tex) eq.highlight_by_tex(v_tex, YELLOW) eq.highlight_by_tex("\\lambda", MAROON_B) eq.scale(3) eq.add_background_rectangle() eq.shift(2*DOWN) title = TextMobject( "Eigen", "vectors \\\\", "Eigen", "values" , arg_separator = "") title.scale(2.5) title.to_edge(UP) # title.highlight_by_tex("Eigen", MAROON_B) title[0].highlight(YELLOW) title[2].highlight(MAROON_B) title.add_background_rectangle() self.add_vector([-1, 1], color = YELLOW, animate = False) self.apply_transposed_matrix([[3, 0], [1, 2]]) self.plane.fade() self.remove(self.j_hat) self.add(eq, title)
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 )
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)
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]
def introduce_acceleration(self): a_words = TexMobject( "{d^2 s \\over dt^2}(t)", "\\Leftrightarrow", "\\text{Acceleration}" ) a_words.highlight_by_tex("d^2 s", MAROON_B) a_words.highlight_by_tex("Acceleration", YELLOW) a_words.to_corner(UP+RIGHT ) self.add(a_words) self.show_car_movement() self.dither() self.a_words = a_words
def construct(self): self.setup_axes() self.force_skipping() self.draw_f() self.remove(self.graph_label) self.graph.set_stroke(GREEN, width = 8) tex = TexMobject("{d^n f", "\\over", "dx^n}") tex.highlight_by_tex("d^n", YELLOW) tex.highlight_by_tex("dx", BLUE) tex.scale_to_fit_height(4) tex.to_edge(UP) self.add(tex)
def construct(self): v_tex, w_tex, p_tex = get_vect_tex(*"vwp") equation = TexMobject( v_tex, "\\times", w_tex, "=", p_tex ) equation.highlight_by_tex(v_tex, V_COLOR) equation.highlight_by_tex(w_tex, W_COLOR) equation.highlight_by_tex(p_tex, P_COLOR) brace = Brace(equation[-1]) brace.stretch_to_fit_width(0.7) vector_text = brace.get_text("Vector") vector_text.highlight(RED) self.add(equation) self.play(*map(Write, [brace, vector_text])) 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
def write_second_derivative(self): ddf_over_dx_squared = TexMobject( "{d(df)", "\\over", "(dx)^2}" ) ddf_over_dx_squared.scale(0.8) ddf_over_dx_squared.move_to(self.ddf, RIGHT) ddf_over_dx_squared.highlight_by_tex("df", self.ddf.get_color()) parens = VGroup( ddf_over_dx_squared[0][1], ddf_over_dx_squared[0][4], ddf_over_dx_squared[2][0], ddf_over_dx_squared[2][3], ) right_shifter = ddf_over_dx_squared[0][0] left_shifter = ddf_over_dx_squared[2][4] exp_two = TexMobject("2") exp_two.highlight(self.ddf.get_color()) exp_two.scale(0.5) exp_two.move_to(right_shifter.get_corner(UP+RIGHT), LEFT) exp_two.shift(MED_SMALL_BUFF*RIGHT) pre_exp_two = VGroup(ddf_over_dx_squared[0][2]) self.play( Write(ddf_over_dx_squared.get_part_by_tex("over")), *[ ReplacementTransform( mob, ddf_over_dx_squared.get_part_by_tex(tex), path_arc = -np.pi/2, ) for mob, tex in (self.ddf, "df"), (self.dx_squared, "dx") ] ) self.dither(2) self.play(FadeOut(parens)) self.play( left_shifter.shift, 0.2*LEFT, right_shifter.shift, 0.2*RIGHT, ReplacementTransform(pre_exp_two, exp_two), ddf_over_dx_squared.get_part_by_tex("over").scale_in_place, 0.8 ) self.dither(2)
def construct(self): rect = Rectangle(width = 5, height = 3) # f = lambda t : 4*np.sin(t*np.pi/2) f = lambda t : 4*t g = lambda t : 3*smooth(t) curve = ParametricFunction(lambda t : f(t)*RIGHT + g(t)*DOWN) curve.highlight(YELLOW) curve.center() rect = Rectangle() rect.replace(curve, stretch = True) regions = [] for vect, color in (UP+RIGHT, BLUE), (DOWN+LEFT, GREEN): region = curve.copy() region.add_control_points(3*[rect.get_corner(vect)]) region.set_stroke(width = 0) region.set_fill(color = color, opacity = 0.5) regions.append(region) upper_right, lower_left = regions v_lines, h_lines = VGroup(), VGroup() for alpha in np.linspace(0, 1, 30): point = curve.point_from_proportion(alpha) top_point = curve.points[0][1]*UP + point[0]*RIGHT left_point = curve.points[0][0]*RIGHT + point[1]*UP v_lines.add(Line(top_point, point)) h_lines.add(Line(left_point, point)) v_lines.highlight(BLUE_E) h_lines.highlight(GREEN_E) equation = TexMobject( "\\int_0^1 g\\,df", "+\\int_0^1 f\\,dg", "= \\big(fg \\big)_0^1" ) equation.to_edge(UP) equation.highlight_by_tex( "\\int_0^1 g\\,df", upper_right.get_color() ) equation.highlight_by_tex( "+\\int_0^1 f\\,dg", lower_left.get_color() ) left_brace = Brace(rect, LEFT) down_brace = Brace(rect, DOWN) g_T = left_brace.get_text("$g(t)\\big|_0^1$") f_T = down_brace.get_text("$f(t)\\big|_0^1$") self.draw_curve(curve) self.play(ShowCreation(rect)) self.play(*map(Write, [down_brace, left_brace, f_T, g_T])) self.dither() self.play(FadeIn(upper_right)) self.play( ShowCreation( v_lines, submobjects = "one_at_a_time", run_time = 2 ), Animation(curve), Animation(rect) ) self.play(Write(equation[0])) self.dither() self.play(FadeIn(lower_left)) self.play( ShowCreation( h_lines, submobjects = "one_at_a_time", run_time = 2 ), Animation(curve), Animation(rect) ) self.play(Write(equation[1])) self.dither() self.play(Write(equation[2])) self.dither()
def construct(self): self.setup_axes() func_graph = self.get_graph( self.function, self.function_color, ) approx_graphs = [ self.get_graph( taylor_approximation(self.function, n), self.approximation_color ) for n in self.order_sequence ] near_text = TextMobject( "Near %s $= %d$"%( self.x_axis_label, self.center_point ) ) near_text.to_corner(UP + RIGHT) near_text.add_background_rectangle() equation = TexMobject( self.function_tex, "\\approx", *self.approximation_terms ) equation.next_to(near_text, DOWN, MED_LARGE_BUFF) equation.to_edge(RIGHT) near_text.next_to(equation, UP, MED_LARGE_BUFF) equation.highlight_by_tex( self.function_tex, self.function_color, substring = False ) approx_terms = VGroup(*[ equation.get_part_by_tex(tex, substring = False) for tex in self.approximation_terms ]) approx_terms.set_fill( self.approximation_color, opacity = 0, ) equation.add_background_rectangle() approx_graph = VectorizedPoint( self.input_to_graph_point(self.center_point, func_graph) ) self.play( ShowCreation(func_graph, run_time = 2), Animation(equation), Animation(near_text), ) for graph, term in zip(approx_graphs, approx_terms): self.play( Transform(approx_graph, graph, run_time = 2), Animation(equation), Animation(near_text), term.set_fill, None, 1, ) self.dither() self.dither(2)
class CubicAndQuarticApproximations(ConstructQuadraticApproximation): CONFIG = { "colors": [BLUE, YELLOW, GREEN, RED, MAROON_B], } def construct(self): self.force_skipping() self.add_background() self.take_third_derivative_of_cubic() self.show_third_derivative_of_cosine() self.add_quartic_term() self.show_fourth_derivative_of_cosine() self.take_fourth_derivative_of_quartic() self.solve_for_c4() self.show_quartic_approximation() def add_background(self): self.setup_axes() self.cosine_graph = self.get_graph( np.cos, color = self.colors[0] ) self.quadratic_graph = self.get_quadratic_graph() self.big_rect = Rectangle( height = 2*SPACE_HEIGHT, width = 2*SPACE_WIDTH, stroke_width = 0, fill_color = BLACK, fill_opacity = 0.5, ) self.add( self.cosine_graph, self.quadratic_graph, self.big_rect ) self.cosine_label = TexMobject("\\cos", "(0)", "=1") self.cosine_label.highlight_by_tex("cos", self.colors[0]) self.cosine_label.scale(0.75) self.cosine_label.to_corner(UP+LEFT) self.add(self.cosine_label) self.add(self.get_cosine_derivative()) self.add(self.get_cosine_second_derivative()) self.polynomial = TexMobject( "P(x)=", "1", "-\\frac{1}{2}", "x^2" ) self.polynomial.highlight_by_tex("1", self.colors[0]) self.polynomial.highlight_by_tex("-\\frac{1}{2}", self.colors[2]) self.polynomial.to_corner(UP+RIGHT) self.polynomial.quadratic_part = VGroup( *self.polynomial[1:] ) self.add(self.polynomial) def take_third_derivative_of_cubic(self): polynomial = self.polynomial plus_cubic_term = TexMobject("+\\,", "c_3", "x^3") plus_cubic_term.next_to(polynomial, RIGHT) plus_cubic_term.to_edge(RIGHT, buff = LARGE_BUFF) plus_cubic_term.highlight_by_tex("c_3", self.colors[3]) plus_cubic_copy = plus_cubic_term.copy() polynomial.generate_target() polynomial.target.next_to(plus_cubic_term, LEFT) self.play(FocusOn(polynomial)) self.play( MoveToTarget(polynomial), GrowFromCenter(plus_cubic_term) ) self.dither() brace = Brace(polynomial.quadratic_part, DOWN) third_derivative = TexMobject( "\\frac{d^3 P}{dx^3}(x) = ", "0" ) third_derivative.shift( brace.get_bottom() + MED_SMALL_BUFF*DOWN -\ third_derivative.get_part_by_tex("0").get_top() ) self.play(Write(third_derivative[0])) self.play(GrowFromCenter(brace)) self.play(ReplacementTransform( polynomial.quadratic_part.copy(), VGroup(third_derivative[1]) )) self.dither(2) self.play(plus_cubic_copy.next_to, third_derivative, RIGHT) derivative_term = self.take_derivatives_of_monomial( VGroup(*plus_cubic_copy[1:]) ) third_derivative.add(derivative_term) self.polynomial_third_derivative = third_derivative def show_third_derivative_of_cosine(self): pass def add_quartic_term(self): pass def show_fourth_derivative_of_cosine(self): pass def take_fourth_derivative_of_quartic(self): pass def solve_for_c4(self): pass def show_quartic_approximation(self): pass #### def take_derivatives_of_monomial(self, term): """ Must be a group of pure TexMobjects, last part must be of the form x^n """ n = int(term[-1].get_tex_string()[-1]) curr_term = term for k in range(n, 0, -1): exponent = curr_term[-1][-1] exponent_copy = exponent.copy() front_num = TexMobject("%d \\cdot"%k) front_num.move_to(curr_term[0][0], DOWN+LEFT) new_monomial = TexMobject("x^%d"%(k-1)) new_monomial.replace(curr_term[-1]) Transform(curr_term[-1], new_monomial).update(1) curr_term.generate_target() curr_term.target.shift( (front_num.get_width()+SMALL_BUFF)*RIGHT ) curr_term[-1][-1].set_fill(opacity = 0) self.play( ApplyMethod( exponent_copy.replace, front_num[0], path_arc = np.pi, ), Write( front_num[1], rate_func = squish_rate_func(smooth, 0.5, 1) ), MoveToTarget(curr_term), run_time = 2 ) self.remove(exponent_copy) self.add(front_num) curr_term = VGroup(front_num, *curr_term) self.dither() self.play(FadeOut(curr_term[-1])) return VGroup(*curr_term[:-1])
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 construct(self): rect = Rectangle(width = 5, height = 3) # f = lambda t : 4*np.sin(t*np.pi/2) f = lambda t : 4*t g = lambda t : 3*smooth(t) curve = ParametricFunction(lambda t : f(t)*RIGHT + g(t)*DOWN) curve.highlight(YELLOW) curve.center() rect = Rectangle() rect.replace(curve, stretch = True) regions = [] for vect, color in (UP+RIGHT, BLUE), (DOWN+LEFT, GREEN): region = curve.copy() region.add_control_points(3*[rect.get_corner(vect)]) region.set_stroke(width = 0) region.set_fill(color = color, opacity = 0.5) regions.append(region) upper_right, lower_left = regions v_lines, h_lines = VGroup(), VGroup() for alpha in np.linspace(0, 1, 30): point = curve.point_from_proportion(alpha) top_point = curve.points[0][1]*UP + point[0]*RIGHT left_point = curve.points[0][0]*RIGHT + point[1]*UP v_lines.add(Line(top_point, point)) h_lines.add(Line(left_point, point)) v_lines.highlight(BLUE_E) h_lines.highlight(GREEN_E) equation = TexMobject( "\\int_0^1 g\\,df", "+\\int_0^1 f\\,dg", "= \\big(fg \\big)_0^1" ) equation.to_edge(UP) equation.highlight_by_tex( "\\int_0^1 g\\,df", upper_right.get_color() ) equation.highlight_by_tex( "+\\int_0^1 f\\,dg", lower_left.get_color() ) left_brace = Brace(rect, LEFT) down_brace = Brace(rect, DOWN) g_T = left_brace.get_text("$g(t)\\big|_0^1$") f_T = down_brace.get_text("$f(t)\\big|_0^1$") self.draw_curve(curve) self.play(ShowCreation(rect)) self.play(*map(Write, [down_brace, left_brace, f_T, g_T])) self.wait() self.play(FadeIn(upper_right)) self.play( ShowCreation( v_lines, submobjects = "one_at_a_time", run_time = 2 ), Animation(curve), Animation(rect) ) self.play(Write(equation[0])) self.wait() self.play(FadeIn(lower_left)) self.play( ShowCreation( h_lines, submobjects = "one_at_a_time", run_time = 2 ), Animation(curve), Animation(rect) ) self.play(Write(equation[1])) self.wait() self.play(Write(equation[2])) self.wait()
def construct(self): clunky_deriv = TexMobject( "{d", "\\big(", "{df", "\\over", "dx}", "\\big)", "\\over", "dx }" ) over_index = clunky_deriv.index_of_part( clunky_deriv.get_parts_by_tex("\\over")[1] ) numerator = VGroup(*clunky_deriv[:over_index]) denominator = VGroup(*clunky_deriv[over_index+1:]) rp = clunky_deriv.get_part_by_tex("(") lp = clunky_deriv.get_part_by_tex(")") dfs, overs, dxs = map(clunky_deriv.get_parts_by_tex, [ "df", "over", "dx" ]) df_over_dx = VGroup(dfs[0], overs[0], dxs[0]) d = clunky_deriv.get_part_by_tex("d") d_over_dx = VGroup(d, overs[1], dxs[1]) d2f_over_dx2 = TexMobject("{d^2 f", "\\over", "dx", "^2}") d2f_over_dx2.highlight_by_tex("dx", YELLOW) for mob in clunky_deriv, d2f_over_dx2: mob.next_to(self.teacher, UP+LEFT) for mob in numerator, denominator: circle = Circle(color = YELLOW) circle.replace(mob, stretch = True) circle.scale_in_place(1.3) mob.circle = circle dx_to_zero = TexMobject("dx \\to 0") dx_to_zero.highlight(YELLOW) dx_to_zero.next_to(clunky_deriv, UP+LEFT) self.student_says( "What's that notation?", target_mode = "raise_left_hand" ) self.change_student_modes("confused", "raise_left_hand", "confused") self.play( FadeIn( clunky_deriv, run_time = 2, submobject_mode = "lagged_start" ), RemovePiCreatureBubble(self.get_students()[1]), self.teacher.change_mode, "raise_right_hand" ) self.dither() self.play(ShowCreation(numerator.circle)) self.dither() self.play(ReplacementTransform( numerator.circle, denominator.circle, )) self.dither() self.play( FadeOut(denominator.circle), Write(dx_to_zero), dxs.highlight, YELLOW ) self.dither() self.play( FadeOut(dx_to_zero), *[ApplyMethod(pi.change, "plain") for pi in self.get_pi_creatures()] ) self.play( df_over_dx.scale, dxs[1].get_height()/dxs[0].get_height(), df_over_dx.move_to, d_over_dx, RIGHT, FadeOut(VGroup(lp, rp)), d_over_dx.shift, 0.8*LEFT + 0.05*UP, ) self.dither() self.play(*[ ReplacementTransform( group, VGroup(d2f_over_dx2.get_part_by_tex(tex)) ) for group, tex in [ (VGroup(d, dfs[0]), "d^2"), (overs, "over"), (dxs, "dx"), (VGroup(dxs[1].copy()), "^2}"), ] ]) self.dither(2) self.student_says( "How does one... \\\\ read that?", student_index = 0, ) self.play(self.teacher.change, "happy") self.dither(2)
def construct(self): self.plane.fade() v = Vector(self.v_coords, color=V_COLOR) w = Vector(self.w_coords, color=W_COLOR) v.coords = Matrix(self.v_coords) w.coords = Matrix(self.w_coords) v.coords.next_to(v.get_end(), LEFT) w.coords.next_to(w.get_end(), RIGHT) v.coords.highlight(v.get_color()) w.coords.highlight(w.get_color()) for coords in v.coords, w.coords: coords.background_rectangle = BackgroundRectangle(coords) coords.add_to_back(coords.background_rectangle) v.label = self.get_vector_label(v, "v", "left", color=v.get_color()) w.label = self.get_vector_label(w, "w", "right", color=w.get_color()) matrix = Matrix( np.array([ list(v.coords.copy().get_entries()), list(w.coords.copy().get_entries()), ]).T) matrix_background = BackgroundRectangle(matrix) col1, col2 = it.starmap(Group, matrix.get_mob_matrix().T) det_text = get_det_text(matrix) v_tex, w_tex = get_vect_tex("v", "w") cross_product = TexMobject(v_tex, "\\times", w_tex, "=") cross_product.highlight_by_tex(v_tex, V_COLOR) cross_product.highlight_by_tex(w_tex, W_COLOR) cross_product.add_background_rectangle() equation_start = Group(cross_product, Group(matrix_background, det_text, matrix)) equation_start.arrange_submobjects() equation_start.next_to(ORIGIN, DOWN).to_edge(LEFT) for vect in v, w: self.play(ShowCreation(vect), Write(vect.coords), Write(vect.label)) self.dither() self.play( Transform(v.coords.background_rectangle, matrix_background), Transform(w.coords.background_rectangle, matrix_background), Transform(v.coords.get_entries(), col1), Transform(w.coords.get_entries(), col2), Transform(v.coords.get_brackets(), matrix.get_brackets()), Transform(w.coords.get_brackets(), matrix.get_brackets()), ) self.play(*map(Write, [det_text, cross_product])) v1, v2 = v.coords.get_entries() w1, w2 = w.coords.get_entries() entries = v1, v2, w1, w2 for entry in entries: entry.target = entry.copy() det = np.linalg.det([self.v_coords, self.w_coords]) equals, dot1, minus, dot2, equals_result = syms = Group( *map(TexMobject, ["=", "\\cdot", "-", "\\cdot", "=%d" % det])) equation_end = Group(equals, v1.target, dot1, w2.target, minus, w1.target, dot2, v2.target, equals_result) equation_end.arrange_submobjects() equation_end.next_to(equation_start) syms_rect = BackgroundRectangle(syms) syms.add_to_back(syms_rect) equation_end.add_to_back(syms_rect) syms.remove(equals_result) self.play(Write(syms), Transform(Group(v1, w2).copy(), Group(v1.target, w2.target), rate_func=squish_rate_func(smooth, 0, 1. / 3), path_arc=np.pi / 2), Transform(Group(v2, w1).copy(), Group(v2.target, w1.target), rate_func=squish_rate_func(smooth, 2. / 3, 1), path_arc=np.pi / 2), run_time=3) self.dither() self.play(Write(equals_result)) self.add_foreground_mobject(equation_start, equation_end) self.show_transformation(v, w) det_sym = TexMobject(str(int(abs(det)))) det_sym.scale(1.5) det_sym.next_to(v.get_end() + w.get_end(), DOWN + RIGHT, buff=MED_BUFF / 2) arc = self.get_arc(v, w, radius=1) arc.highlight(RED) self.play(Write(det_sym)) self.play(ShowCreation(arc)) self.dither()
def square_point(self): z = self.number z_point = self.plane.number_to_point(z) zero_point = self.plane.number_to_point(0) dot = Dot(z_point, color=self.dot_color) line = Line(zero_point, z_point) line.highlight(dot.get_color()) label = TexMobject(complex_string_with_i(z)) label.add_background_rectangle() label.next_to(dot, RIGHT, SMALL_BUFF) square_point = self.plane.number_to_point(z**2) square_dot = Dot(square_point, color=self.square_color) square_line = Line(zero_point, square_point) square_line.highlight(square_dot.get_color()) square_label = TexMobject(complex_string_with_i(z**2)) square_label.add_background_rectangle() square_label.next_to(square_dot, UP + RIGHT, SMALL_BUFF) result_length_label = TexMobject(str(int(abs(z**2)))) result_length_label.next_to(square_line.get_center(), self.result_label_vect) result_length_label.add_background_rectangle() arrow = Arrow( z_point, square_point, # buff = SMALL_BUFF, path_arc=np.pi / 2) arrow.highlight(WHITE) z_to_z_squared = TexMobject("z", "\\to", "z^2") z_to_z_squared.highlight_by_tex("z", dot.get_color()) z_to_z_squared.highlight_by_tex("z^2", square_dot.get_color()) z_to_z_squared.next_to(arrow.point_from_proportion(0.5), RIGHT, MED_SMALL_BUFF) z_to_z_squared.add_to_back( BackgroundRectangle( VGroup(z_to_z_squared[2][0], *z_to_z_squared[:-1])), BackgroundRectangle(z_to_z_squared[2][1])) self.play(Write(label), ShowCreation(line), DrawBorderThenFill(dot)) self.dither() self.play( ShowCreation(arrow), FadeIn(z_to_z_squared), Animation(label), ) self.play(*[ ReplacementTransform( start.copy(), target, path_arc=np.pi / 2, run_time=1.5) for start, target in [ (dot, square_dot), (line, square_line), (label, square_label), ] ]) self.dither() self.play(Write(result_length_label)) self.dither() self.example_dot = dot self.example_label = label self.example_line = line self.square_dot = square_dot self.square_label = square_label self.square_line = square_line self.z_to_z_squared = z_to_z_squared self.z_to_z_squared_arrow = arrow self.result_length_label = result_length_label
def show_functions(self): def get_deriv(n): return lambda x : derivative( s_scene.graph.underlying_function, x, n ) s_scene = TrajectoryGraphScene() v_scene = TrajectoryGraphScene( func = get_deriv(1), color = GREEN, y_max = 4, y_axis_label = "v", ) a_scene = TrajectoryGraphScene( func = get_deriv(2), color = MAROON_B, y_axis_label = "a", y_min = -2, y_max = 2, ) j_scene = TrajectoryGraphScene( func = get_deriv(3), color = PINK, y_axis_label = "j", y_min = -2, y_max = 2, ) s_graph, v_graph, a_graph, j_graph = graphs = [ VGroup(*scene.get_top_level_mobjects()) for scene in s_scene, v_scene, a_scene, j_scene ] for i, graph in enumerate(graphs): graph.scale_to_fit_height(SPACE_HEIGHT) graph.to_corner(UP+LEFT) graph.shift(i*DOWN/2.0) s_words = TexMobject( "s(t)", "\\Leftrightarrow", "\\text{Displacement}" ) s_words.highlight_by_tex("s(t)", s_scene.graph.get_color()) v_words = TexMobject( "\\frac{ds}{dt}(t)", "\\Leftrightarrow", "\\text{Velocity}" ) v_words.highlight_by_tex("ds", v_scene.graph.get_color()) j_words = TexMobject( "\\frac{d^3 s}{dt^3}(t)", "\\Leftrightarrow", "\\text{Jerk}" ) j_words.highlight_by_tex("d^3", j_scene.graph.get_color()) self.a_words.generate_target() words_group = VGroup(s_words, v_words, self.a_words.target, j_words) words_group.arrange_submobjects( DOWN, buff = MED_LARGE_BUFF, aligned_edge = LEFT ) words_group.to_corner(UP+RIGHT) j_graph.scale(0.3).next_to(j_words, LEFT) positive_rect = Rectangle() positive_rect.set_stroke(width = 0) positive_rect.set_fill(GREEN, 0.5) positive_rect.replace( Line( a_scene.coords_to_point(0, -1), a_scene.coords_to_point(5, 1), ), stretch = True ) negative_rect = Rectangle() negative_rect.set_stroke(width = 0) negative_rect.set_fill(RED, 0.5) negative_rect.replace( Line( a_scene.coords_to_point(5, 1), a_scene.coords_to_point(10, -1), ), stretch = True ) self.show_car_movement( MoveToTarget(self.a_words), FadeIn(s_words), FadeIn(s_graph), ) self.play( s_graph.scale, 0.3, s_graph.next_to, s_words, LEFT ) self.play(*map(FadeIn, [v_graph, v_words]) ) self.dither(2) self.play( v_graph.scale, 0.3, v_graph.next_to, v_words, LEFT ) self.dither(2) self.play( Indicate(self.a_words), FadeIn(a_graph), ) self.dither() self.play(FadeIn(positive_rect)) for x in range(2): self.show_car_movement( run_time = 3, rate_func = lambda t : smooth(t/2.0) ) self.dither() self.play(FadeIn(negative_rect)) self.dither() self.play(MoveCar( self.car, self.line.get_end(), run_time = 3, rate_func = lambda t : 2*smooth((t+1)/2.0) - 1 )) self.dither() self.play( a_graph.scale, 0.3, a_graph.next_to, self.a_words, LEFT, *map(FadeOut, [positive_rect, negative_rect]) ) self.play( FadeOut(self.car), FadeIn(j_words), FadeIn(j_graph), self.line.scale, 0.5, self.line.get_left(), self.line.shift, LEFT, ) self.car.scale(0.5) self.car.move_to(self.line.get_start()) self.play(FadeIn(self.car)) self.show_car_movement() self.dither(2)
def construct(self): triples = [(u**2 - v**2, 2 * u * v, u**2 + v**2) for u in range(1, 15) for v in range(1, u) if fractions.gcd(u, v) == 1 and not (u % 2 == v % 2)][:40] triangles = VGroup() titles = VGroup() for i, (a, b, c) in enumerate(triples): triangle = Polygon(ORIGIN, a * RIGHT, a * RIGHT + b * UP) triangle.highlight(WHITE) max_width = max_height = 4 triangle.scale_to_fit_height(max_height) if triangle.get_width() > max_width: triangle.scale_to_fit_width(max_width) triangle.move_to(2 * RIGHT) num_strings = map(str, (a, b, c)) labels = map(TexMobject, num_strings) for label, color in zip(labels, SIDE_COLORS): label.highlight(color) labels[0].next_to(triangle, DOWN) labels[1].next_to(triangle, RIGHT) labels[2].next_to(triangle.get_center(), UP + LEFT) triangle.add(*labels) title = TexMobject(str(a), "^2", "+", str(b), "^2", "=", str(c), "^2") for num, color in zip([a, b, c], SIDE_COLORS): title.highlight_by_tex(str(num), color) title.next_to(triangle, UP, LARGE_BUFF) title.generate_target() title.target.scale(0.5) title.target.move_to( (-SPACE_WIDTH + MED_LARGE_BUFF + 2.7*(i//8))*RIGHT + \ (SPACE_HEIGHT - MED_LARGE_BUFF - (i%8))*UP, UP+LEFT ) triangles.add(triangle) titles.add(title) triangle = triangles[0] title = titles[0] self.play( Write(triangle), Write(title), run_time=2, ) self.dither() self.play(MoveToTarget(title)) for i in range(1, 17): new_triangle = triangles[i] new_title = titles[i] if i < 4: self.play(Transform(triangle, new_triangle), FadeIn(new_title)) self.dither() self.play(MoveToTarget(new_title)) else: self.play(Transform(triangle, new_triangle), FadeIn(new_title.target)) self.dither() self.play(FadeOut(triangle)) self.play( LaggedStart(FadeIn, VGroup(*[title.target for title in titles[17:]]), run_time=5)) self.dither(2)
def show_orientation_rule(self): self.remove(self.i_hat, self.j_hat) for vect in self.v, self.w: vect.add(vect.label) vect.target = vect.copy() angle = np.pi / 3 self.v.target.rotate(-angle) self.w.target.rotate(angle) self.v.target.label.rotate_in_place(angle) self.w.target.label.rotate_in_place(-angle) for vect in self.v, self.w: vect.target.label[0].set_fill(opacity=0) self.square.target = self.square.copy().restore() transform = self.get_matrix_transformation([ self.v.target.get_end()[:2], self.w.target.get_end()[:2], ]) self.square.target.apply_function(transform) movers = Group(self.square, self.v, self.w) movers.target = Group(*[m.target for m in movers]) movers.save_state() self.remove(self.square) self.play(Transform(movers, movers.target)) self.dither() v_tex, w_tex = ["\\vec{\\textbf{%s}}" % s for s in "v", "w"] positive_words, negative_words = words_list = [ TexMobject(v_tex, "\\times", w_tex, "\\text{ is }", word) for word in "\\text{positive}", "\\text{negative}" ] for words in words_list: words.highlight_by_tex(v_tex, V_COLOR) words.highlight_by_tex(w_tex, W_COLOR) words.highlight_by_tex("\\text{positive}", GREEN) words.highlight_by_tex("\\text{negative}", RED) words.add_background_rectangle() words.next_to(self.square, UP) arc = self.get_arc(self.v, self.w) arc.highlight(GREEN) self.play(Write(positive_words), ShowCreation(arc)) self.dither() self.remove(arc) self.play(movers.restore) arc = self.get_arc(self.v, self.w) arc.highlight(RED) self.play(Transform(positive_words, negative_words), ShowCreation(arc)) self.dither() anticommute = TexMobject(v_tex, "\\times", w_tex, "=-", w_tex, "\\times", v_tex) anticommute.shift(SPACE_WIDTH * RIGHT / 2) anticommute.to_edge(UP) anticommute.highlight_by_tex(v_tex, V_COLOR) anticommute.highlight_by_tex(w_tex, W_COLOR) anticommute.add_background_rectangle() for v1, v2 in (self.v, self.w), (self.w, self.v): v1.label[0].set_fill(opacity=0) v1.target = v1.copy() v1.target.label.rotate_in_place(v1.get_angle() - v2.get_angle()) v1.target.label.scale_in_place(v1.get_length() / v2.get_length()) v1.target.rotate(v2.get_angle() - v1.get_angle()) v1.target.scale(v2.get_length() / v1.get_length()) v1.target.label.move_to(v2.label) self.play(FadeOut(arc), Transform(positive_words, anticommute)) self.play( Transform(self.v, self.v.target), Transform(self.w, self.w.target), rate_func=there_and_back, run_time=2, ) self.dither()