diff options
Diffstat (limited to 'FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers')
9 files changed, 83 insertions, 64 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..05ff51d --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/README.md @@ -0,0 +1,20 @@ +<h1><div align=”center”><b>SubTopic: Lagrange Multipliers</b></h1></div> +<br/></br> + +<tab>file1_Extrema_over_g(x,y)=k + +![file1_Extrema_over_g(x,y)=k](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_Geometric_Proof + +![file2_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/file2_Geometric_Proof.gif?raw=true) +<br/></br> +<br/></br> + +<tab>file3_Constraints_g_and_h + +![file3_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/file3_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 differindex 9d64d50..d423943 100644 --- 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 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 index da17aac..a01efb0 100644 --- 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 @@ -5,33 +5,26 @@ import math as m class ConstrainedExtrema(ThreeDScene): def construct(self): axes = ThreeDAxes().fade(0.4) - label_x = TextMobject("$x$").shift([5.5,-0.5,0]).fade(0.4) #---- x axis - label_y = TextMobject("$y$").shift([-0.5,5.5,0]).rotate(-4.5).fade(0.4) #---- y axis + 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 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.4) + ]),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().set_color('#FF00FF').shift([-0.4,0,1.5]).rotate(1.9,UP).scale(0.7) + 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) + maxima = Dot(color = '#4169E1').shift([0.1,0,2.2]).rotate(1.571,UP) - l1 = DashedLine([-0.5,0.5,0.9],[-0.5,0.5,0],color = '#F08080') - l2 = DashedLine([0.1,0,2.1],[0.1,0,0],color = '#F08080') - - c2 = Circle(fill_opacity= 0.5).shift([-0.3,0.2,0]).scale(0.4) - - minima_refl = Dot(color = '#4682B4').shift([-0.5,0.5,0]).rotate(1.571,UP) - maxima_refl = Dot(color = '#4682B4').shift([0.1,0,0]).rotate(1.571,UP) - - max_text = TextMobject("maximum over $g(x,y)=k$",color = '#FFA074').shift([-1.7,0,0]).scale(0.5).shift(2.2*UP) - min_text = TextMobject("minimum over $g(x,y)=k$",color = '#FFA074').shift([2.5,0.5,1]).scale(0.5).shift(0.5*UP) - label_f = TextMobject("$z=f(x,y)$",color = '#8A2BE2').scale(0.5).shift(3*UP+3*RIGHT) - label_g = TextMobject("$g(x,y)=k$",color = '#8A2BE2').scale(0.5).shift(2*RIGHT) + 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) @@ -42,16 +35,11 @@ class ConstrainedExtrema(ThreeDScene): 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) - self.play(ShowCreation(l1),ShowCreation(l2)) - self.play(Write(c2)) - self.add_fixed_in_frame_mobjects(label_g) - self.wait(1) - self.play(Write(maxima_refl)) - self.play(Write(minima_refl)) - self.wait(1) + self.wait(1) diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file2_Geometric_Proof.gif b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file2_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/file2_Geometric_Proof.gif diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file2_Geometric_Proof.py b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file2_Geometric_Proof.py index 2c2a9de..2c1d668 100644 --- a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file2_Geometric_Proof.py +++ b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file2_Geometric_Proof.py @@ -1,7 +1,7 @@ from manimlib.imports import* #---- visualization of geometric proof of Lagrange multiplier -class GeometricProof(ThreeDScene): +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 @@ -12,19 +12,18 @@ class GeometricProof(ThreeDScene): 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,checkerboard_colors=[GREEN_C, GREEN_E]).scale(1).shift([-1.5,-1.5,0]) + ]),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 at maxima - a_dg = Arrow(color = '#FF00FF').scale(0.8).shift(3.2*DOWN+2.3*LEFT).rotate(-2) #---- g parallel to f at maxima + 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) #---- g parallel to f at minima - b_df = Arrow(color = '#FF00FF').scale(0.6).rotate(-2).shift(1.43*LEFT+1.1*DOWN) #---- f parallel to g at minima + 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) - #---- level curves 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) @@ -48,7 +47,6 @@ class GeometricProof(ThreeDScene): p_text= TextMobject("$P$").shift([1.8,2.6,0]).scale(0.5) - #---- labelling of level curves 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) @@ -70,8 +68,9 @@ class GeometricProof(ThreeDScene): self.set_camera_orientation(phi=0 * DEGREES, theta = 90*DEGREES) self.add(axes) self.add(label_x) - self.add(label_y) - self.play(Write(surface)) + self.add(label_y) + self.wait(1) + self.add(surface) self.wait(1) self.play(ShowCreation(level_Curve)) self.wait(1) diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file3_Constraints_g_and_h.gif b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file3_Constraints_g_and_h.gif Binary files differnew file mode 100644 index 0000000..0da30ad --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file3_Constraints_g_and_h.gif diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file3_Constraints_g_and_h.py b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file3_Constraints_g_and_h.py new file mode 100644 index 0000000..742d6b5 --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file3_Constraints_g_and_h.py @@ -0,0 +1,41 @@ +from manimlib.imports import* +import math as m + +class firstScene(ThreeDScene): + def construct(self): + axes = ThreeDAxes() + label_x = TextMobject("$x$").shift([5.5,-0.5,0]).fade(0.4) #---- x axis + label_y = TextMobject("$y$").shift([-0.5,5.5,0]).rotate(-4.5).fade(0.4) #---- y axis + + #---- constraint g(x,y) + cylinder = ParametricSurface( + lambda u, v: np.array([ + np.cos(TAU * u), + np.sin(TAU * u), + 2 * (v) + ]),checkerboard_colors=[YELLOW_C,YELLOW_D,YELLOW_E]).rotate(m.radians(-40),RIGHT).shift([0.5,0.5,0]).scale(0.8) + + #---- constraint h(x,y) + 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(2).fade(0.3) + + figure = VGroup(cylinder,plane).rotate(m.radians(-45),DOWN).scale(1.5) + + self.set_camera_orientation(phi=65*DEGREES,theta=45*DEGREES) + self.add(axes) + self.add(label_x) + self.add(label_y) + self.wait(1) + self.play(Write(cylinder)) + self.play(Write(plane)) + self.wait(1) + self.begin_ambient_camera_rotation(rate=0.4) + self.wait(1) + self.wait(1) + self.play(FadeOut(label_x),FadeOut(label_y)) + self.wait(1) + self.wait(1) diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file3_Optimizing_function_w.r.t_one_constraint.gif b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file3_Optimizing_function_w.r.t_one_constraint.gif Binary files differdeleted file mode 100644 index 9602283..0000000 --- a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file3_Optimizing_function_w.r.t_one_constraint.gif +++ /dev/null diff --git a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file3_Optimizing_function_w.r.t_one_constraint.py b/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file3_Optimizing_function_w.r.t_one_constraint.py deleted file mode 100644 index bf75dd8..0000000 --- a/FSF-2020/calculus-of-several-variables/approximations-and-optimizations/Lagrange-Multipliers/file3_Optimizing_function_w.r.t_one_constraint.py +++ /dev/null @@ -1,29 +0,0 @@ -from manimlib.imports import* - -class firstScene(ThreeDScene): - def construct(self): - axes = ThreeDAxes() - cylinder = ParametricSurface( - lambda u, v: np.array([ - np.cos(TAU * v), - np.sin(TAU * v), - 2 * (u) - ]),checkerboard_colors=[YELLOW_C,YELLOW_D,YELLOW_E] - ).fade(0.4) #Resolution of the surfaces - - plane = ParametricSurface( - lambda u, v: np.array([ - u, - v, - u+v - ]),checkerboard_colors=[TEAL_C,TEAL_D,TEAL_E] - ).scale(2.5) - self.add(axes) - self.set_camera_orientation(phi=75*DEGREES,theta=45*DEGREES) - self.play(Write(cylinder)) - self.play(Write(plane)) - self.wait(1) - self.begin_ambient_camera_rotation(rate=0.7) - self.wait(5) - self.move_camera(phi=35*DEGREES,theta=-45*DEGREES) - self.wait(2) |