summaryrefslogtreecommitdiff
path: root/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields
diff options
context:
space:
mode:
Diffstat (limited to 'FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields')
-rw-r--r--FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/README.md11
-rw-r--r--FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/file1_vector_fields.py350
-rw-r--r--FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/file2_grad_of_scalar_function.py320
-rw-r--r--FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/file3_constructing_vector_field.py196
-rw-r--r--FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/file4_slope_field.py247
-rw-r--r--FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/gifs/file1_vector_fields.gifbin0 -> 5384744 bytes
-rw-r--r--FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/gifs/file2_grad_of_scalar_function.gifbin0 -> 6913246 bytes
-rw-r--r--FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/gifs/file3_constructing_vector_field.gifbin0 -> 3838142 bytes
-rw-r--r--FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/gifs/file4_slope_field.gifbin0 -> 1860382 bytes
9 files changed, 1124 insertions, 0 deletions
diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/README.md b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/README.md
new file mode 100644
index 0000000..d8c0956
--- /dev/null
+++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/README.md
@@ -0,0 +1,11 @@
+**file1_vector_fields**
+![file1_vector_fields](gifs/file1_vector_fields.gif)
+
+**file2_grad_of_scalar_function**
+![file2_grad_of_scalar_function](gifs/file2_grad_of_scalar_function.gif)
+
+**file3_constructing_vector_field**
+![file3_constructing_vector_field](gifs/file3_constructing_vector_field.gif)
+
+**file4_slope_field**
+![file4_slope_field](gifs/file4_slope_field.gif)
diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/file1_vector_fields.py b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/file1_vector_fields.py
new file mode 100644
index 0000000..6b1b686
--- /dev/null
+++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/file1_vector_fields.py
@@ -0,0 +1,350 @@
+from manimlib.imports import *
+
+class VectorFields(ThreeDScene):
+
+ CONFIG = {
+ "axes_config": {
+ "x_min": -4,
+ "x_max": 4,
+ "y_min": -4,
+ "y_max": 4,
+ "z_min": -3,
+ "z_max": 3,
+ "a":-4 ,"b": 4, "c":-4 , "d":4,
+ "axes_shift": ORIGIN+2*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": 10,
+ },
+ "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": 4,
+ "colors": [BLUE,GREEN,ORANGE,RED],
+ "length_func": lambda norm : .45*sigmoid(norm),
+ "opacity": 1.0,
+ "vector_config": {
+ "stroke_width":3.5,
+ "max_tip_length_to_length_ratio": 0.35,
+ "max_stroke_width_to_length_ratio": 8,
+ },
+ },
+
+ }
+
+
+ def construct(self):
+
+ self.setup_axes()
+ axes=self.axes
+
+ self.set_camera_orientation(distance=35,
+ phi=0 * DEGREES,
+ theta=-90 * DEGREES,
+ )
+ self.move_camera(frame_center=axes.c2p(0,0,0))
+
+ self.show_2d_field()
+ self.wait(3)
+
+ self.show_3d_field()
+ self.begin_ambient_camera_rotation(rate=-.3,)
+ self.wait(1.5)
+ 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),
+ ),
+ self.move_camera(
+ # distance=20,
+ phi=85 * DEGREES,
+ rate_func=linear,
+ run_time=8
+ )
+ self.wait(5)
+
+
+ def show_2d_field(self):
+ d2_field_text=TexMobject(
+ r"\vec F(x,y)=-y\hat i+x\hat j",
+ stroke_width=1.5
+ ).set_color_by_gradient(
+ *self.default_vector_field_config["colors"]
+ )
+ d2_field_text.to_corner(UR,buff=.5)
+
+ d2_field = self.get_vector_field(
+ lambda v: np.array([
+ -v[1],
+ v[0],
+ 0
+ ]),
+ )
+ self.add_fixed_in_frame_mobjects(d2_field_text)
+ # self.add(d2_field)
+ self.play(Write(d2_field_text))
+ self.play(FadeIn(d2_field))
+
+ self.d2_field=d2_field
+ self.d2_field_text=d2_field_text
+
+ def show_3d_field(self):
+ d3_field_text=TexMobject(
+ r"\vec F(x,y,z)=-y\hat i+x\hat j+0 \hat k",
+ stroke_width=1.5
+ ).set_color_by_gradient(
+ *self.default_vector_field_config["colors"]
+ )
+ d3_field_text.to_corner(UR,buff=.5)
+
+ d3_field= self.get_vector_field(
+ lambda v: np.array([
+ -v[1],
+ v[0],
+ 0
+ # v[0]*v[2]
+ ]),
+ z_min=-2,
+ z_max= 2,
+ delta_x= 1,
+ delta_y= 1,
+ delta_z= 1,
+ length_func=lambda norm : .5*sigmoid(norm),
+ opacity= 1,
+ ThreeD=True
+ )
+
+ self.remove(self.d2_field,self.d2_field_text)
+ self.add_fixed_in_frame_mobjects(d3_field_text)
+ # self.add(d3_field)
+ self.play(Write(d3_field_text))
+ self.play(FadeIn(d3_field))
+
+ def get_vector_field(self,func,ThreeD=False,**kwargs):
+ config = dict()
+ config.update(self.default_vector_field_config)
+ config.update(kwargs)
+ if ThreeD:
+ vector_field= VectorField3D(func,**config)
+ else:
+ vector_field= VectorField(func,**config)
+
+ vector_field.move_to(self.axes.c2p(0,0,0))
+ self.vector_field=vector_field
+
+ return vector_field
+
+
+
+#-------------------------------------------------------
+ #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(
+ -0 * DEGREES, LEFT,
+ about_point=axes.c2p(0, 0, 0),
+ )
+ axes.y_axis.rotate(
+ 0 * 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),
+ ]
+ 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
+
+#-----------------------------------------------------------
+
+class VectorField3D(VGroup):
+ CONFIG = {
+ "delta_x": 1,
+ "delta_y": 1,
+ "delta_z": 1,
+ "x_min": int(np.floor(-FRAME_WIDTH / 2)),
+ "x_max": int(np.ceil(FRAME_WIDTH / 2)),
+ "y_min": int(np.floor(-FRAME_HEIGHT / 2)),
+ "y_max": int(np.ceil(FRAME_HEIGHT / 2)),
+ "z_min":-1,
+ "z_max": 1,
+ "min_magnitude": 0,
+ "max_magnitude": 4,
+ "colors": DEFAULT_SCALAR_FIELD_COLORS,
+ # Takes in actual norm, spits out displayed norm
+ "length_func": lambda norm: 0.45 * sigmoid(norm),
+ "opacity": 1.0,
+ "vector_config": {},
+ }
+ '''Position of the tip of vector to be fixed'''
+ def __init__(self, func, **kwargs):
+ VGroup.__init__(self, **kwargs)
+ self.func = func
+ self.rgb_gradient_function = get_rgb_gradient_function(
+ self.min_magnitude,
+ self.max_magnitude,
+ self.colors,
+ flip_alphas=False
+ )
+ x_range = np.arange(
+ self.x_min,
+ self.x_max + self.delta_x,
+ self.delta_x
+ )
+ y_range = np.arange(
+ self.y_min,
+ self.y_max + self.delta_y,
+ self.delta_y
+ )
+ z_range = np.arange(
+ self.z_min,
+ self.z_max + self.delta_z,
+ self.delta_z
+ )
+ for x, y, z in it.product(x_range, y_range, z_range):
+ point = x * RIGHT + y * UP + z * OUT
+ # print(point)
+ self.add(self.get_vector(point))
+ self.set_opacity(self.opacity)
+
+ def get_vector(self, point, **kwargs):
+ output = np.array(self.func(point))
+ norm = get_norm(output)
+ if norm == 0:
+ output *= 0
+ else:
+ output *= self.length_func(norm) / norm
+ # norm=np.linalg.norm(output)
+ vector_config = dict(self.vector_config)
+ vector_config.update(kwargs)
+
+ vect = Vector(
+ output,
+ **vector_config
+ )
+ vect_perp=vect.copy().rotate(PI/2, axis=output)
+ vect= VGroup(vect,vect_perp)
+ # vect= self.position_vector(vect,point,output,norm)
+ vect.shift(point)
+ fill_color = rgb_to_color(
+ self.rgb_gradient_function(np.array([norm]))[0]
+ )
+ vect.set_color(fill_color)
+ return vect
+
+ '''def position_vector(self,vect,point,output,norm):
+ theta,phi=self.get_theta_phi(output,norm)
+ vect.rotate(PI-phi, axis=RIGHT)
+ vect.rotate(theta, axis=IN)
+ # or apply rotation matrix?
+ return vect
+
+ def get_theta_phi(self,output,norm):
+ if norm==0:
+ phi,theta=0,0
+ else:
+ phi= np.arccos(output[-1]/norm)
+ if output[0]!=0:
+ theta= np.arccos(output[0]/(norm*np.sin(phi)))
+ else:
+ theta= 0
+ return phi,theta'''
+
+
+
+ #uploaded by Somnath Pandit. FSF2020_Vector_fields
+
+
+
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
+
+
+
diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/file3_constructing_vector_field.py b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/file3_constructing_vector_field.py
new file mode 100644
index 0000000..fc56306
--- /dev/null
+++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/file3_constructing_vector_field.py
@@ -0,0 +1,196 @@
+from manimlib.imports import *
+
+
+class VectorFields(GraphScene):
+ CONFIG = {
+ "x_min" : -4,
+ "x_max" : 4,
+ "y_min" : -4,
+ "y_max" : 4,
+ "graph_origin": ORIGIN+2.5*LEFT,
+ "x_axis_width": 7,
+ "y_axis_height": 7,
+ "x_tick_frequency": 1,
+ "y_tick_frequency": 1,
+ "default_vector_field_config": {
+ "delta_x": .5,
+ "delta_y": .5,
+ "min_magnitude": 0,
+ "max_magnitude": 4,
+ "colors": [GREEN,GREEN,YELLOW,RED],
+ "length_func": lambda n: n/2.5,
+ "opacity": .75,
+ "vector_config": {
+ "stroke_width":6,
+ "max_stroke_width_to_length_ratio":4
+ },
+ },
+
+ "a":-3.5 ,"b": 4, "c": -3.5 ,"d": 4,
+ }
+
+ def construct(self):
+ X = RIGHT*self.x_axis_width/(self.x_max- self.x_min)
+ Y = UP*self.y_axis_height/(self.y_max- self.y_min)
+ self.X=X ;self.Y=Y
+
+ self.setup_axes(animate=False)
+ vector_function = lambda v: np.array([
+ (v[0]-self.graph_origin[0])*(v[1]-self.graph_origin[1]),
+ -(v[0]-self.graph_origin[0]),
+ 0,
+ ])
+
+ vector_field=self.get_vector_field(
+ vector_function,
+ colors= [GREEN]
+ )
+
+ self.show_points()
+ self.wait(.5)
+ self.show_func_machine()
+ self.wait(1)
+ self.produce_vectors(vector_field)
+ self.wait(.5)
+ self.scale_down_vectors(vector_function)
+ self.wait(2)
+
+
+
+ def show_points(self):
+ dn=1
+ x_vals=np.arange(self.a,self.b,dn)
+ y_vals=np.arange(self.c,self.d,dn)
+ dots=VGroup()
+ for x_val in x_vals:
+ for y_val in y_vals:
+ dot=Dot(
+ self.coords_to_point(x_val,y_val),
+ radius=.05,
+ color=TEAL,
+ )
+ dots.add(dot)
+ self.play(ShowCreation(dots, run_time=1))
+ self.dots=dots
+
+ def show_func_machine(self):
+ machine=RoundedRectangle(
+ height=2,
+ width=3.5,
+ color=PURPLE,
+ stroke_width=8
+ ).to_edge(RIGHT, buff=.4)
+
+ machine_label=TexMobject(
+ r"\vec F=xy\hat i-x\hat j",
+ stroke_width=1.5,
+ ).set_color_by_gradient(
+ *self.default_vector_field_config["colors"]
+ ).next_to(machine,IN)
+
+ machine=VGroup(machine,machine_label)
+ self.add(machine)
+
+ self.func_machine=machine
+
+
+ def produce_vectors(self,vector_field):
+ count,i=3,0
+ self.run_time=1
+ non_scaled_vectors=VGroup()
+ for dot in self.dots:
+ if i==count:
+ self.run_time=.05
+ position=dot.get_center()
+ vect= vector_field.get_vector(position)
+ self.go_to_machine(dot)
+ self.take_vec_from_machine(vect,position)
+ non_scaled_vectors.add(vect)
+ i+=1
+
+ self.non_scaled_vectors=non_scaled_vectors
+
+ def go_to_machine(self,dot):
+ if self.run_time>.5:
+ self.play(ApplyMethod(
+ dot.next_to,
+ self.func_machine,4*UP,
+ ),
+ run_time=self.run_time
+ )
+ self.dot=dot
+
+ def take_vec_from_machine(self,vect,position):
+ vect.next_to(self.func_machine,DOWN,buff=.1)
+
+ if self.run_time>.5:
+ point_coord=TexMobject(
+ "(x_i,y_i)"
+ ).next_to(self.dot,RIGHT,buff= .01).scale(.75)
+ input_point=VGroup(point_coord, self.dot)
+ self.play(
+ ApplyMethod(
+ input_point.shift,DOWN,
+ run_time=self.run_time
+ )),
+ self.play(
+ FadeOut(input_point),
+ run_time=.2
+ )
+ self.play(
+ FadeIn(vect),
+ run_time=.4
+ )
+ else:
+ self.remove(self.dot)
+ self.add(vect)
+ self.wait(1.0/15)
+
+ self.play(
+ vect.move_to,position,
+ run_time=self.run_time
+ )
+
+ def scale_down_vectors(self,vector_function):
+ scale_down_text=TextMobject(
+ r"Vectors are rescaled\\ for clarity\\ and \\",
+ r"colors are used to \\ indicate magnitudes",
+ stroke_width=1.2
+ )
+ scale_down_text[0][:7].set_color(BLUE)
+ scale_down_text[1].set_color_by_gradient(
+ *self.default_vector_field_config["colors"]
+ )
+ scale_down_text.to_corner(UR).shift(DOWN)
+ scaled_vector_field= self.get_vector_field(
+ vector_function,
+ length_func= lambda norm : .75*sigmoid(norm)
+ )
+ for vector in self.non_scaled_vectors:
+ scaled_vect= scaled_vector_field.get_vector(vector.get_center())
+ vector.target= scaled_vect
+
+ self.play(FadeOut(self.func_machine))
+ self.play(Write(scale_down_text))
+ self.wait(1.2)
+ self.play(LaggedStartMap(
+ MoveToTarget, self.non_scaled_vectors,
+ run_time=3
+ ))
+
+ def get_vector_field(self,func,**kwargs):
+ config = dict()
+ config.update(self.default_vector_field_config)
+ config.update(kwargs)
+ vector_field= VectorField(func,**config)
+
+ return vector_field
+
+
+
+
+
+#uploaded by Somnath Pandit. FSF2020_Vector_fields
+
+
+
diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/file4_slope_field.py b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/file4_slope_field.py
new file mode 100644
index 0000000..8ebb6f5
--- /dev/null
+++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/file4_slope_field.py
@@ -0,0 +1,247 @@
+from manimlib.imports import *
+
+
+class SlopeFields(GraphScene):
+ CONFIG = {
+ "x_min" : -2,
+ "x_max" : 2,
+ "y_min" : -2,
+ "y_max" : 2,
+ "graph_origin": ORIGIN+2.5*LEFT,
+ "x_axis_width": 7,
+ "y_axis_height": 7,
+ "x_tick_frequency": 1,
+ "y_tick_frequency": 1,
+ "default_slope_field_config": {
+ "delta_x": .2,
+ "delta_y": .2,
+ "opacity": 1,
+ "color": BLUE_A,
+ "slope_length_factor": .2,
+ "line_config": {
+ "stroke_width":2.5,
+ },
+ },
+
+ "a":-1.9 ,"b": 2, "c": -1.9 ,"d": 2,
+ }
+
+ def construct(self):
+ X = RIGHT*self.x_axis_width/(self.x_max- self.x_min)
+ Y = UP*self.y_axis_height/(self.y_max- self.y_min)
+ self.X=X ;self.Y=Y
+
+ self.setup_axes(animate=False)
+
+ slope_field=self.get_slope_field(
+ lambda x,y:-2.0*(x-self.graph_origin[0])*(y-self.graph_origin[1]),
+ x_min=self.graph_origin[0]+self.a,
+ x_max=self.graph_origin[0]+self.b,
+ y_min=self.graph_origin[1]+self.c,
+ y_max=self.graph_origin[1]+self.d,
+ color= GREEN_B
+ )
+
+ self.show_points()
+ self.wait(.5)
+ self.show_func_machine()
+ self.wait(1)
+ self.produce_slopes(slope_field)
+ # self.add(slope_field)
+ self.glimpse_of_solutions()
+ self.wait(2)
+
+
+
+
+ def show_points(self):
+ dn=1.0/5
+ x_vals=np.arange(self.a,self.b,dn)
+ y_vals=np.arange(self.c,self.d,dn)
+ dots=VGroup()
+ for x_val in x_vals:
+ for y_val in y_vals:
+ dot=Dot(
+ self.coords_to_point(x_val,y_val),
+ radius=.04,
+ color=TEAL,
+ )
+ dots.add(dot)
+ self.play(ShowCreation(dots, run_time=1))
+ self.dots=dots
+
+ def show_func_machine(self):
+ machine=RoundedRectangle(
+ height=3,
+ width=4,
+ color=PURPLE,
+ stroke_width=8
+ ).to_edge(RIGHT, buff=.4)
+
+ machine_label=TextMobject(
+ r"Line segment\\ with slope\\"," $y'=-2xy$",
+ stroke_width=1.2,
+ color=BLUE
+ ).next_to(machine,IN)
+ machine_label[1].set_color(GREEN)
+ machine=VGroup(machine, machine_label)
+ self.play(FadeIn(machine))
+
+ self.func_machine = machine
+
+
+ def produce_slopes(self,slope_field):
+ count,i=3,0
+ self.run_time=1
+ for dot in self.dots:
+ if i==count:
+ self.run_time=.05
+ position=dot.get_center()
+ line= slope_field.get_slope(position)
+ self.go_to_machine(dot)
+ self.take_line_from_machine(line,position)
+ i+=1
+
+ def go_to_machine(self,dot):
+ if self.run_time>.5:
+ self.play(ApplyMethod(
+ dot.next_to,
+ self.func_machine,4*UP,
+ ),
+ run_time=self.run_time
+ )
+ self.dot=dot
+
+ def take_line_from_machine(self,vect,position):
+
+ if self.run_time>.5:
+ vect.next_to(self.func_machine,DOWN,buff=.1)
+ self.play(
+ ApplyMethod(
+ self.dot.shift,DOWN,
+ run_time=self.run_time
+ )),
+ self.play(
+ FadeOut(self.dot),
+ run_time=.2
+ )
+ self.play(
+ FadeIn(vect),
+ run_time=.4
+ )
+ self.play(
+ ApplyMethod(
+ vect.move_to,position
+ ),
+ run_time=self.run_time
+ )
+ else:
+ self.remove(self.dot)
+ self.add(vect)
+ vect.move_to(position)
+
+
+ def get_slope_field(self,func,**kwargs):
+ config = dict()
+ config.update(self.default_slope_field_config)
+ config.update(kwargs)
+ slope_field= SlopeField(func,**config)
+
+ return slope_field
+
+ def glimpse_of_solutions(self):
+ sol_text= TextMobject(
+ r"The solution curves\\ seem to be like...",
+ color= BLUE,
+ stroke_width=1.2
+ )
+ sol_text.to_corner(UR, buff=1)
+ condition_text= TextMobject(
+ r"for different\\ initial conditions",
+ color= GOLD,
+ stroke_width=1.1
+ )
+ condition_text.next_to(sol_text,DOWN,buff=1)
+ solution1 = self.get_graph(
+ lambda x : np.exp(-x**2),
+ x_min = self.a,
+ x_max = self.b,
+ color = PINK)
+ solution2 = self.get_graph(
+ lambda x : .5*np.exp(-x**2),
+ x_min = self.a,
+ x_max = self.b,
+ color = YELLOW)
+ solution3 = self.get_graph(
+ lambda x : 1.5*np.exp(-x**2),
+ x_min = self.a,
+ x_max = self.b,
+ color = BLUE)
+ solution4 = self.get_graph(
+ lambda x : -np.exp(-x**2),
+ x_min = self.a,
+ x_max = self.b,
+ color = RED_E)
+
+ self.play(FadeOut(self.func_machine))
+ self.play(Write(sol_text))
+ self.wait(.6)
+ self.play(ShowCreation(solution1))
+ self.play(Write(condition_text))
+ self.play(ShowCreation(solution2))
+ self.wait(.5)
+ self.play(ShowCreation(solution3))
+ self.wait(.5)
+ self.play(ShowCreation(solution4))
+
+
+class SlopeField(VGroup):
+ CONFIG = {
+ "delta_x": 0.5,
+ "delta_y": 0.5,
+ "x_min": int(np.floor(-FRAME_WIDTH / 2)),
+ "x_max": int(np.ceil(FRAME_WIDTH / 2)),
+ "y_min": int(np.floor(-FRAME_HEIGHT / 2)),
+ "y_max": int(np.ceil(FRAME_HEIGHT / 2)),
+ "opacity": 1.0,
+ "color": WHITE,
+ "slope_length_factor": .25,
+ "line_config": {},
+ }
+
+ def __init__(self, func, **kwargs):
+ VGroup.__init__(self, **kwargs)
+ self.func = func
+
+ x_range = np.arange(
+ self.x_min,
+ self.x_max + self.delta_x,
+ self.delta_x
+ )
+ y_range = np.arange(
+ self.y_min,
+ self.y_max + self.delta_y,
+ self.delta_y
+ )
+ for x, y in it.product(x_range, y_range):
+ point = x * RIGHT + y * UP
+ self.add(self.get_slope(point))
+ self.set_opacity(self.opacity)
+
+ def get_slope(self, point, **kwargs):
+ slope = self.func(*point[:2])
+ line_config = dict(self.line_config)
+ line_config.update(kwargs)
+ line = Line(ORIGIN,self.slope_length_factor*RIGHT, **line_config)
+ line.move_to(point).rotate(np.arctan(slope/3.2))
+
+ line.set_color(self.color)
+ return line
+
+
+
+
+#uploaded by Somnath Pandit. FSF2020_Vector_fields
+
+
+
diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/gifs/file1_vector_fields.gif b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/gifs/file1_vector_fields.gif
new file mode 100644
index 0000000..96e50ac
--- /dev/null
+++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/gifs/file1_vector_fields.gif
Binary files differ
diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/gifs/file2_grad_of_scalar_function.gif b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/gifs/file2_grad_of_scalar_function.gif
new file mode 100644
index 0000000..c1ab66a
--- /dev/null
+++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/gifs/file2_grad_of_scalar_function.gif
Binary files differ
diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/gifs/file3_constructing_vector_field.gif b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/gifs/file3_constructing_vector_field.gif
new file mode 100644
index 0000000..6a57cab
--- /dev/null
+++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/gifs/file3_constructing_vector_field.gif
Binary files differ
diff --git a/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/gifs/file4_slope_field.gif b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/gifs/file4_slope_field.gif
new file mode 100644
index 0000000..c39ec54
--- /dev/null
+++ b/FSF-2020/calculus-of-several-variables/integrals-of-multivariable-functions/vector-fields/gifs/file4_slope_field.gif
Binary files differ