diff options
Diffstat (limited to 'FSF-2020')
18 files changed, 367 insertions, 335 deletions
diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/README.md b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/README.md index 5bd9cc5..857d298 100644 --- a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/README.md +++ b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/README.md @@ -19,14 +19,20 @@ <br/></br> <br/></br> -<tab>file4_Types_of_critical_points +<tab>file4_Relative_Maximum_and_Relative_Minimum -![file4_Types_of_critical_points](https://github.com/vnb09/FSF-mathematics-python-code-archive/blob/fsf_tasks/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file4_Types_of_critical_points.gif?raw=true) +![file4_Relative_Maxima_and_Relative_Minima](https://github.com/vnb09/FSF-mathematics-python-code-archive/blob/fsf_tasks/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file4_Relative_Maximum_and_Relative_Minimum.gif?raw=true) <br/></br> <br/></br> -<tab>file5_f(x,y)=(y-x)(1-2x-3y) +<tab>file5_Saddle_Point -![file5_f(x,y)=(y-x)(1-2x-3y)](https://github.com/vnb09/FSF-mathematics-python-code-archive/blob/fsf_tasks/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file5_f(x%2Cy)%3D(y-x)(1-2x-3y).gif?raw=true) +![file5_Saddle_Point](https://github.com/vnb09/FSF-mathematics-python-code-archive/blob/fsf_tasks/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file5_Saddle_Point.gif?raw=true) +<br/></br> +<br/></br> + +<tab>file6_f(x,y)=(y-x)(1-2x-3y) + +![file6_f(x,y)=(y-x)(1-2x-3y)](https://github.com/vnb09/FSF-mathematics-python-code-archive/blob/fsf_tasks/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file6_f(x%2Cy)%3D(y-x)(1-2x-3y).gif?raw=true) <br/></br> <br/></br> diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file4_Relative_Maximum_and_Relative_Minimum.gif b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file4_Relative_Maximum_and_Relative_Minimum.gif Binary files differnew file mode 100644 index 0000000..6b93359 --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file4_Relative_Maximum_and_Relative_Minimum.gif diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file4_Relative_Maximum_and_Relative_Minimum.py b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file4_Relative_Maximum_and_Relative_Minimum.py new file mode 100644 index 0000000..3bd810d --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file4_Relative_Maximum_and_Relative_Minimum.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 Maximum and Relative Minimum",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 Maximum").shift(3.1*UP+1.5*RIGHT).scale(0.5) + min_text = TextMobject("Relative Minimum").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.gif b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file4_Types_of_critical_points.gif Binary files differdeleted file mode 100644 index 91e7084..0000000 --- a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file4_Types_of_critical_points.gif +++ /dev/null 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) diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file5_Saddle_Point.gif b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file5_Saddle_Point.gif Binary files differnew file mode 100644 index 0000000..7300f3a --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file5_Saddle_Point.gif diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file5_Saddle_Point.py b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file5_Saddle_Point.py new file mode 100644 index 0000000..67dbb18 --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file5_Saddle_Point.py @@ -0,0 +1,71 @@ +from manimlib.imports import* +import math as m + +#---- saddle point of a function +class SaddlePoint(ThreeDScene): + def construct(self): + + h_text = TextMobject("Saddle Point",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) = -x^2-y^2 + surface = ParametricSurface( + lambda u, v: np.array([ + u, + v, + u**2-v**2 + ]),u_min = -1, u_max = 1, v_min = -1, v_max = 1,checkerboard_colors = [BLUE_B,BLUE_C,BLUE_D,BLUE_E]).shift([0,0,0]).scale(3) + + #---- curve(trace) along y axis + curve_x = ParametricSurface( + lambda u, v: np.array([ + u*0.1, + v, + v**2 + ]),v_min = -1, v_max = 1, u_min = -0.2, u_max = 0.2).shift([0,0,-2]).scale(3.1).set_color("#800000").rotate(m.radians(180),UP) + + x_text = TextMobject("A dip at critical point along x axis").scale(0.5).to_corner(UL) + + #---- curve(trace) along x axis + curve_y = ParametricSurface( + lambda u, v: np.array([ + u, + v*0.1, + -u**2 + ]),v_min = -0.2, v_max = 0.2, u_min = -1, u_max = 1).scale(3).shift([0.1,0,2.2]).set_color("#800000").rotate(m.radians(182),DOWN) + + y_text = TextMobject("A peak at critical point along y axis").scale(0.5).to_corner(UL) + + d = Dot(color = YELLOW).shift([0,-0.22,0]) #---- critical point(saddle point) + + self.add_fixed_in_frame_mobjects(h_text) + self.wait(1) + self.play(FadeOut(h_text)) + self.wait(1) + self.set_camera_orientation(phi = 75*DEGREES, theta = 40*DEGREES) + self.add(axes) + self.add(label_x) + self.add(label_y) + self.play(Write(surface)) + self.wait(1) + self.move_camera(phi = 45*DEGREES, theta = 70*DEGREES) + self.add(curve_y) + self.play(Write(d)) + self.wait(1) + self.add_fixed_in_frame_mobjects(x_text) + self.wait(1) + self.wait(1) + self.play(FadeOut(curve_y),FadeOut(d),FadeOut(x_text)) + self.wait(1) + self.move_camera(phi = 40*DEGREES, theta = 30*DEGREES) + self.add(curve_x) + self.play(Write(d)) + self.wait(1) + self.add_fixed_in_frame_mobjects(y_text) + self.begin_ambient_camera_rotation(rate = 0.3) + self.wait(3) + self.play(FadeOut(curve_x),FadeOut(d),FadeOut(y_text)) + self.wait(1) diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file5_f(x,y)=(y-x)(1-2x-3y).gif b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file6_f(x,y)=(y-x)(1-2x-3y).gif Binary files differindex 4bc92f8..4bc92f8 100644 --- a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file5_f(x,y)=(y-x)(1-2x-3y).gif +++ b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file6_f(x,y)=(y-x)(1-2x-3y).gif diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file5_f(x,y)=(y-x)(1-2x-3y).py b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file6_f(x,y)=(y-x)(1-2x-3y).py index 41c3b61..41c3b61 100644 --- a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file5_f(x,y)=(y-x)(1-2x-3y).py +++ b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Critical-Points/file6_f(x,y)=(y-x)(1-2x-3y).py diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/README.md b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/README.md new file mode 100644 index 0000000..e9cc918 --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/README.md @@ -0,0 +1,21 @@ +<h1><div align=”center”><b>SubTopic: The Second Derivative Test</b></h1></div> +<br/></br> + +<tab>file1_Second_order_partial_derivatives + +![file1_Second_order_partial_derivatives](https://github.com/vnb09/FSF-mathematics-python-code-archive/blob/fsf_tasks/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/file1_Second_order_partial_derivatives.gif?raw=true) +<br/></br> +<br/></br> + +<tab>file2_Nondegenerate_Hessian_Matrix + +![file2_Nondegenerate_Hessian_Matrix](https://github.com/vnb09/FSF-mathematics-python-code-archive/blob/fsf_tasks/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/file2_Nondegenerate_Hessian_Matrix.gif?raw=true) +<br/></br> +<br/></br> + +<tab>file3_Degenerate_Hessian_Matrix + +![file3_Degenerate_Hessian_Matrix](https://github.com/vnb09/FSF-mathematics-python-code-archive/blob/fsf_tasks/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/file3_Degenerate_Hessian_Matrix.gif?raw=true) +<br/></br> +<br/></br> + diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/file2_Degenerate_Hessian_Matrix.gif b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/file2_Degenerate_Hessian_Matrix.gif Binary files differdeleted file mode 100644 index d49cdd5..0000000 --- a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/file2_Degenerate_Hessian_Matrix.gif +++ /dev/null diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/file2_Degenerate_Hessian_Matrix.py b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/file2_Degenerate_Hessian_Matrix.py deleted file mode 100644 index c1e3516..0000000 --- a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/file2_Degenerate_Hessian_Matrix.py +++ /dev/null @@ -1,52 +0,0 @@ -from manimlib.imports import* - -class firstscene(Scene): - def construct(self): - - h_text = TextMobject("Degenerate Hessian Matrix", color = RED).scale(1).shift(UP) - - - f_text = TextMobject("$f(x,y) = 2x^3+y^3$", color = TEAL).scale(1).to_corner(UL) - c_text = TextMobject("Critical Point: $(0,0)$", color = TEAL).scale(1).next_to(f_text).shift(DOWN+4.3*LEFT) - m_text = TextMobject("\\begin{equation*} D_2(x,y)= \\begin{vmatrix} 12x\\space & 0\\space \\\\ 0 & 6y \\end{vmatrix} \\end{equation*}",color = YELLOW) - d_text = TextMobject("\\begin{equation*} D_2(0,0)= \\begin{vmatrix} 0 \\space & 0\\space \\\\ 0 & 0 \\end{vmatrix} \\end{equation*}",color = PURPLE) - - - t_text = TextMobject("$D_2 = 0$(Inconclusive)", color = TEAL).scale(1).shift(2*DOWN) - - self.play(ShowCreation(h_text)) - self.wait(1) - self.play(FadeOut(h_text)) - self.wait(1) - self.play(ShowCreation(f_text)) - self.wait(1) - self.play(ShowCreation(c_text)) - self.wait(1) - self.play(ShowCreation(m_text)) - self.wait(2) - self.play(ReplacementTransform(m_text,d_text)) - self.wait(1) - self.play(ShowCreation(t_text)) - self.wait(2) - - -class SecondScene(ThreeDScene): - def construct(self): - axes = ThreeDAxes() - - f = ParametricSurface( - lambda u, v: np.array([ - u, - v, - (2*u**3)+v**3 - ]),v_min=-1,v_max=1,u_min=-1,u_max=1,checkerboard_colors=[TEAL_C,YELLOW_D,BLUE_E], - resolution=(20, 20)).scale(1) - - self.set_camera_orientation(phi=25 * DEGREES,theta = 80*DEGREES) - self.begin_ambient_camera_rotation(rate=0.1) - - f_text = TextMobject("$f(x,y) = 2x^3+y^3$",color = ORANGE).shift(2*DOWN+2*RIGHT).scale(0.8) - self.add_fixed_in_frame_mobjects(f_text) - self.add(axes) - self.play(Write(f)) - self.wait(2) diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/file2_Nondegenerate_Hessian_Matrix.gif b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/file2_Nondegenerate_Hessian_Matrix.gif Binary files differnew file mode 100644 index 0000000..0d58b4f --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/file2_Nondegenerate_Hessian_Matrix.gif diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/file2_Nondegenerate_Hessian_Matrix.py b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/file2_Nondegenerate_Hessian_Matrix.py new file mode 100644 index 0000000..32c1559 --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/file2_Nondegenerate_Hessian_Matrix.py @@ -0,0 +1,158 @@ +from manimlib.imports import* +import math as m + +class Minima(ThreeDScene): + def construct(self): + + heading = TextMobject("Nondegenerate Hessian Matrix",color = BLUE) + + 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 + + h_text = TextMobject("Case 1: $\\frac{\\partial^2 f}{\\partial x^2}>0$ and $\\frac{\\partial^2 f}{\\partial y^2}>0$").scale(1) + + #---- determiniant of Hessian Matrix + hessian_surface = ParametricSurface( + lambda u, v: np.array([ + u, + v, + -0.5*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]).scale(1).fade(0.2) + + det_text= TextMobject("$det \\hspace{1mm} H = (\\frac{\\partial^2 f}{\\partial x^2})(\\frac{\\partial^2 f}{\\partial y^2})-(\\frac{\\partial^2 f}{\\partial x \\partial y})^2 $").to_corner(UL).scale(0.7) + + #---- function f(x,y) + f_surface = ParametricSurface( + lambda u, v: np.array([ + u, + v, + u**2+v**2 + ]),u_min = -1.3, u_max = 1.3, v_min = -1.3, v_max = 1.3).set_color(TEAL).shift([0,0,-0.5]) + + f_text= TextMobject("surface of the function").to_corner(UL).scale(0.8) + + d = Dot(color = "#800000").shift([0,0,-0.52]) #---- critical point + + self.set_camera_orientation(phi = 75*DEGREES, theta = 40*DEGREES) + self.add_fixed_in_frame_mobjects(heading) + self.wait(1) + self.play(FadeOut(heading)) + self.wait(1) + self.add_fixed_in_frame_mobjects(h_text) + self.wait(1) + self.play(FadeOut(h_text)) + self.wait(1) + self.add(axes) + self.add(label_x) + self.add(label_y) + self.play(Write(hessian_surface)) + self.wait(1) + self.add_fixed_in_frame_mobjects(det_text) + self.move_camera(phi = 90*DEGREES, theta= 60*DEGREES) + self.play(Write(d)) + self.wait(1) + self.play(FadeOut(det_text),ReplacementTransform(hessian_surface,f_surface)) + self.wait(1) + self.add_fixed_in_frame_mobjects(f_text) + self.wait(1) + self.play(FadeOut(f_text),FadeOut(f_surface),FadeOut(axes),FadeOut(label_x),FadeOut(label_y),FadeOut(d)) + +class Maxima(ThreeDScene): + def construct(self): + + 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 + + h_text = TextMobject("Case 2: $\\frac{\\partial^2 f}{\\partial x^2}<0$ and $\\frac{\\partial^2 f}{\\partial y^2}<0$").scale(1) + + #---- determiniant of Hessian Matrix + hessian_surface = ParametricSurface( + lambda u, v: np.array([ + u, + v, + 0.5*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]).scale(1).fade(0.2) + + det_text= TextMobject("$det \\hspace{1mm} H = (\\frac{\\partial^2 f}{\\partial x^2})(\\frac{\\partial^2 f}{\\partial y^2})-(\\frac{\\partial^2 f}{\\partial x \\partial y})^2 $").to_corner(UL).scale(0.7) + + #---- function g(x,y) + g_surface = ParametricSurface( + lambda u, v: np.array([ + u, + v, + -u**2-v**2 + ]),u_min = -1.3, u_max = 1.3, v_min = -1.3, v_max = 1.3).set_color(TEAL).shift([0,0,0.5]) + + g_text= TextMobject("surface of the function").to_corner(UL).scale(0.8) + + d = Dot(color = "#800000").shift([0,0,0.5]) #---- critical point + + self.set_camera_orientation(phi = 75*DEGREES, theta = 40*DEGREES) + self.add_fixed_in_frame_mobjects(h_text) + self.wait(1) + self.play(FadeOut(h_text)) + self.wait(1) + self.add(axes) + self.add(label_x) + self.add(label_y) + self.play(Write(hessian_surface)) + self.wait(1) + self.add_fixed_in_frame_mobjects(det_text) + self.play(Write(d)) + self.wait(1) + self.play(FadeOut(det_text),ReplacementTransform(hessian_surface,g_surface)) + self.wait(1) + self.add_fixed_in_frame_mobjects(g_text) + self.wait(1) + self.play(FadeOut(g_text),FadeOut(g_surface),FadeOut(axes),FadeOut(label_x),FadeOut(label_y),FadeOut(d)) + +class SaddlePoint(ThreeDScene): + def construct(self): + + 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 + + h_text = TextMobject("Case 3: $\\frac{\\partial^2 f}{\\partial x^2}$ and $\\frac{\\partial^2 f}{\\partial y^2}$ have opposite signs").scale(1) + + #---- determiniant of Hessian Matrix + hessian_surface = ParametricSurface( + lambda u, v: np.array([ + u, + v, + m.exp(0.5*u**2-0.5*v**2) + ]),u_min = -1.2, u_max = 1.2, v_min = -2.5, v_max = 2.5).set_color(TEAL).shift([0,0,-1]).scale(1).fade(0.2) + + det_text= TextMobject("$det \\hspace{1mm} H = (\\frac{\\partial^2 f}{\\partial x^2})(\\frac{\\partial^2 f}{\\partial y^2})-(\\frac{\\partial^2 f}{\\partial x \\partial y})^2 $").to_corner(UL).scale(0.7) + + #---- function p(x,y) + p_surface = ParametricSurface( + lambda u, v: np.array([ + u, + v, + u**2-v**2 + ]),u_min = -1, u_max = 1, v_min = -1, v_max =1).set_color(TEAL).shift([0,0,0]).scale(2) + + p_text= TextMobject("surface of the function").to_corner(UL).scale(0.8) + + d = Dot(color = "#800000").shift([0,0,0]) #---- critical point + + self.set_camera_orientation(phi = 80*DEGREES, theta = 60*DEGREES) + self.add_fixed_in_frame_mobjects(h_text) + self.wait(1) + self.play(FadeOut(h_text)) + self.wait(1) + self.add(axes) + self.add(label_x) + self.add(label_y) + self.wait(1) + self.play(Write(hessian_surface)) + self.play(Write(d)) + self.wait(1) + self.add_fixed_in_frame_mobjects(det_text) + self.wait(2) + self.play(FadeOut(det_text),ReplacementTransform(hessian_surface,p_surface)) + self.add_fixed_in_frame_mobjects(p_text) + self.wait(2) diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/file3_Degenerate_Hessian_Matrix.gif b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/file3_Degenerate_Hessian_Matrix.gif Binary files differnew file mode 100644 index 0000000..36fd25c --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/file3_Degenerate_Hessian_Matrix.gif diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/file3_Degenerate_Hessian_Matrix.py b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/file3_Degenerate_Hessian_Matrix.py new file mode 100644 index 0000000..732ef4f --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/file3_Degenerate_Hessian_Matrix.py @@ -0,0 +1,56 @@ +from manimlib.imports import* +import math as m + +class DegenerateHessian(ThreeDScene): + def construct(self): + + heading = TextMobject("Degenerate Hessian Matrix",color = BLUE) + + h_text = TextMobject("For $det \\hspace{1mm} H = 0$, the surface of the function at the critical point would be flat.").scale(0.7) + + 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 + + #---- function f(x,y) + f_surface = ParametricSurface( + lambda u, v: np.array([ + u, + v, + -4*u**3-v**3 + ]),u_min = -0.8, u_max = 0.8, v_min = -0.8, v_max = 0.8).set_color(TEAL).shift([0,1,0]).scale(1.3) + + #---- function f(x,y) + zoom_surface = ParametricSurface( + lambda u, v: np.array([ + u, + v, + -4*u**3-v**3 + ]),u_min = -0.8, u_max = 0.8, v_min = -0.8, v_max = 0.8).set_color(TEAL).shift([0,1,0]).scale(2.5) + + f_text= TextMobject("surface of the function").to_corner(UL).scale(0.5) + + d = Dot(color = "#800000").shift([0,1,0]) #---- critical point + d2 = Dot(color = "#800000").shift([0,0.7,0]) #---- critical point + plane = Rectangle(color = YELLOW,fill_opacity= 0.3).shift([0,0.6,0]).rotate(m.radians(90)).scale(0.4) + + self.set_camera_orientation(phi = 70*DEGREES, theta = 45*DEGREES) + self.add_fixed_in_frame_mobjects(heading) + self.wait(1) + self.play(FadeOut(heading)) + self.add_fixed_in_frame_mobjects(h_text) + self.wait(2) + self.play(FadeOut(h_text)) + self.wait(1) + self.add(axes) + self.add(label_x) + self.add(label_y) + self.play(Write(f_surface)) + self.add_fixed_in_frame_mobjects(f_text) + self.wait(1) + self.play(Write(d)) + self.wait(1) + self.play(ReplacementTransform(f_surface,zoom_surface),ReplacementTransform(d,d2)) + self.wait(2) + self.play(Write(plane)) + self.wait(1) diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/file3_Nondegenerate_Hessian_Matrix.gif b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/file3_Nondegenerate_Hessian_Matrix.gif Binary files differdeleted file mode 100644 index 2b0acb3..0000000 --- a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/file3_Nondegenerate_Hessian_Matrix.gif +++ /dev/null diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/file3_Nondegenerate_Hessian_Matrix.py b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/file3_Nondegenerate_Hessian_Matrix.py deleted file mode 100644 index 3056842..0000000 --- a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/The-Second-Derivative-Test/file3_Nondegenerate_Hessian_Matrix.py +++ /dev/null @@ -1,145 +0,0 @@ -from manimlib.imports import* - -class firstScene(Scene): - def construct(self): - - e_text = TextMobject("Case 3: One positive and one negative eigenvalue", color = YELLOW).scale(1).shift(3*UP+1*LEFT) - f_text = TextMobject("$f(x,y) = x^2-2y^2-2x$").scale(0.8).next_to(e_text).shift(6*LEFT+DOWN) - c_text = TextMobject("Critical Point: $(1,0)$").scale(0.8).next_to(f_text).shift(DOWN+4*LEFT) - d_text = TextMobject("\\begin{equation*} D_2(1,0)= \\begin{vmatrix} 2 \\space & 0\\space \\\\ 0 & -4 \\end{vmatrix} \\end{equation*}",color = GREEN).scale(0.9) - - t_text = TextMobject("$D_2 = -8<0$ (Saddle Point)", color = BLUE).scale(0.9).shift(2*DOWN) - - self.play(ShowCreation(e_text)) - self.wait(1) - self.play(ShowCreation(f_text)) - self.wait(1) - self.play(ShowCreation(c_text)) - self.wait(1) - self.play(ShowCreation(d_text)) - self.wait(1) - self.play(ShowCreation(t_text)) - self.wait(2) - -class SaddlePoint(ThreeDScene): - def construct(self): - axes = ThreeDAxes() - f = ParametricSurface( - lambda u, v: np.array([ - u, - v, - u**2-2*v**2-2*u - ]),v_min=-1,v_max=1,u_min=-1,u_max=1,checkerboard_colors=[RED_C,PURPLE_D,YELLOW_E], - resolution=(20, 20)).scale(1) - - self.set_camera_orientation(phi=35 * DEGREES,theta=80*DEGREES) - self.begin_ambient_camera_rotation(rate=0.4) - - f_text = TextMobject("$f(x,y) = x^2-2y^2-2x$",color = GREEN).shift(2*DOWN+2*RIGHT).scale(0.8) - self.add_fixed_in_frame_mobjects(f_text) - self.add(axes) - self.play(Write(f)) - self.wait(3) - - -class secondScene(Scene): - def construct(self): - - h_text = TextMobject("NonDegenerate Hessian Matrix", color = GREEN).scale(1).shift(UP) - e_text = TextMobject("Case 1: Two positive eigenvalues", color = PINK).scale(1).shift(3*UP+2*LEFT) - f_text = TextMobject("$f(x,y) = 2x^2+3y^2-2yx$",color = TEAL).scale(0.8).next_to(e_text).shift(6*LEFT+DOWN) - c_text = TextMobject("Critical Point: $(0,0)$",color = TEAL).scale(0.8).next_to(f_text).shift(DOWN+4.5*LEFT) - d_text = TextMobject("\\begin{equation*} D_2(0,0)= \\begin{vmatrix} 4 \\space & -2\\space \\\\ -2 & 6 \\end{vmatrix} \\end{equation*}",color = PINK).scale(0.9) - - t_text = TextMobject("$D_2 = 20>0$ (Relative Maxima or Relative Minima)", color = YELLOW).scale(0.9).shift(1*DOWN) - tm_text = TextMobject("$D_1 = \\frac{\\partial^2 f}{\\partial x^2} =4 >0$ (Relative Minima)", color = YELLOW).scale(0.9).shift(2*DOWN) - - - self.play(ShowCreation(h_text)) - self.wait(1) - self.play(FadeOut(h_text)) - self.wait(1) - self.play(ShowCreation(e_text)) - self.wait(1) - self.play(ShowCreation(f_text)) - self.wait(1) - self.play(ShowCreation(c_text)) - self.wait(1) - self.play(ShowCreation(d_text)) - self.wait(1) - self.play(ShowCreation(t_text)) - self.wait(1) - self.play(ShowCreation(tm_text)) - self.wait(2) - self.play(FadeOut(e_text),FadeOut(f_text),FadeOut(c_text),FadeOut(d_text),FadeOut(t_text),FadeOut(tm_text)) - -class Minima(ThreeDScene): - def construct(self): - axes = ThreeDAxes() - f = ParametricSurface( - lambda u, v: np.array([ - u, - v, - 2*u**2+3*v**2-2*v*u - ]),v_min=-1,v_max=1,u_min=-1,u_max=1,checkerboard_colors=[BLUE_C,YELLOW_D,GREEN_E], - resolution=(20, 20)).scale(1) - - self.set_camera_orientation(phi=10 * DEGREES,theta=90*DEGREES) - self.begin_ambient_camera_rotation(rate=0.2) - - f_text = TextMobject("$f(x,y) = 2x^2+3y^2-2yx$",color = PURPLE).shift(2*DOWN+3*RIGHT).scale(0.8) - self.add_fixed_in_frame_mobjects(f_text) - self.add(axes) - self.play(Write(f)) - self.wait(2) - - -class thirdScene(Scene): - def construct(self): - - - e_text = TextMobject("Case 2: Two negative eigenvalues", color = RED).scale(1).shift(3*UP+2*LEFT) - f_text = TextMobject("$f(x,y) = -x^2-4y^2$",color = BLUE).scale(0.8).next_to(e_text).shift(6*LEFT+DOWN) - c_text = TextMobject("Critical Point: $(0,0)$",color = BLUE).scale(0.8).next_to(f_text).shift(DOWN+3.8*LEFT) - d_text = TextMobject("\\begin{equation*} D_2(0,0)= \\begin{vmatrix} -2 \\space & 0\\space \\\\ 0 & -8 \\end{vmatrix} \\end{equation*}",color = TEAL).scale(0.9) - - t_text = TextMobject("$D_2 = 16>0$ (Relative Maxima or Relative Minima)" ).scale(0.9).shift(1*DOWN) - tm_text = TextMobject("$D_1 = \\frac{\\partial^2 f}{\\partial x^2} =-2 <0$ (Relative Maxima)").scale(0.9).shift(2*DOWN) - - - self.play(ShowCreation(e_text)) - self.wait(1) - self.play(ShowCreation(f_text)) - self.wait(1) - self.play(ShowCreation(c_text)) - self.wait(1) - self.play(ShowCreation(d_text)) - self.wait(1) - self.play(ShowCreation(t_text)) - self.wait(1) - self.play(ShowCreation(tm_text)) - self.wait(2) - self.play(FadeOut(e_text),FadeOut(f_text),FadeOut(c_text),FadeOut(d_text),FadeOut(t_text),FadeOut(tm_text)) - - -class Maxima(ThreeDScene): - def construct(self): - axes = ThreeDAxes() - f = ParametricSurface( - lambda u, v: np.array([ - u, - v, - -u**2-4*v**2 - ]),v_min=-1,v_max=1,u_min=-1,u_max=1,checkerboard_colors=[BLUE_C,PURPLE_D,TEAL_E], - resolution=(20, 20)).scale(1) - - self.set_camera_orientation(phi=75 * DEGREES) - self.begin_ambient_camera_rotation(rate=0.4) - - f_text = TextMobject("$f(x,y) = -x^2-4y^2$",color = YELLOW).shift(2*DOWN+3*RIGHT).scale(0.8) - self.add_fixed_in_frame_mobjects(f_text) - self.add(axes) - self.play(Write(f)) - self.wait(1) - self.move_camera(phi=30*DEGREES,theta=45*DEGREES,run_time=5) - self.wait(2) |