Метод касательных. Метод Ньютона.

Поделиться
HTML-код
  • Опубликовано: 4 май 2024

Комментарии • 3

  • @OnTheWayToTheDirection
    @OnTheWayToTheDirection  2 месяца назад

    Code Snippet:
    from manim import *
    from math import log2
    class MovingAndZoomingCamera(MovingCameraScene):
    def construct(self):
    self.camera.frame.save_state()
    # 1. Построение графика и осей:
    axes = Axes(
    x_range=[-11, 11, 1],
    y_range=[-11, 11, 1],
    x_length = 7,
    y_length = 7,
    axis_config={"color": BLUE},
    ).move_to(LEFT*3)
    labels = axes.get_axis_labels(x_label="x", y_label="y")
    graph = axes.plot(lambda x: (x/2)**3, x_range=[-4, 4], color=GREEN)

    self.play(Create(axes, run_time = 4))
    self.play(Write(labels))
    self.play(Create(graph))
    # показываем что мы ищем:
    reshenie_dot = Dot(axes.coords_to_point(0,0), color = PINK).scale(0.8)
    podpis = MathTex("x^*", color = PINK).move_to(reshenie_dot.get_center() + LEFT/2.5 + UP/2.5).scale(0.8)
    self.play(
    Create(reshenie_dot),
    Write(podpis),
    run_time = 2
    )
    self.wait()
    # 2. Построение крайних значений функции:
    # --------------------------------------------------------
    Rpoint = Dot().move_to(axes.coords_to_point(4, 8))
    self.play(Create(Rpoint)) # *
    self.wait()
    R_point_proecsia = Dot().move_to(axes.coords_to_point(4, 0)) # точка проекц на ось Х.
    R_point_proecsia.scale(0.5)
    R_Dline = DashedLine( # пунктирная линия
    Rpoint.get_center(),
    R_point_proecsia.get_center()
    )
    # --------------------------------------------------------

    Lpoint = Dot().move_to(axes.coords_to_point(-4, -8))
    self.play(Create(Lpoint)) # *
    self.wait()
    L_point_proecsia = Dot().move_to(axes.coords_to_point(-4, 0)) # точка проекц на ось Х.
    L_point_proecsia.scale(0.5)
    L_Dline = DashedLine( # пунктирная линия
    Lpoint.get_center(),
    L_point_proecsia.get_center()
    )
    self.play(Create(L_Dline), Create(L_point_proecsia), Create(R_Dline), Create(R_point_proecsia))
    self.wait()
    # --------------------------------------------------------
    # 3. Подписываем крайние точки:
    L_label = MathTex("x_{a}").move_to(L_point_proecsia.get_center() + UP/3).scale(0.6)
    R_label = MathTex("x_{b}").move_to(R_point_proecsia.get_center() + DOWN/3).scale(0.6)
    self.play(Create(L_label), Create(R_label))
    self.wait()
    # 4. Проводим касаетльную
    #-
    R_label_new = MathTex("x_{0}", color = RED).move_to(R_point_proecsia.get_center() + DOWN/3).scale(0.6)
    self.play(Transform(R_label, R_label_new), Flash(R_label_new, flash_radius=0.25), run_time = 3)
    #-
    target_point = Dot().move_to(axes.coords_to_point(2.667, 0)).scale(0.5)
    casatelnaya = Line(
    axes.coords_to_point(4, 8),
    target_point.get_center(),
    color = BLUE
    )
    x1_text = MathTex("x_{1}", color = RED).move_to(target_point.get_center() + DOWN/3).scale(0.5)
    # self.play(self.camera.frame.animate.move_to(casatelnaya).set(width=10))
    self.play(Create(casatelnaya), Create(target_point))
    self.play(Create(x1_text))
    self.wait()
    # 5. Начинаем писать формулу:
    angle = Angle(
    axes.x_axis, # направление 1
    Line(axes.coords_to_point(2.667, 0), axes.coords_to_point(4, 8)), # направление 2
    radius=0.2,
    color = ORANGE
    )
    value = MathTex(r"\alpha", color = ORANGE).move_to(angle.get_center() + UP/5 + RIGHT/7).scale(0.7)
    self.play(Create(angle), Create(value))
    L1 = MathTex(
    "x_1 - x_0",
    " = ",
    "-",
    r"AB",
    r"\cdot",
    r"\cos(",
    r"\alpha",
    ")"
    ).move_to([4,3,0])
    L1[0].color = RED
    L1[2].color = RED
    L1[3].color = BLUE
    L1[6].color = ORANGE
    # 6. Обозначения для касательно
    A = Text("A", color=BLUE).move_to(x1_text.get_center()).scale(0.6)
    B = Text("B", color=BLUE).move_to(Rpoint.get_center()+UP/3+RIGHT/6).scale(0.6)

    self.play(Write(L1))
    self.play(
    ReplacementTransform(x1_text, A), # не используй Transform!!!!
    Flash(x1_text, flash_radius=0.25),
    run_time = 3
    )
    self.play(Create(B))
    self.wait()

    self.play(Wiggle(
    VGroup(
    A,
    B,
    casatelnaya,
    L1[3]
    )
    ), run_time = 2)


    self.wait()

    • @OnTheWayToTheDirection
      @OnTheWayToTheDirection  2 месяца назад

      # 7. отмечаю f(x_0) на оси Y:
      R_point_proecsia_y = Dot().move_to(axes.coords_to_point(0, 8)).scale(0.5)
      F_ot_X_dashLIne = DashedLine( # пунктирная линия
      Rpoint.get_center(),
      R_point_proecsia_y.get_center()
      )
      self.play(Create(R_point_proecsia_y), Create(F_ot_X_dashLIne), run_time = 2)
      self.wait()
      # 8. Подписываем значение.
      f_ot_x_Label = MathTex("f(x_0)", color = GREEN).move_to(R_point_proecsia_y.get_center()+LEFT/1.8).scale(0.7)
      self.play(Create(f_ot_x_Label))
      self.wait()
      # 9. Меняем формулу
      L2 = MathTex(
      "x_1 - x_0",
      " = ",
      "-",
      r"\frac{f(x_0)}{\sin(\alpha)}",
      r"\cdot",
      r"\cos(",
      r"\alpha",
      ")"
      ).move_to(L1.get_center() + DOWN).scale(0.7)
      L2[0].color = RED
      L2[3].color = BLUE
      L2[6].color = ORANGE
      self.play(Create(L2), run_time = 3)
      self.wait()
      L3 = MathTex(
      "x_1 - x_0",
      " = ",
      "-",
      r"f(x_0) \cdot",
      r"ctg(",
      r"\alpha",
      ")"
      ).move_to(L2.get_center() + DOWN).scale(0.7)
      L3[0].color = RED
      L3[-2].color = ORANGE
      self.play(Create(L3), run_time = 3)
      self.wait()
      L4 = MathTex(
      "x_1 - x_0",
      " = ",
      "-",
      r"\frac{f(x_0)}{tg(\alpha)}",
      ).move_to(L3.get_center() + DOWN).scale(0.7)
      L4[0].color = RED
      L4[2].color = RED
      L4[3][-2:-1].color = ORANGE
      self.play(Create(L4), run_time = 3)
      self.wait()
      L5 = MathTex(
      "x_1 - x_0",
      " = ",
      "-",
      r"\frac{f(x_0)}{f'(x_0)}",
      ).move_to(L4.get_center() + DOWN).scale(0.7)
      L5[0].color = RED
      L5[2].color = RED
      self.play(Create(L5), run_time = 3)
      self.wait()
      L6 = MathTex(
      "x_1",
      " = ",
      "x_0"
      "-",
      r"\frac{f(x_0)}{f'(x_0)}",
      ).move_to(L5.get_center() + DOWN).scale(0.7)
      L6[0].color = RED
      L6[2].color = RED
      self.play(Create(L6), run_time = 3)
      self.wait()
      self.play(FadeOut(VGroup(L1,L2,L3,L4,L5)))
      self.play(L6.animate.move_to(L1.get_center()))
      self.play(L6.animate.scale(1.4))
      self.wait()
      # 10. Подготовка к построению 2ой касательной:
      self.play(self.camera.frame.animate.move_to(axes.coords_to_point(2,0)).set(width=10))
      self.wait()
      # 11. Убираем лишние обозначения:
      self.play(FadeOut(casatelnaya, B, angle, value), run_time = 2)
      x1_text = MathTex("x_{1}", color = RED).move_to(target_point.get_center() + DOWN/3).scale(0.5)
      self.play(
      ReplacementTransform(A, x1_text), # не используй Transform!!!!
      Flash(x1_text, flash_radius=0.25),
      run_time = 3
      )
      self.wait()
      # 12. Снова делаем необходимые построения:
      Rpoint = Dot().move_to(axes.coords_to_point(2.667, 2.45)).scale(0.5)
      R_point_proecsia_y = Dot().move_to(axes.coords_to_point(0, 2.45)).scale(0.5)
      target_point = Dot().move_to(axes.coords_to_point(1.777, 0)).scale(0.5)
      F_ot_X_dashLIne = DashedLine( # пунктирная линия
      Rpoint.get_center(),
      R_point_proecsia_y.get_center()
      )
      F_to_X_dashLIne = DashedLine( # пунктирная линия
      Rpoint.get_center(),
      axes.coords_to_point(2.667, 0)
      )

      casatelnaya = Line(
      Rpoint.get_center(),
      target_point.get_center(),
      color = BLUE
      )
      f_ot_x_Label = MathTex("f(x_1)", color = GREEN).move_to(R_point_proecsia_y.get_center()+LEFT/1.8).scale(0.7)
      x2_text = MathTex("x_{2}", color = RED).move_to(target_point.get_center() + DOWN/3).scale(0.4)
      self.play(
      Create(f_ot_x_Label),
      Create(F_to_X_dashLIne),
      Create(F_ot_X_dashLIne),
      Create(casatelnaya),
      Create(x2_text),
      Create(R_point_proecsia_y),
      Create(target_point),
      Create(Rpoint),
      run_time = 3
      )
      self.wait()

    • @OnTheWayToTheDirection
      @OnTheWayToTheDirection  2 месяца назад

      # 13. Снова записываем формулу:
      self.play(Restore(self.camera.frame)) # перемещение камеры на исходную позицию
      L7 = MathTex(
      "x_2",
      " = ",
      "x_1"
      "-",
      r"\frac{f(x_1)}{f'(x_1)}",
      ).move_to(L6.get_center() + DOWN*1.3)
      L7[0].color = RED
      L7[2].color = RED
      self.play(Create(L7))
      self.wait()
      # 14. Продолжаем её до n:
      L8 = MathTex(
      "..."
      ).move_to(L7.get_center() + DOWN)
      self.play(Create(L8))
      self.wait()
      L9 = MathTex(
      "x_n",
      " = ",
      "x_{n-1}"
      "-",
      r"\frac{f(x_{n-1})}{f'(x_{n-1})}",
      ).move_to(L8.get_center() + DOWN)
      L9[0].color = RED
      L9[2].color = RED
      self.play(Create(L9))
      self.wait(10)