summaryrefslogtreecommitdiff
path: root/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces
diff options
context:
space:
mode:
authorPurusharth Saxena2020-07-19 13:21:24 +0530
committerGitHub2020-07-19 13:21:24 +0530
commita15447d7f518153438894928f960329cc32b1053 (patch)
tree599fba92f6d348653b43c6bc664a7318b6589df3 /FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces
parentae98b8f71568711d01ae8d561c1d068f7ce329b5 (diff)
parenteadaf1b3e4245b4b5f3b932334400c0f3a0dcd22 (diff)
downloadFSF-mathematics-python-code-archive-a15447d7f518153438894928f960329cc32b1053.tar.gz
FSF-mathematics-python-code-archive-a15447d7f518153438894928f960329cc32b1053.tar.bz2
FSF-mathematics-python-code-archive-a15447d7f518153438894928f960329cc32b1053.zip
Merge pull request #72 from simranchhattani/master
Final changes
Diffstat (limited to 'FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces')
-rw-r--r--FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/Basis.py174
-rw-r--r--FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/Intersection_of_Subspaces.py52
-rw-r--r--FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/Subspace_Example.py82
-rw-r--r--FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/Subspace_Non_Example.py25
-rw-r--r--FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/gifs/Basis_of_a_Subspace.mp4bin0 -> 10735096 bytes
-rw-r--r--FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/gifs/Intersection_of_Subspaces.mp4bin0 -> 1112086 bytes
-rw-r--r--FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/gifs/Subspace_Example.gifbin647405 -> 0 bytes
-rw-r--r--FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/gifs/Subspace_Non_Example.mp4bin0 -> 818876 bytes
8 files changed, 251 insertions, 82 deletions
diff --git a/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/Basis.py b/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/Basis.py
new file mode 100644
index 0000000..6d2edc8
--- /dev/null
+++ b/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/Basis.py
@@ -0,0 +1,174 @@
+from manimlib.imports import *
+
+
+VECTORS = [[1, 2],
+ [-4, 2],
+ [-3, -3],
+ [3,-2],
+ [3,3],
+ [-2,1],
+ [-1,-3]]
+
+class Scene1(LinearTransformationScene):
+
+ CONFIG = {
+ "include_background_plane": True,
+ "include_foreground_plane": False,
+ "show_coordinates": False,
+ "show_basis_vectors": True,
+ "basis_vector_stroke_width": 3,
+
+ }
+ def construct(self):
+ self.setup()
+ ihat, jhat = self.get_basis_vectors()
+ labels = self.get_basis_vector_labels()
+ self.add(ihat, jhat)
+ self.add(*labels)
+
+ self.show_vector_as_basis_sum()
+ self.wait(2)
+
+ def show_vector_as_basis_sum(self):
+ text1 = TextMobject(r"Vector Space $\mathbb{R}^2$}").scale(0.8).shift(3*UP)
+ text1.add_background_rectangle()
+ self.play(ShowCreation(text1))
+ text2 = TextMobject(r"$\mathbb{R}^2$",color=BLUE_E).scale(0.8).shift(6.5*LEFT+3.5*UP)
+ text3 = TextMobject(r"\text{Basis Vectors:}",r"\text{$\hat{i}$}",r"\text{,}",r"\text{$\hat{j}$}").scale(0.7).shift(2*UP+2.5*RIGHT)
+ text3[1].set_color(GREEN_C)
+ text3[3].set_color(RED_C)
+
+ self.wait(2)
+ self.play(Transform(text1,text2))
+ self.wait(1)
+ self.play(ShowCreation(text3))
+ self.wait(1.7)
+ self.play(FadeOut(text3))
+
+ for i in range(len(VECTORS)):
+ v = self.add_vector(VECTORS[i], stroke_width = 3,color=YELLOW_D)
+
+ linei = Line(start = ORIGIN, end = VECTORS[i][0]*RIGHT)
+ linei.set_color(GREEN_C)
+ linej = Line(start = linei.get_end(),
+ end = linei.get_end() + VECTORS[i][1]*UP)
+ linej.set_color(RED_C)
+ self.play(ShowCreation(linei))
+ self.play(ShowCreation(linej))
+ vlabel = self.get_vector_label(v, str(VECTORS[i][0]) +
+ r"\imath" + "+" +
+ str(VECTORS[i][1]) +
+ r"\jmath", at_tip = True)
+ self.play(ShowCreation(vlabel))
+
+ self.play(FadeOut(linei),FadeOut(linej))
+ self.wait(1)
+ dot = Dot(v.get_end(), fill_color = v.get_stroke_color())
+ self.play(ShowCreation(dot),FadeOut(v),FadeOut(vlabel))
+ self.wait(0.3)
+
+class Scene2(LinearTransformationScene):
+ CONFIG = {
+ "num_vectors" : 16,
+ "start_color" : GREY,
+ "end_color" : YELLOW_D,
+ "include_background_plane": True,
+ "include_foreground_plane": False,
+ }
+
+ def get_vectors(self):
+ return [
+ Vector([x, y], stroke_width = 3.5)
+ for x in np.arange(-int(FRAME_X_RADIUS), int(FRAME_X_RADIUS)+0.5, 0.5)
+ for y in np.arange(-int(FRAME_Y_RADIUS), int(FRAME_Y_RADIUS)+0.5, 0.5)
+ ]
+
+ def lock_in_faded_grid(self, dimness=0.7, axes_dimness=0.5):
+ plane = self.add_plane()
+ axes = plane.get_axes()
+ plane.fade(dimness)
+ axes.set_color(WHITE)
+ axes.fade(axes_dimness)
+ self.add(axes)
+
+ def construct(self):
+ self.lock_in_faded_grid()
+
+ vectors = self.get_vectors()
+ colors = Color(self.start_color).range_to(
+ self.end_color, len(vectors)
+ )
+ for vect, color in zip(vectors, colors):
+ vect.set_color(color)
+
+ vector_group = VGroup(*vectors)
+ self.play(
+ ShowCreation(
+ vector_group,
+ run_time = 3
+ )
+ )
+
+ self.wait(1)
+
+ vectors.sort(key=lambda v: v.get_length())
+ def v_to_dot(vector):
+ return Dot(vector.get_end(), fill_color = vector.get_stroke_color())
+ self.wait()
+ rate_functions = [
+ squish_rate_func(smooth, float(x)/(len(vectors)+2), 1)
+ for x in range(len(vectors))
+ ]
+ self.play(*[
+ Transform(v, v_to_dot(v), rate_func = rf, run_time = 3)
+ for v, rf in zip(vectors, rate_functions)
+ ])
+ self.wait(2)
+ self.play_final_animation(vectors, rate_functions)
+ self.wait(2)
+
+ text1 = TextMobject(" Basis is the minimum information required to ").shift(3.1*UP).scale(0.8)
+ text2 = TextMobject("generate the whole space.").scale(0.8).shift(2.6*UP)
+
+ text1.add_background_rectangle()
+ text2.add_background_rectangle()
+
+
+
+ self.play(ShowCreation(text1),ShowCreation(text2))
+
+ self.play(ShowCreation(self.get_basis_vectors()))
+ self.wait(3)
+
+ def play_final_animation(self, vectors, rate_functions):
+
+ h_line = Line(
+ FRAME_X_RADIUS*RIGHT, FRAME_X_RADIUS*LEFT,
+ stroke_width = 0.5,
+ color = BLUE_E
+ )
+ v_line = Line(
+ FRAME_Y_RADIUS*UP, FRAME_Y_RADIUS*DOWN,
+ stroke_width = 0.5,
+ color = BLUE_E
+ )
+ line_pairs = [
+ VGroup(h_line.copy().shift(y), v_line.copy().shift(x))
+ for v in vectors
+ for x, y, z in [v.get_center()]
+ ]
+ plane = NumberPlane()
+
+ self.play(
+ ShowCreation(plane),
+ *[
+ Transform(v, p, rate_func = rf)
+ for v, p, rf in zip(vectors, line_pairs, rate_functions)
+ ]
+ )
+ self.remove(*vectors)
+
+
+
+
+ \ No newline at end of file
diff --git a/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/Intersection_of_Subspaces.py b/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/Intersection_of_Subspaces.py
new file mode 100644
index 0000000..ec82daa
--- /dev/null
+++ b/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/Intersection_of_Subspaces.py
@@ -0,0 +1,52 @@
+from manimlib.imports import *
+class ThreeDSpace(ThreeDScene):
+
+
+ def construct(self):
+ axes = ThreeDAxes()
+ self.set_camera_orientation(phi = 80*DEGREES,theta =110*DEGREES)
+ self.begin_ambient_camera_rotation(rate=0.09)
+
+
+
+
+ cube = Cube(stroke_width=5,color=WHITE).shift([1.5,1.5,1.5]).scale(1.5)
+ cube.set_fill(TEAL)
+
+ cube.set_opacity(0.4)
+
+
+ plane1 = Polygon([0,0,3],[3,0,3],[3,3,0],[0,3,0])
+ plane1.set_opacity(0.65)
+ plane1.set_fill(PURPLE)
+ plane1.set_color(PURPLE)
+
+
+ plane2 = Polygon([0,3,3],[3,3,3],[3,0,0],[0,0,0])
+ plane2.set_opacity(0.7)
+ plane2.set_fill(RED)
+ plane2.set_color(RED)
+ line = Line(color=YELLOW,set_opacity=100).shift([1.5,1.5,1.5]).scale(1.5)
+
+ vgroup = VGroup(plane1,plane2,line,cube)
+ vgroup.shift([-1,-1,-1])
+
+ dot = Dot(color=BLACK).shift([0.5,0.5,0.5]).scale(1)
+ text = TextMobject(r"\text{The}",r"\text{line}",r"\text{representing the intersection of the two planes is a Subspace.}",opacity = 0.6).scale(0.7).shift(3*UP)
+ text[1].set_color(YELLOW)
+ self.add_fixed_in_frame_mobjects(text)
+ self.play(ShowCreation(text))
+
+
+ self.play(ShowCreation(cube))
+ self.play(ShowCreation(plane1))
+ self.play(ShowCreation(plane2))
+
+ self.play(ShowCreation(line),ShowCreation(dot))
+
+
+ self.wait(15)
+
+
+
+ \ No newline at end of file
diff --git a/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/Subspace_Example.py b/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/Subspace_Example.py
deleted file mode 100644
index ada173e..0000000
--- a/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/Subspace_Example.py
+++ /dev/null
@@ -1,82 +0,0 @@
-from manimlib.imports import *
-class Subspace_Example(Scene):
- def construct(self):
- sq = Square(side = 2, color=BLACK).shift(2*LEFT)
- sq.set_fill(color=RED,opacity=350)
- line1=Line(color=BLACK).shift(2*LEFT)
- line1.rotate(np.pi/2)
- line2=Line(color=BLACK).shift(2.5*LEFT+0.5*UP)
- line2.scale(0.5)
- line3=Line(color=BLACK).shift(+1.5*LEFT)
- line3.scale(0.5)
- a1=TextMobject(r"$a_1$",color=BLACK).scale(0.5).shift(3.4*LEFT+0.7*UP)
- a2=TextMobject(r"$a_2$",color=BLACK).scale(0.5).shift(3.4*LEFT+0.3*DOWN)
- a3=TextMobject(r"$a_3$",color=BLACK).scale(0.5).shift(0.7*LEFT+0.5*DOWN)
- a4=TextMobject(r"$a_4$",color=BLACK).scale(0.5).shift(0.7*LEFT+0.5*UP)
- big_rect=Rectangle().scale(3).shift(0.5*DOWN)
- big_rect.set_fill(color=GREY,opacity=350)
- vec_space=TextMobject("$Vector Space$").scale(0.77).shift(4.5*RIGHT+3.5*UP)
- sub=TextMobject(r"$Subspace$",color=BLACK).scale(0.77).shift(3.8*RIGHT+2*UP)
- self.play(ShowCreation(vec_space))
- self.play(ShowCreation(big_rect),ShowCreation(sub))
- self.play(ShowCreation(sq),ShowCreation(line1),ShowCreation(line2),ShowCreation(line3),ShowCreation(a1),ShowCreation(a2),ShowCreation(a3),ShowCreation(a4))
- rec = Rectangle(color=BLACK).scale(0.5).shift(1*RIGHT)
- rec.rotate(np.pi/2)
- rec.set_fill(color=BLUE,opacity=350)
- line4=Line(color=BLACK).shift(1*RIGHT).rotate(np.pi/2)
- line5=Line(color=BLACK).scale(0.25).shift(0.75*RIGHT)
- line6=Line(color=BLACK).scale(0.25).shift(0.5*DOWN+1.25*RIGHT)
- b1=TextMobject(r"$b_1$",color=BLACK).scale(0.5).shift(0.3*RIGHT+0.5*UP)
- b2=TextMobject(r"$b_2$",color=BLACK).scale(0.5).shift(0.3*RIGHT+0.5*DOWN)
- b3=TextMobject(r"$b_3$",color=BLACK).scale(0.5).shift(1.67*RIGHT+0.8*DOWN)
- b4=TextMobject(r"$b_4$",color=BLACK).scale(0.5).shift(1.67*RIGHT+0.5*UP)
- self.play(ShowCreation(rec),ShowCreation(line4),ShowCreation(line5),ShowCreation(line6),ShowCreation(b1),ShowCreation(b2),ShowCreation(b3),ShowCreation(b4))
- self.wait(1)
- text1=TextMobject(r"$a_1 + a_2 = a_3 + a_4$",color=BLACK).scale(0.5).shift(2*LEFT+1.5*DOWN)
- text2=TextMobject(r"$b_1 + b_2 = b_3 + b_4$",color=BLACK).scale(0.5).shift(1.5*RIGHT+1.5*DOWN)
- self.play(ShowCreation(text1),ShowCreation(text2))
- self.wait(3)
- self.play(FadeOut(text1),FadeOut(text2))
- rec.shift(3*LEFT+2.01*DOWN)
- line4.shift(3*LEFT+2*DOWN)
- line5.shift(3*LEFT+2*DOWN)
- line6.shift(3*LEFT+2*DOWN)
- b1.shift(3.1*LEFT+2.1*DOWN)
- b2.shift(3.1*LEFT+2.1*DOWN)
- b3.shift(2.9*LEFT+2*DOWN)
- b4.shift(2.9*LEFT+2.3*DOWN)
- self.play(ShowCreation(rec),ShowCreation(line4),ShowCreation(line5),ShowCreation(line6),ShowCreation(b1),ShowCreation(b2),ShowCreation(b3),ShowCreation(b4))
- self.wait(2)
-
- text3=TextMobject(r"$(a_1 + a_2) + (b_1 + b_2) = (a_3 + a_4) + (b_3 + b_4)$",color=BLACK).scale(0.5).shift(2.5*RIGHT+0.5*DOWN)
- text3=TextMobject(r"$(a_1 + a_2) + (b_1 + b_2) = (a_3 + a_4) + (b_3 + b_4)$",color=BLACK).scale(0.5).shift(2.5*RIGHT+0.5*DOWN)
- text4=TextMobject("Vector Addition",color=BLACK).scale(0.8).shift(2.5*RIGHT+0.5*UP)
- self.play(ShowCreation(text3),ShowCreation(text4))
- self.wait(3)
- rec.set_fill(color=GREY,opacity=350)
- self.play(FadeOut(text3),FadeOut(text4),FadeOut(line4),FadeOut(line5),FadeOut(line6),FadeOut(rec),FadeOut(b4),FadeOut(b3),FadeOut(b2),FadeOut(b1))
- sq1=Square(color=BLACK).scale(0.5).shift(1.5*LEFT+1.5*UP)
- sq1.set_fill(color=RED,opacity=350)
- sq2=Square(color=BLACK).scale(0.5).shift(1.5*LEFT+1.5*DOWN)
- sq2.set_fill(color=RED,opacity=350)
- rec1=Rectangle(height=0.5,width=1,color=BLACK).shift(2.5*LEFT+1.2*UP)
- rec1.set_fill(color=RED,opacity=350)
- rec2=Rectangle(height=1.5,width=1,color=BLACK)
- rec2.set_fill(color=RED,opacity=350).shift(2.5*LEFT+1.5*DOWN)
- self.play(ShowCreation(sq1),ShowCreation(sq2),ShowCreation(rec1),ShowCreation(rec2))
- a=TextMobject(r"$a_1$",color=BLACK).scale(0.5).shift(3.4*LEFT+1.2*UP)
- b=TextMobject(r"$a_2$",color=BLACK).scale(0.5).shift(3.4*LEFT+1.4*DOWN)
- c=TextMobject(r"$a_3$",color=BLACK).scale(0.5).shift(0.7*LEFT+1.4*DOWN)
- d=TextMobject(r"$a_4$",color=BLACK).scale(0.5).shift(0.7*LEFT+1.4*UP)
- self.play(ShowCreation(a),ShowCreation(b),ShowCreation(c),ShowCreation(d))
- self.wait(2.3)
- text4=TextMobject("Scalar Multiplication",color=BLACK).scale(0.8).shift(2.5*RIGHT+0.5*UP)
- text5=TextMobject(r"$\implies 2(a_1 + a_2) = 2(a_3 + a_4)$",color=BLACK).scale(0.5).shift(2*RIGHT+0.5*DOWN)
- text6=TextMobject(r"$(a_1 + a_1) + (a_2 + a_2) = (a_3 + a_3) + (a_4 +a_4)$",color=BLACK).scale(0.5).shift(2.5*RIGHT)
- self.play(ShowCreation(text4),ShowCreation(text5),ShowCreation(text6))
- self.wait(3)
-
-
-
-
-
diff --git a/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/Subspace_Non_Example.py b/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/Subspace_Non_Example.py
new file mode 100644
index 0000000..115a722
--- /dev/null
+++ b/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/Subspace_Non_Example.py
@@ -0,0 +1,25 @@
+from manimlib.imports import *
+class ThreeDSpace(ThreeDScene):
+
+
+ def construct(self):
+ axes = ThreeDAxes()
+ self.add(axes)
+ self.set_camera_orientation(phi = 80*DEGREES,theta =110*DEGREES)
+ self.begin_ambient_camera_rotation(rate=0.09)
+ plane1 = Polygon([-1.5,1.5,-1.5],[1.5,1.5,-1.5],[1.5,-1.5,1.5],[-1.5,-1.5,1.5])
+ plane1.set_opacity(0.65)
+ plane1.set_fill(GREEN)
+ plane1.set_color(GREEN)
+
+
+ plane2 = Polygon([-1.5,1.5,1.5],[1.5,1.5,1.5],[1.5,-1.5,-1.5],[-1.5,-1.5,-1.5])
+ plane2.set_opacity(0.7)
+ plane2.set_fill(MAROON_A)
+ plane2.set_color(MAROON_A)
+ line = Line(color=YELLOW,set_opacity=100,start=[1.5,1.2,1.2],end=[-1.5,1.2,1.2])
+
+
+ self.play(ShowCreation(plane1),ShowCreation(plane2),ShowCreation(line))
+ self.wait(10)
+
diff --git a/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/gifs/Basis_of_a_Subspace.mp4 b/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/gifs/Basis_of_a_Subspace.mp4
new file mode 100644
index 0000000..d384f80
--- /dev/null
+++ b/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/gifs/Basis_of_a_Subspace.mp4
Binary files differ
diff --git a/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/gifs/Intersection_of_Subspaces.mp4 b/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/gifs/Intersection_of_Subspaces.mp4
new file mode 100644
index 0000000..d43bfbe
--- /dev/null
+++ b/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/gifs/Intersection_of_Subspaces.mp4
Binary files differ
diff --git a/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/gifs/Subspace_Example.gif b/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/gifs/Subspace_Example.gif
deleted file mode 100644
index 32b02be..0000000
--- a/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/gifs/Subspace_Example.gif
+++ /dev/null
Binary files differ
diff --git a/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/gifs/Subspace_Non_Example.mp4 b/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/gifs/Subspace_Non_Example.mp4
new file mode 100644
index 0000000..390f4cf
--- /dev/null
+++ b/FSF-2020/linear-algebra/vector-spaces/Vector-Spaces/Subspaces/gifs/Subspace_Non_Example.mp4
Binary files differ