diff options
Diffstat (limited to 'FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers')
9 files changed, 284 insertions, 0 deletions
diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/README.md b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/README.md new file mode 100644 index 0000000..903eaed --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/README.md @@ -0,0 +1,26 @@ +<h1><div align=”center”><b>SubTopic: Lagrange Multipliers</b></h1></div> +<br/></br> + +<tab>file1_Extrema_over_g(x,y) + +![file1_Extrema_over_g(x,y)](https://github.com/vnb09/FSF-mathematics-python-code-archive/blob/fsf_tasks/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file1_Extrema_over_g(x%2Cy)%3Dk.gif?raw=true) +<br/></br> +<br/></br> + +<tab>file2_Constraint_circle_with_contour_plot_of_the_surface_x^2+y^2+x^3-y^3 + +![file2_Constraint_circle_with_contour_plot_of_the_surface_x^2+y^2+x^3-y^3](https://github.com/vnb09/FSF-mathematics-python-code-archive/blob/fsf_tasks/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file2_Constraint_circle_with_contour_plot_of_the_surface_x%5E2%2By%5E2%2Bx%5E3-y%5E3.gif?raw=true) +<br/></br> +<br/></br> + +<tab>file3_Geometric_Proof + +![file3_Geometric_Proof](https://github.com/vnb09/FSF-mathematics-python-code-archive/blob/fsf_tasks/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file3_Geometric_Proof.gif?raw=true) +<br/></br> +<br/></br> + +<tab>file4_Constraints_g_and_h + +![file4_Constraints_g_and_h](https://github.com/vnb09/FSF-mathematics-python-code-archive/blob/fsf_tasks/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file4_Constraints_g_and_h.gif?raw=true) +<br/></br> +<br/></br> diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file1_Extrema_over_g(x,y)=k.gif b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file1_Extrema_over_g(x,y)=k.gif Binary files differnew file mode 100644 index 0000000..9a9042f --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file1_Extrema_over_g(x,y)=k.gif diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file1_Extrema_over_g(x,y)=k.py b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file1_Extrema_over_g(x,y)=k.py new file mode 100644 index 0000000..b7adcc7 --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file1_Extrema_over_g(x,y)=k.py @@ -0,0 +1,45 @@ +from manimlib.imports import* +import math as m + +#---- optimizing funtion f(x,y) w.r.t to g(x,y) +class ConstrainedExtrema(ThreeDScene): + def construct(self): + axes = ThreeDAxes().scale(0.7).rotate(math.radians(180)) + label_x = TextMobject("$x$").shift(4*LEFT).fade(0.4) #---- x axis + label_y = TextMobject("$y$").shift(3.2*DOWN+0.2*RIGHT).rotate(math.radians(180)).fade(0.4) #---- y axis + + surface = ParametricSurface( + lambda u, v: np.array([ + u, + v, + u**2+v**2+u**3-v**3 + ]),u_min=-0.5,u_max=0.5, v_min=-0.5,v_max=0.5).scale(5).shift([0,1,2.5]).set_color(TEAL).fade(0.2) + + c = Circle(color='#FF00FF',fill_opacity=0.3).shift([-0.4,0,1.5]).rotate(1.9,UP).scale(0.7) + + minima = Dot(color = '#4169E1').shift([-0.5,0.5,1]).rotate(1.571,UP) + maxima = Dot(color = '#4169E1').shift([0.1,0,2.2]).rotate(1.571,UP) + + max_text = TextMobject("maximum over $g(x,y)=k$",color = '#FFA074').scale(0.6).shift(2.3*UP+2*LEFT) + min_text = TextMobject("minimum over $g(x,y)=k$",color = '#FFA074').shift([2.5,0.5,1]).scale(0.6).shift(0.5*UP) + label_f = TextMobject("$z=f(x,y)$",color=TEAL).scale(0.8).shift(3*UP+3*RIGHT) + label_g = TextMobject("g(x,y)=k",color = PURPLE).scale(0.5).shift(1.5*UP+0.8*LEFT) + + + self.add(axes) + self.add(label_x) + self.add(label_y) + self.set_camera_orientation(phi=75*DEGREES,theta=45*DEGREES) + self.play(Write(surface)) + self.add_fixed_in_frame_mobjects(label_f) + self.wait(2) + self.play(Write(c)) + self.wait(1) + self.add_fixed_in_frame_mobjects(label_g) + self.wait(1) + self.play(Write(maxima)) + self.add_fixed_in_frame_mobjects(max_text) + self.wait(1) + self.play(Write(minima)) + self.add_fixed_in_frame_mobjects(min_text) + self.wait(1) diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file2_Constraint_circle_with_contour_plot_of_the_surface_x^2+y^2+x^3-y^3.gif b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file2_Constraint_circle_with_contour_plot_of_the_surface_x^2+y^2+x^3-y^3.gif Binary files differnew file mode 100644 index 0000000..d8e03fd --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file2_Constraint_circle_with_contour_plot_of_the_surface_x^2+y^2+x^3-y^3.gif diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file2_Constraint_circle_with_contour_plot_of_the_surface_x^2+y^2+x^3-y^3.py b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file2_Constraint_circle_with_contour_plot_of_the_surface_x^2+y^2+x^3-y^3.py new file mode 100644 index 0000000..bbbf238 --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file2_Constraint_circle_with_contour_plot_of_the_surface_x^2+y^2+x^3-y^3.py @@ -0,0 +1,72 @@ +from manimlib.imports import* +import math as m + +#---- contour plot of the surface with constraint circle +class ContourScene(ThreeDScene): + def construct(self): + axes = ThreeDAxes().scale(0.7).rotate(m.radians(180)).fade(0.6) + label_x = TextMobject("$x$").shift(4*LEFT).fade(0.4) #---- x axis + label_y = TextMobject("$y$").shift(3.2*DOWN+0.2*RIGHT).rotate(m.radians(180)).fade(0.4) #---- y axis + + #---- surface of the function f(x,y) = x^2+y^2+x^3-y^3 + surface = ParametricSurface( + lambda u, v: np.array([ + u, + v, + u**2+v**2+u**3-v**3 + ]),u_min=-0.5,u_max=0.5, v_min=-0.5,v_max=0.5).scale(5).shift([0,-0.5,2.5]).set_color(TEAL).fade(0.5) + + + #---- contour plots of the surface of the function + + c0 = Circle(color = '#800000').scale(0.5).shift([0,-0.5,0]) + c1 = Circle(color = '#800000').scale(1).shift([0,-0.5,0]) + c2 = Circle(color = '#800000').scale(1.5).shift([0,-0.5,0]) + c3 = Circle(color = '#800000').scale(2).shift([0,-0.5,0]) + c4 = Circle(color = '#800000').scale(2.5).shift([0,-0.5,0]) + + #---- constraint circle + circle = Circle(color='#FF00FF',fill_opacity=0.3).shift([-0.5,-1.2,1.5]).rotate(1.9,UP).scale(0.8) + circle2 = Circle(color='#FF00FF',fill_opacity=0.3).shift([0.74,0.95,1.5]).rotate(1.9,UP).scale(0.8) + + maxima = Dot(color = '#4169E1').shift([0.7,0.15,1.5]) #---- point of maxima + minima = Dot(color = '#4169E1').shift([0.8,1.7,1.5]) #---- point of minima + + min_text = TextMobject("minimum over $g(x,y)=k$",color = '#FFA074').scale(0.6).shift([-2,0.16,1.5]) + max_text = TextMobject("maximum over $g(x,y)=k$",color = '#FFA074').shift([-2.3,-2.6,1.5]).scale(0.6).shift(0.5*UP) + + + #---- labelling contour curves + label_c0 = TextMobject("1",color = '#FFA074').shift([0.2,0.1,0.5]).scale(0.5) + label_c1 = TextMobject("2",color = '#FFA074').shift([0.2,-0.6,0.5]).scale(0.5) + label_c2 = TextMobject("3",color = '#FFA074').shift([0.2,-1.1,0.5]).scale(0.5) + label_c3 = TextMobject("4",color = '#FFA074').shift([0.2,-1.6,0.5]).scale(0.5) + label_c4 = TextMobject("5",color = '#FFA074').shift([0.2,-2.1,0.5]).scale(0.5) + + + self.set_camera_orientation(phi=75 * DEGREES, theta = 45*DEGREES) + self.add(axes) + self.add(label_x) + self.add(label_y) + self.wait(1) + self.play(Write(surface)) + self.play(Write(circle)) + self.wait(1) + self.play(FadeOut(circle)) + self.wait(1) + self.move_camera(phi=0 * DEGREES, theta = 90*DEGREES) + self.wait(1) + self.play(Write(c0),Write(c1),Write(c2),Write(c3),Write(c4)) + self.play(FadeOut(surface)) + self.add_fixed_in_frame_mobjects(label_c0) + self.add_fixed_in_frame_mobjects(label_c1) + self.add_fixed_in_frame_mobjects(label_c2) + self.add_fixed_in_frame_mobjects(label_c3) + self.add_fixed_in_frame_mobjects(label_c4) + self.wait(1) + self.play(Write(circle2)) + self.wait(1) + self.play(Write(minima),Write(maxima)) + self.add_fixed_in_frame_mobjects(max_text) + self.add_fixed_in_frame_mobjects(min_text) + self.wait(1) diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file3_Geometric_Proof.gif b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file3_Geometric_Proof.gif Binary files differnew file mode 100644 index 0000000..e028a81 --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file3_Geometric_Proof.gif diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file3_Geometric_Proof.py b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file3_Geometric_Proof.py new file mode 100644 index 0000000..2c1d668 --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file3_Geometric_Proof.py @@ -0,0 +1,89 @@ +from manimlib.imports import* + +#---- visualization of geometric proof of Lagrange multiplier +class firstScene(ThreeDScene): + def construct(self): + axes = ThreeDAxes().scale(0.7).rotate(math.radians(180)) + label_x = TextMobject("$x$").shift(4*RIGHT).fade(0.4) #---- x axis + label_y = TextMobject("$y$").shift(3.2*DOWN+0.2*RIGHT).rotate(math.radians(180)).fade(0.4) #---- y axis + + surface = ParametricSurface( + lambda u, v: np.array([ + 1*np.sin(u)*np.cos(v), + 1*np.sin(u)*np.sin(v), + -1*np.sin(u)*np.sin(u)+2 + ]),u_min=0,u_max=PI/2,v_min=0,v_max=2*PI).set_color(GREEN).scale(1).shift([-1.5,-1.5,0]) + + d = Dot([-2,-2.55,0],color = '#800000') + a_df = Arrow(color = '#00FFFF').rotate(-2).shift(3.2*DOWN+2.3*LEFT) #---- f parallel to g + a_dg = Arrow(color = '#FF00FF').scale(0.8).shift(3.2*DOWN+2.3*LEFT).rotate(-2) #---- f parallel to g + + b_dg = Arrow(color = '#00FFFF').rotate(1.1).shift(0.82*LEFT+0.15*UP) #---- f parallel to g + b_df = Arrow(color = '#FF00FF').scale(0.6).rotate(-2).shift(1.43*LEFT+1.1*DOWN) #---- f parallel to g + + + qd = Dot(color = '#800000').shift(1.2*LEFT+0.6*DOWN) + + l1 = Line([-1,-3.1,0],[-4,-3.1,0],color = PINK).rotate(-0.3).fade(0.6) + l2 = Line([-0.9,-2.9,0],[-4,-2.9,0],color = PINK).rotate(-0.3).fade(0.6) + l3= Line([-0.8,-2.7,0],[-4,-2.7,0],color = PINK).rotate(-0.3).fade(0.6) + l4= Line([-0.7,-2.45,0],[-4,-2.45,0],color = PINK).rotate(-0.3).fade(0.6) + l5= Line([-0.6,-2.2,0],[-4,-2.25,0],color = PINK).rotate(-0.3).fade(0.6) + l6 = Line([-0.5,-2,0],[-4,-2,0],color = PINK).rotate(-0.3).fade(0.6) + l7 = Line([-0.4,-1.8,0],[-4,-1.8,0],color = PINK).rotate(-0.3).fade(0.6) + l8 = Line([-0.3,-1.6,0],[-4,-1.6,0],color = PINK).rotate(-0.3).fade(0.6) + l9= Line([-0.2,-1.4,0],[-4,-1.4,0],color = PINK).rotate(-0.3).fade(0.6) + l10= Line([-0.1,-1.2,0],[-4,-1.2,0],color = PINK).rotate(-0.3).fade(0.6) + l11 = Line([-0,-1,0],[-4,-1,0],color = PINK).rotate(-0.3).fade(0.6) + l12 = Line([-0,-0.8,0],[-4,-0.8,0],color = PINK).rotate(-0.3).fade(0.6) + l13= Line([-0,-0.55,0],[-4,-0.55,0],color = PINK).rotate(-0.3).fade(0.6) + l14= Line([-0,-0.35,0],[-4,-0.35,0],color = PINK).rotate(-0.3).fade(0.6) + l15= Line([-0.,-0.15,0],[-4,-0.15,0],color = PINK).rotate(-0.3).fade(0.6) + + rel_text = TextMobject("$\\nabla f = \\lambda \\nabla g$",color = TEAL).shift([3,3.2,0]).scale(0.5) + + f_text = TextMobject("$\\nabla f$",color = '#800000').shift([1,1,0]).scale(0.5) + g_text = TextMobject("$\\nabla g$").shift([1.2,-0.8,0]).scale(0.5) + + p_text= TextMobject("$P$").shift([1.8,2.6,0]).scale(0.5) + + l1_text = TextMobject("$w=$ 17").rotate(math.radians(180)).scale(0.4).shift(2.7*DOWN+4.36*LEFT) + l2_text = TextMobject("$w=$ 16").rotate(math.radians(180)).scale(0.4).shift(2.46*DOWN+4.36*LEFT) + l3_text = TextMobject("$w=$ 15").rotate(math.radians(180)).scale(0.4).shift(2.2*DOWN+4.36*LEFT) + l4_text = TextMobject("$w=$ 14").rotate(math.radians(180)).scale(0.4).shift(1.97*DOWN+4.36*LEFT) + l5_text = TextMobject("$w=$ 13").rotate(math.radians(180)).scale(0.4).shift(1.74*DOWN+4.36*LEFT) + l6_text = TextMobject("$w=$ 12").rotate(math.radians(180)).scale(0.4).shift(1.5*DOWN+4.36*LEFT) + l7_text = TextMobject("$w=$ 11").rotate(math.radians(180)).scale(0.4).shift(1.26*DOWN+4.36*LEFT) + l8_text = TextMobject("$w=$ 10").rotate(math.radians(180)).scale(0.4).shift(1.05*DOWN+4.36*LEFT) + l9_text = TextMobject("$w=$ 9").rotate(math.radians(180)).scale(0.4).shift(0.8*DOWN+4.32*LEFT) + l10_text = TextMobject("$w=$ 8").rotate(math.radians(180)).scale(0.4).shift(0.6*DOWN+4.32*LEFT) + l11_text = TextMobject("$w=$ 7").rotate(math.radians(180)).scale(0.4).shift(0.4*DOWN+4.32*LEFT) + l12_text = TextMobject("$w=$ 6").rotate(math.radians(180)).scale(0.4).shift(0.2*DOWN+4.32*LEFT) + l13_text = TextMobject("$w=$ 5").rotate(math.radians(180)).scale(0.4).shift(-0.02*DOWN+4.32*LEFT) + l14_text = TextMobject("$w=$ 4").rotate(math.radians(180)).scale(0.4).shift(-0.23*DOWN+4.32*LEFT) + l15_text = TextMobject("$w=$ 3").rotate(math.radians(180)).scale(0.4).shift(-0.44*DOWN+4.32*LEFT) + + level_Curve = VGroup(l1,l1_text,l2,l2_text,l3,l3_text,l4,l4_text,l5,l5_text,l6,l6_text,l7,l7_text,l8,l8_text,l9,l9_text,l10,l10_text,l11,l11_text,l12,l12_text,l13,l13_text,l14,l14_text,l15,l15_text) + + self.set_camera_orientation(phi=0 * DEGREES, theta = 90*DEGREES) + self.add(axes) + self.add(label_x) + self.add(label_y) + self.wait(1) + self.add(surface) + self.wait(1) + self.play(ShowCreation(level_Curve)) + self.wait(1) + self.play(ShowCreation(a_df),ShowCreation(a_dg),Write(d)) + self.wait(1) + self.add_fixed_in_frame_mobjects(rel_text) + self.add_fixed_in_frame_mobjects(p_text) + self.wait(1) + self.play(Write(qd)) + self.wait(1) + self.play(ShowCreation(b_df)) + self.add_fixed_in_frame_mobjects(f_text) + self.wait(1) + self.play(ShowCreation(b_dg)) + self.add_fixed_in_frame_mobjects(g_text) + self.wait(1) diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file4_Constraints_g_and_h.gif b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file4_Constraints_g_and_h.gif Binary files differnew file mode 100644 index 0000000..f1f7974 --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file4_Constraints_g_and_h.gif diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file4_Constraints_g_and_h.py b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file4_Constraints_g_and_h.py new file mode 100644 index 0000000..a1396fc --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file4_Constraints_g_and_h.py @@ -0,0 +1,52 @@ +from manimlib.imports import* +import math as m + + class Constraints(ThreeDScene): + def construct(self): + axes = ThreeDAxes().rotate(m.radians(75)) + label_x = TextMobject("$x$").shift([-5.5,1,0]).fade(0.4) #---- x axis + label_y = TextMobject("$y$").shift([1,5.5,0]).rotate(-4.5).fade(0.4) #---- y axis + + cylinder = ParametricSurface( + lambda u, v: np.array([ + np.cos(TAU * u), + np.sin(TAU * u), + 2 * (1-1.5*v) + ]),checkerboard_colors=[YELLOW_C,YELLOW_D,YELLOW_E]).shift([0.5,0.5,-0.13]).scale(1) + + plane = ParametricSurface( + lambda u, v: np.array([ + u, + v, + u+v + ]),checkerboard_colors=[TEAL_C,TEAL_D,TEAL_E]).shift([0,0,0]).rotate(m.radians(-40),RIGHT).scale(4).fade(0.3) + + c = Circle(color='#FF00FF',fill_opacity=0.3).shift([0.7,-1.3,0.4]).rotate(2.5,UP).scale(1.32) + + f_text = TextMobject("$f(x,y)=x^2+y^2+z^2$",color = '#FFA074').scale(0.6).to_corner(UL) + g_text = TextMobject("$g(x,y)=x^2+y^2+1$",color = '#FFA074').scale(0.6).to_corner(UL) + h_text = TextMobject("$h(x,y)=x+y-z=1$",color = '#FFA074').scale(0.6).to_corner(UL) + + + + self.set_camera_orientation(phi=65*DEGREES,theta=95*DEGREES) + + self.add(axes) + self.add(label_x) + self.add(label_y) + self.wait(1) + self.add_fixed_in_frame_mobjects(f_text) + self.play(Write(c)) + self.wait(1) + self.play(FadeOut(f_text)) + self.wait(1) + self.add_fixed_in_frame_mobjects(g_text) + self.play(Write(cylinder)) + self.wait(1) + self.play(FadeOut(g_text)) + self.wait(1) + self.add_fixed_in_frame_mobjects(h_text) + self.play(Write(plane)) + self.wait(1) + self.play(FadeOut(h_text)) + self.wait(1) |