diff options
author | Vaishnavi | 2020-06-26 03:37:33 +0530 |
---|---|---|
committer | GitHub | 2020-06-26 03:37:33 +0530 |
commit | cfba6959b00fab943e6d590a28bd57c24032d71e (patch) | |
tree | 403c5b8c36ff8556216fcea882debec854cfd82f /FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points | |
parent | f1dfbd78a5fea187577cc648f0d251c897a9c907 (diff) | |
download | FSF-mathematics-python-code-archive-cfba6959b00fab943e6d590a28bd57c24032d71e.tar.gz FSF-mathematics-python-code-archive-cfba6959b00fab943e6d590a28bd57c24032d71e.tar.bz2 FSF-mathematics-python-code-archive-cfba6959b00fab943e6d590a28bd57c24032d71e.zip |
Update and rename file4_Types_of_critical_points.py to file4_Relative_Maxima_and_Relative_Minima.py
Diffstat (limited to 'FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points')
2 files changed, 51 insertions, 134 deletions
diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file4_Relative_Maxima_and_Relative_Minima.py b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file4_Relative_Maxima_and_Relative_Minima.py new file mode 100644 index 0000000..7999527 --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file4_Relative_Maxima_and_Relative_Minima.py @@ -0,0 +1,51 @@ +from manimlib.imports import* +import math as m + +#---- locating extrema of a funtion using critical points +class Extrema(ThreeDScene): + def construct(self): + + h_text = TextMobject("Relative Maxima and Relative Minima",color = GREEN) + + axes = ThreeDAxes() + label_x = TextMobject("$x$").shift([5.5,-0.3,0]) #---- x axis + label_y = TextMobject("$y$").shift([-0.3,5.5,0]).rotate(-4.5) #---- y axis + + #---- f(x,y) = 5(x+y)e^(-x^2-y^2) + surface = ParametricSurface( + lambda u, v: np.array([ + u, + v, + 5*(u+v)*m.exp(-u**2-v**2) + ]),u_min = -PI, u_max = PI, v_min = -PI, v_max = PI).set_color(TEAL).shift([0,0,0]).fade(0.4) + + d1 = Dot(color = YELLOW).shift([0.5,0.5,3.02]) #---- critical point for maxima + l1 = Line([0.5,0.5,0.1],[0.5,0.5,3],color = YELLOW) + + d2 = Dot(color = YELLOW).shift([-1.15,0,-2.98]) #---- critical point for minima + l2 = Line([-1.15,0,0],[-1.15,0,-2.98],color = YELLOW) + + max_text = TextMobject("Relative Maxima").shift(3.1*UP+1.5*RIGHT).scale(0.5) + min_text = TextMobject("Relative Minima").shift(3.1*DOWN+1.5*LEFT).scale(0.5) + + self.add_fixed_in_frame_mobjects(h_text) + self.wait(1) + self.wait(1) + self.play(FadeOut(h_text)) + self.wait(1) + self.set_camera_orientation(phi = 100*DEGREES, theta = -40*DEGREES) + self.add(axes) + self.add(label_x) + self.add(label_y) + self.play(Write(surface)) + self.wait(1) + self.play(Write(l1),Write(d1)) + self.add_fixed_in_frame_mobjects(max_text) + self.wait(1) + self.play(Write(l2),Write(d2)) + self.add_fixed_in_frame_mobjects(min_text) + self.wait(1) + self.wait(1) + self.play(FadeOut(l1),FadeOut(d1),FadeOut(l2),FadeOut(d2),FadeOut(max_text),FadeOut(min_text)) + self.begin_ambient_camera_rotation(rate = 0.3) + self.wait(3) diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file4_Types_of_critical_points.py b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file4_Types_of_critical_points.py deleted file mode 100644 index 656fb68..0000000 --- a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file4_Types_of_critical_points.py +++ /dev/null @@ -1,134 +0,0 @@ -from manimlib.imports import* - - -#---- Relative Maxima -class firstScene(ThreeDScene): - def construct(self): - - r_text = TextMobject("Relative Maximum at ORIGIN",color ='#87CEFA') - - axes = ThreeDAxes() - label_x = TextMobject("$x$").shift([5.5,-0.5,0]) #---- x axis - label_y = TextMobject("$y$").shift([-0.5,5.5,0]).rotate(-4.5) #---- y axis - - #----graph of the function f(x,y) = -x**2-y**2 - surface = ParametricSurface( - lambda u, v: np.array([ - u, - v, - -u**2-v**2 - ]),v_min = -1, v_max = 1, u_min = -1, u_max = 1, checkerboard_colors = [YELLOW_B,YELLOW_C,YELLOW_D, YELLOW_E]).scale(1.5).shift([0,0,-0.51]).fade(0.3) - - f_text = TextMobject("$f(x,y) = -x^2-y^2$").to_corner(UL) - - d = Dot(color = "#800000").shift([0,0,0]) #---- critical point - - self.set_camera_orientation(phi = 75 * DEGREES, theta = 45 * DEGREES) - self.add_fixed_in_frame_mobjects(r_text) - self.wait(1) - self.play(FadeOut(r_text)) - self.begin_ambient_camera_rotation(rate = 0.1) - self.add(axes) - self.add(label_x) - self.add(label_y) - self.play(Write(surface),Write(d)) - self.add_fixed_in_frame_mobjects(f_text) - self.wait(2) - self.play(FadeOut(axes),FadeOut(surface),FadeOut(f_text),FadeOut(d),FadeOut(label_x),FadeOut(label_y)) - - -#---- Relative Minima -class secondScene(ThreeDScene): - def construct(self): - - r2_text = TextMobject("Relative Minimum at ORIGIN",color ='#87CEFA') - - axes = ThreeDAxes() - label_x = TextMobject("$x$").shift([5.5,-0.5,0]) #---- x axis - label_y = TextMobject("$y$").shift([-0.5,5.5,0]).rotate(-4.5) #---- y axis - - #----graph of the function g(x,y) = x**2+y**2 - surface = ParametricSurface( - lambda u, v: np.array([ - u, - v, - u**2+v**2 - ]),v_min = -1, v_max = 1, u_min = -1, u_max = 1, checkerboard_colors =[TEAL_B,TEAL_C,TEAL_D,TEAL_E]).scale(1.5).shift([0,0,0.55]).fade(0.1) - - d = Dot(color = "#800000").shift([0,0,0]) #---- critical point - - g_text = TextMobject("$f(x,y) = x^2+y^2$").to_corner(UL) - - self.set_camera_orientation(phi = 75 * DEGREES, theta = 45 * DEGREES) - self.add_fixed_in_frame_mobjects(r2_text) - self.wait(1) - self.play(FadeOut(r2_text)) - self.begin_ambient_camera_rotation(rate = 0.1) - self.add(axes) - self.add(label_x) - self.add(label_y) - self.play(Write(surface),Write(d)) - self.add_fixed_in_frame_mobjects(g_text) - self.wait(2) - self.play(FadeOut(axes),FadeOut(surface),FadeOut(g_text),FadeOut(d),FadeOut(label_x),FadeOut(label_y)) - - - -#---- Saddle Point -class thirdScene(ThreeDScene): - def construct(self): - - r3_text = TextMobject("Saddle Point", color = '#87CEFA') - - axes = ThreeDAxes() - label_x = TextMobject("$x$").shift([5.5,-0.5,0]) #---- x axis - label_y = TextMobject("$y$").shift([-0.5,5.5,0]).rotate(-4.5) #---- y axis - - #---- graph of function h(x,y) = -x^2 + y^2 - surface = ParametricSurface( - lambda u, v: np.array([ - u, - v, - -u**2+v**2 - ]),v_min = -1, v_max = 1, u_min = -1, u_max = 1,checkerboard_colors = [PURPLE_B,PURPLE_C,PURPLE_D,PURPLE_E]).scale(1.5).shift([0,0,0]) - - #---- curve(trace) along x axis - curve_x = ParametricSurface( - lambda u, v: np.array([ - u*0.4, - v, - v**2 - ]),v_min = -1, v_max = 1, u_min = -0.2, u_max = 0.2).shift([0,0,0.34]).scale(1.5).set_color("#800000") - - #---- curve(trace) along y axis - curve_y = ParametricSurface( - lambda u, v: np.array([ - u, - v*0.4, - -u**2 - ]),v_min = -0.2, v_max = 0.2, u_min = -1, u_max = 1).scale(1.6).shift([0,0,-0.1]).set_color("#800000") - - d = Dot(color = GREEN).shift([0,0,0.1]) #---- critical point - - h_text = TextMobject("$f(x,y) = -x^2+y^2$").to_corner(UL) - - self.add_fixed_in_frame_mobjects(r3_text) - self.wait(1) - self.set_camera_orientation(phi = 50 * DEGREES,theta = 45 * DEGREES) - self.play(FadeOut(r3_text)) - self.add(axes) - self.add(label_x) - self.add(label_y) - self.begin_ambient_camera_rotation(rate = 0.3) - self.add_fixed_in_frame_mobjects(h_text) - self.play(Write(surface)) - self.wait(1) - self.add(curve_y) - self.add(d) - self.wait(1) - self.play(FadeOut(curve_y)) - self.wait(1) - self.add(curve_x) - self.wait(1) - self.add(d) - self.wait(1) |