diff options
Diffstat (limited to 'FSF-2020/calculus-of-several-variables')
8 files changed, 365 insertions, 30 deletions
diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/fundamental-theorem-of-line-integral/file1_grad_of_scalar_function.gif b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/fundamental-theorem-of-line-integral/file1_grad_of_scalar_function.gif Binary files differindex 5a6e102..1fd2e15 100644 --- a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/fundamental-theorem-of-line-integral/file1_grad_of_scalar_function.gif +++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/fundamental-theorem-of-line-integral/file1_grad_of_scalar_function.gif diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/fundamental-theorem-of-line-integral/file1_grad_of_scalar_function.py b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/fundamental-theorem-of-line-integral/file1_grad_of_scalar_function.py index c9f479c..fd3d9b5 100644 --- a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/fundamental-theorem-of-line-integral/file1_grad_of_scalar_function.py +++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/fundamental-theorem-of-line-integral/file1_grad_of_scalar_function.py @@ -1,6 +1,6 @@ from manimlib.imports import * -class GradOfScalar(ThreeDScene): +class GradOfScalarFunc(ThreeDScene): CONFIG = { "axes_config": { @@ -27,7 +27,7 @@ class GradOfScalar(ThreeDScene): "num_axis_pieces": 1, }, "default_graph_style": { - "stroke_width": 2, + "stroke_width": 5, "stroke_color": WHITE, }, "default_vector_field_config": { @@ -38,8 +38,8 @@ class GradOfScalar(ThreeDScene): "y_min": -3, "y_max": 3, "min_magnitude": 0, - "max_magnitude": 2, - "colors": [TEAL,GREEN,GREEN,GREEN,YELLOW,RED], + "max_magnitude": 3, + "colors": [TEAL,GREEN,YELLOW,RED], "length_func": lambda norm : norm*np.exp(-.38*norm)/2, "opacity": 1.0, "vector_config": { @@ -49,9 +49,9 @@ class GradOfScalar(ThreeDScene): "default_surface_config": { "fill_opacity": 0.5, "checkerboard_colors": [BLUE_E], - "stroke_width": .5, + "stroke_width": .2, "stroke_color": WHITE, - "stroke_opacity": 0.75, + "stroke_opacity": 0.5, }, } @@ -66,17 +66,24 @@ class GradOfScalar(ThreeDScene): theta=-135 * DEGREES, ) - scalar_fn_text=TexMobject("f(x,y,z)=","xy").set_color(BLUE) + scalar_fn_text=TexMobject("f(x,y)=","xy").set_color(BLUE) scalar_fn_text.to_corner(UR,buff=.6) operator=TexMobject("\\vec\\nabla").next_to( scalar_fn_text,LEFT,buff=.2 ).set_color(GOLD) - grad_text=TexMobject(r"\dfrac{\partial f}{\partial x} \hat i+\dfrac{\partial f}{\partial y} \hat j+\dfrac{\partial f}{\partial z} \hat k").set_color(GOLD) + + grad_text=TexMobject(r"\dfrac{\partial f}{\partial x} \hat i+\dfrac{\partial f}{\partial y} \hat j").set_color(GOLD) grad_text.next_to(scalar_fn_text,DOWN).scale(.9) - VGroup(grad_text[0][1],grad_text[0][9],grad_text[0][17]).set_color(BLUE) - VGroup(grad_text[0][5:8],grad_text[0][13:16],grad_text[0][21:23]).set_color(WHITE) + VGroup( + grad_text[0][1], + grad_text[0][9] + ).set_color(BLUE) + VGroup( + grad_text[0][5:8], + grad_text[0][13:16] + ).set_color(WHITE) vector_field_text=TexMobject("\\vec F=y\hat i+x\hat j").set_color_by_gradient(*self.default_vector_field_config["colors"]) vector_field_text.next_to(scalar_fn_text,DOWN) @@ -108,30 +115,33 @@ class GradOfScalar(ThreeDScene): self.play(Write(grad_text)) self.wait(2) - self.play(FadeOut(grad_text)) - self.add_fixed_in_frame_mobjects(vector_field_text) - show_vec_field=[ + + show_vects=[ FadeIn(v_field1), - Write(vector_field_text), ] self.begin_ambient_camera_rotation(rate=.2) self.move_camera( # distance=20, phi=60 * DEGREES, - added_anims=show_vec_field, + added_anims=show_vects, run_time=4.5 ) - + + self.play(FadeOut(grad_text)) self.wait(2) self.stop_ambient_camera_rotation() - fadeout= [FadeOut(s_field1)] + self.add_fixed_in_frame_mobjects(vector_field_text) + vector_field= [ + FadeOut(s_field1), + Write(vector_field_text), + ] self.move_camera( # distance=20, phi=0 * DEGREES, theta=-90 * DEGREES, - added_anims=fadeout, + added_anims=vector_field, run_time=2 ) self.wait(2) @@ -165,6 +175,7 @@ class GradOfScalar(ThreeDScene): config.update(self.default_vector_field_config) config.update(kwargs) vector_field= VectorField(func,**config) + vector_field.move_to(self.axes.c2p(0,0,0)) self.vector_field=vector_field if on_surface: @@ -175,15 +186,14 @@ class GradOfScalar(ThreeDScene): def get_vectors_on_surface(self): - config = dict() - config.update(self.default_vector_field_config["vector_config"]) vectors_on_surface = VGroup(*[ - self.vector_field.get_vector(point,**config) + self.vector_field.get_vector(point) for point in self.surface_points ]) return vectors_on_surface - + + def get_surface(self, func, **kwargs): axes=self.axes @@ -305,4 +315,3 @@ class GradOfScalar(ThreeDScene): - diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/fundamental-theorem-of-line-integral/file2_line_int_independent_of_path.gif b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/fundamental-theorem-of-line-integral/file2_line_int_independent_of_path.gif Binary files differindex 29c6d02..8d375bb 100644 --- a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/fundamental-theorem-of-line-integral/file2_line_int_independent_of_path.gif +++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/fundamental-theorem-of-line-integral/file2_line_int_independent_of_path.gif diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/fundamental-theorem-of-line-integral/file2_line_int_independent_of_path.py b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/fundamental-theorem-of-line-integral/file2_line_int_independent_of_path.py index b9597b6..b8f7cfa 100644 --- a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/fundamental-theorem-of-line-integral/file2_line_int_independent_of_path.py +++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/fundamental-theorem-of-line-integral/file2_line_int_independent_of_path.py @@ -95,7 +95,7 @@ class LineIntegration(GraphScene): def get_endpoints_of_curve(self): points=[[-3,0],[2,2]] - point_labels= ["P_i","P_f"] + point_labels= ["P_f","P_i"] for point,label in zip(points,point_labels): dot=Dot(self.coords_to_point(*point)).set_color(RED) dot_label=TexMobject(label) diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file2_scalar_line_integral.gif b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file2_scalar_line_integral.gif Binary files differindex 71c97d6..f9a8f98 100644 --- a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file2_scalar_line_integral.gif +++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file2_scalar_line_integral.gif diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file2_scalar_line_integral.py b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file2_scalar_line_integral.py index 996ead1..200f768 100644 --- a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file2_scalar_line_integral.py +++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/line-integrals/file2_scalar_line_integral.py @@ -47,8 +47,8 @@ class LineIntegrationProcess(SpecialThreeDScene): axes=self.axes self.set_camera_orientation(distance=35, - phi=65 * DEGREES, - theta=-65 * DEGREES, + phi=60 * DEGREES, + theta=-60 * DEGREES, ) fn_text=TextMobject("$z=2+x^2y$").set_color(BLUE) @@ -86,7 +86,14 @@ class LineIntegrationProcess(SpecialThreeDScene): self.play(Write(area_text)) self.play(Write(self.area),run_time=2) self.play(FadeOut(VGroup(surface,fn_text))) - self.wait() + self.move_camera( + # distance=20, + phi=90 * DEGREES, + # theta=-90 * DEGREES, + # added_anims=into_graph, + run_time=2 + ) + self.wait(2) self.stop_ambient_camera_rotation() # self.get_lines() @@ -307,7 +314,8 @@ class LineIntegrationProcess(SpecialThreeDScene): line=DashedLine(start,end,color=color) return line - + +#------------------------------------------------------- #customize 3D axes def get_three_d_axes(self, include_labels=True, include_numbers=True, **kwargs): config = dict(self.axes_config) @@ -417,5 +425,3 @@ class LineIntegrationProcess(SpecialThreeDScene): #uploaded by Somnath Pandit.FSF2020_Line_Integrals - - diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/file2_grad_of_scalar_function.gif b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/file2_grad_of_scalar_function.gif Binary files differnew file mode 100644 index 0000000..c1ab66a --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/file2_grad_of_scalar_function.gif diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/file2_grad_of_scalar_function.py b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/file2_grad_of_scalar_function.py new file mode 100644 index 0000000..231b15c --- /dev/null +++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/file2_grad_of_scalar_function.py @@ -0,0 +1,320 @@ +from manimlib.imports import * + +class GradOfScalarFunc(ThreeDScene): + + CONFIG = { + "axes_config": { + "x_min": -3, + "x_max": 3, + "y_min": -3, + "y_max": 3, + "z_min": 0, + "z_max": 3, + "a":-3 ,"b": 3, "c":-3 , "d":3, + "axes_shift": ORIGIN+IN+LEFT, + "x_axis_config": { + "tick_frequency": 1, + # "include_tip": False, + }, + "y_axis_config": { + "tick_frequency": 1, + # "include_tip": False, + }, + "z_axis_config": { + "tick_frequency": 1, + # "include_tip": False, + }, + "num_axis_pieces": 1, + }, + "default_graph_style": { + "stroke_width": 2, + "stroke_color": WHITE, + }, + "default_vector_field_config": { + "delta_x": .5, + "delta_y": .5, + "x_min": -3, + "x_max": 3, + "y_min": -3, + "y_max": 3, + "min_magnitude": 0, + "max_magnitude": 2, + "colors": [BLUE,GREEN,GREEN,ORANGE,RED], + "length_func": lambda norm : .45*sigmoid(norm), + "opacity": 1.0, + "vector_config": { + "stroke_width":6 + }, + }, + "default_surface_config": { + "fill_opacity": 0.5, + "checkerboard_colors": [BLUE_D], + "stroke_width": .5, + "stroke_color": WHITE, + "stroke_opacity": 0.2, + }, + } + + + def construct(self): + + self.setup_axes() + axes=self.axes + + self.set_camera_orientation(distance=35, + phi=80 * DEGREES, + theta=-80 * DEGREES, + ) + + scalar_fn_text=TexMobject("f(x,y)=","\cos(xy)").set_color(BLUE) + scalar_fn_text.to_corner(UR,buff=.6) + + operator=TexMobject("\\vec\\nabla").next_to( + scalar_fn_text,LEFT,buff=.2 + ).set_color(GOLD) + + grad_text=TexMobject(r"\dfrac{\partial f}{\partial x} \hat i+\dfrac{\partial f}{\partial y} \hat j+\dfrac{\partial f}{\partial z} \hat k").set_color(GOLD) + grad_text.next_to(scalar_fn_text,DOWN).scale(.9) + + VGroup( + grad_text[0][1], + grad_text[0][9], + grad_text[0][17] + ).set_color(BLUE) + VGroup( + grad_text[0][5:8], + grad_text[0][13:16], + grad_text[0][21:23] + ).set_color(WHITE) + + vector_field_text=TexMobject( + r"\vec F&=-y\sin(xy)\hat i\\ &-x\sin(xy)\hat j" + ).set_color_by_gradient( + *self.default_vector_field_config["colors"] + ) + vector_field_text.next_to(scalar_fn_text,DOWN) + + + '''always generate the scalar field first''' + s_field=self.get_scalar_field( + func= lambda x ,y : np.cos(x*y/2), + dn=.25 + ) + v_field=self.get_vector_field( + lambda v: np.array([ + -(v[1]-axes.c2p(0,0,0)[1])*np.sin((v[0]-axes.c2p(0,0,0)[0])*(v[1]-axes.c2p(0,0,0)[1])), + -(v[0]-axes.c2p(0,0,0)[0])*np.sin((v[0]-axes.c2p(0,0,0)[0])*(v[1]-axes.c2p(0,0,0)[1])), + 0, + ]), + on_surface=True, + ) + + self.add_fixed_in_frame_mobjects(scalar_fn_text) + + self.begin_ambient_camera_rotation(rate=.2) + self.play(Write(s_field),run_time=2) + self.wait(4) + self.stop_ambient_camera_rotation() + + self.add_fixed_in_frame_mobjects(operator) + self.play(Write(operator),FadeOut(scalar_fn_text[1])) + self.add_fixed_in_frame_mobjects(grad_text) + self.play(Write(grad_text)) + self.wait(1.5) + + self.play(FadeOut(grad_text)) + self.add_fixed_in_frame_mobjects(vector_field_text) + show_vec_field=[ + FadeIn(v_field), + Write(vector_field_text), + ] + # self.play(*show_vec_field,run_time=.5) + self.begin_ambient_camera_rotation(rate=.2) + self.move_camera( + # distance=20, + phi=50 * DEGREES, + added_anims=show_vec_field, + run_time=3 + ) + + self.wait(5) + self.stop_ambient_camera_rotation() + + fadeout= [FadeOut(s_field)] + # self.play(*fadeout) + self.move_camera( + # distance=20, + phi=0 * DEGREES, + theta=-90 * DEGREES, + added_anims=fadeout, + run_time=2 + ) + self.wait(2) + + + + + + def get_scalar_field(self,func,dn=.5): + surface= self.get_surface( + lambda x , y: + func(x,y), + ) + + self.surface_points=self.get_points(func,dn) + return surface + + def get_points(self,func,dn): + axes=self.axes + + x_vals=np.arange(axes.a,axes.b,dn) + y_vals=np.arange(axes.c,axes.d,dn) + points=[] + for x_val in x_vals: + for y_val in y_vals: + points+=[axes.c2p(x_val,y_val,func(x_val,y_val)+.05)] + return points + + def get_vector_field(self,func,on_surface=True,**kwargs): + config = dict() + config.update(self.default_vector_field_config) + config.update(kwargs) + vector_field= VectorField(func,**config) + vector_field.move_to(self.axes.c2p(0,0,0)) + self.vector_field=vector_field + + if on_surface: + vector_field=self.get_vectors_on_surface() + + return vector_field + + + + def get_vectors_on_surface(self): + vectors_on_surface = VGroup(*[ + self.vector_field.get_vector(point) + for point in self.surface_points + ]) + + return vectors_on_surface + + + def get_surface(self, func, **kwargs): + axes=self.axes + config = { + "u_min": axes.a, + "u_max": axes.b, + "v_min": axes.c, + "v_max": axes.d, + "resolution": ( + 4*(axes.y_max - axes.y_min) // axes.y_axis.tick_frequency, + 4*(axes.x_max - axes.x_min) // axes.x_axis.tick_frequency, + ), + } + + config.update(self.default_surface_config) + config.update(kwargs) + return ParametricSurface( + lambda x,y : axes.c2p( + x, y, func(x, y) + ), + **config + ) + + +#------------------------------------------------------- + #customize 3D axes + def get_three_d_axes(self, include_labels=True, include_numbers=False, **kwargs): + config = dict(self.axes_config) + config.update(kwargs) + axes = ThreeDAxes(**config) + axes.set_stroke(width=2) + self.axes=axes + + if include_numbers: + self.add_axes_numbers(axes) + + if include_labels: + self.add_axes_labels(axes) + + # Adjust axis orientation + axes.x_axis.rotate( + -90 * DEGREES, LEFT, + about_point=axes.c2p(0, 0, 0), + ) + axes.y_axis.rotate( + 90 * DEGREES, UP, + about_point=axes.c2p(0, 0, 0), + ) + + return axes + + + def setup_axes(self): + axes = self.get_three_d_axes(include_labels=True) + axes.scale(1) + # axes.center() + axes.shift(axes.axes_shift) + + self.add(axes) + self.axes = axes + + def add_axes_numbers(self, axes): + x_axis = axes.x_axis + y_axis = axes.y_axis + tex_vals_x = [ + + ("1", axes.b), + ("-1", axes.a), + ] + tex_vals_y=[ + + ("1", axes.d) + ] + x_labels = VGroup() + y_labels = VGroup() + for tex, val in tex_vals_x: + label = TexMobject(tex) + label.scale(1) + label.next_to(x_axis.n2p(val), DOWN) + # label.rotate(180 * DEGREES) + x_labels.add(label) + x_axis.add(x_labels) + x_axis.numbers = x_labels + + for tex, val in tex_vals_y: + label = TexMobject(tex) + label.scale(1) + label.next_to(y_axis.n2p(val), LEFT) + label.rotate(90 * DEGREES) + y_labels.add(label) + + y_axis.add(y_labels) + y_axis.numbers = y_labels + + return axes + + def add_axes_labels(self, axes): + x_label = TexMobject("x") + x_label.next_to(axes.x_axis.get_end(), RIGHT) + axes.x_axis.label = x_label + + y_label = TextMobject("y") + y_label.rotate(90 * DEGREES, OUT) + y_label.next_to(axes.y_axis.get_end(), UP) + axes.y_axis.label = y_label + + z_label = TextMobject("z") + z_label.rotate(90 * DEGREES, RIGHT) + z_label.next_to(axes.z_axis.get_zenith(), LEFT) + axes.z_axis.label = z_label + for axis in axes: + axis.add(axis.label) + return axes + + + + #uploaded by Somnath Pandit. FSF2020_Vector_fields + + + |