summaryrefslogtreecommitdiff
path: root/FSF-2020
diff options
context:
space:
mode:
authorG Sri Harsha2020-07-01 02:46:49 +0530
committerGitHub2020-07-01 02:46:49 +0530
commit2b32209d3cd416001702eed3e6b2d68d6251d7f5 (patch)
tree28d41d72029e194aa2f01b81a0f1ee1d3f9e8c39 /FSF-2020
parent7248227e3b8be3871185cee9b84d9c0bd6108cf1 (diff)
downloadFSF-mathematics-python-code-archive-2b32209d3cd416001702eed3e6b2d68d6251d7f5.tar.gz
FSF-mathematics-python-code-archive-2b32209d3cd416001702eed3e6b2d68d6251d7f5.tar.bz2
FSF-mathematics-python-code-archive-2b32209d3cd416001702eed3e6b2d68d6251d7f5.zip
added codes
Diffstat (limited to 'FSF-2020')
-rw-r--r--FSF-2020/calculus/series-and-transformations/Z-Transform/video1_Sampling.py81
-rw-r--r--FSF-2020/calculus/series-and-transformations/Z-Transform/video2_ZTransformOfDelta.py121
-rw-r--r--FSF-2020/calculus/series-and-transformations/Z-Transform/video3_RegionOfConvergence.py144
3 files changed, 346 insertions, 0 deletions
diff --git a/FSF-2020/calculus/series-and-transformations/Z-Transform/video1_Sampling.py b/FSF-2020/calculus/series-and-transformations/Z-Transform/video1_Sampling.py
new file mode 100644
index 0000000..47615e3
--- /dev/null
+++ b/FSF-2020/calculus/series-and-transformations/Z-Transform/video1_Sampling.py
@@ -0,0 +1,81 @@
+from manimlib.imports import *
+import math
+
+def func(x):
+ return math.pow(x,3)-2*math.pow(x,2)-x+3
+
+class graphScene(GraphScene):
+ CONFIG = {
+ "x_min": -3,
+ "x_max": 3,
+ "y_min": -4,
+ "y_max": 4,
+ "x_tick_frequency": 0.2,
+ "graph_origin": ORIGIN,
+ "function_color": RED,
+ "axes_color": BLUE,
+ "x_axis_label": "$t$",
+ "y_axis_label": "$f(t)$",
+ "exclude_zero_label": True,
+ "x_labeled_nums": range(-3, 4, 1),
+ "y_axis_height": 5,
+ "x_axis_width": 9,
+ }
+
+ def construct(self):
+ x_each_unit = self.x_axis_width / (self.x_max - self.x_min)
+ y_each_unit = self.y_axis_height / (self.y_max - self.y_min)
+
+ fx=TextMobject("$f(t) = { t }^{ 3 }{ -2t }^{ 2 }-t+3$").set_color(RED).to_corner(UP+RIGHT).scale(0.4)
+ self.setup_axes(animate=True,scalee=1)
+ function=self.get_graph(lambda x:math.pow(x,3)-2*math.pow(x,2)-x+3,color=RED,x_min=-1,x_max=2)
+ functionArea=self.get_riemann_rectangles(function,x_min=-1,x_max=2,dx=0.01,start_color=GREEN,end_color=YELLOW,stroke_color=GREEN,fill_opacity=0.8)
+ functionDot=Dot(point=self.graph_origin,radius=0.065,color=WHITE)
+ aboveText1=TextMobject("Continuous","Time Function").shift(4*RIGHT+2*UP).scale(0.4).set_color_by_tex_to_color_map({"Continuous":YELLOW,"Time Function":BLUE})
+ aboveText2=TextMobject("Discrete","Time Function").shift(4*RIGHT+2*UP).scale(0.4).set_color_by_tex_to_color_map({"Time Function":BLUE,"Discrete":YELLOW})
+
+ bottomText1=TextMobject("Instead of considering the","function","over the","entire $t$,").shift(4.5*RIGHT+3*DOWN).scale(0.4).set_color_by_tex_to_color_map({"entire $t$,":RED,"function":YELLOW})
+ bottomText2=TextMobject("We consider only at","certain $t$").shift(4.5*RIGHT+3*DOWN).scale(0.4).set_color_by_tex_to_color_map({"certain $t$":RED})
+
+ self.play(ShowCreation(function),Write(fx),FadeIn(aboveText1))
+ self.wait(0.7)
+ self.play(Write(bottomText1))
+ self.play(ShowCreation(functionArea),MoveAlongPath(functionDot,function))
+ self.wait(0.7)
+ self.play(FadeOut(bottomText1))
+ self.play(Write(bottomText2),FadeOut(aboveText1))
+
+ dots=[Dot(radius=0.05) for i in range(10)]
+ dotShifts=[-1,-0.7,-0.4,0,0.3,0.6,1,1.3,1.6,2]
+ lines=[]
+ for x in dotShifts:
+ lines.append(Line(start=(x*x_each_unit,func(x)*y_each_unit,0),end=(x*x_each_unit,0,0),color=GREEN))
+ for i in range(10):
+ dots[i].shift(ORIGIN+RIGHT*x_each_unit*dotShifts[i]+y_each_unit*UP*func(dotShifts[i]))
+ updatedGraph=VGroup(dots[0],
+ dots[1],
+ dots[2],
+ dots[3],
+ dots[4],
+ dots[5],
+ dots[6],
+ dots[7],
+ dots[8],
+ dots[9])
+ updatedGraph1=VGroup(
+ lines[0],
+ lines[1],
+ lines[2],
+ lines[3],
+ lines[4],
+ lines[5],
+ lines[6],
+ lines[7],
+ lines[8],
+ lines[9])
+
+ self.play(FadeOut(functionDot))
+ self.play(FadeOut(function),FadeIn(updatedGraph))
+ self.play(FadeOut(functionArea),FadeIn(updatedGraph1))
+ self.play(FadeOut(bottomText2),FadeIn(aboveText2))
+ self.wait(2) \ No newline at end of file
diff --git a/FSF-2020/calculus/series-and-transformations/Z-Transform/video2_ZTransformOfDelta.py b/FSF-2020/calculus/series-and-transformations/Z-Transform/video2_ZTransformOfDelta.py
new file mode 100644
index 0000000..3063aa6
--- /dev/null
+++ b/FSF-2020/calculus/series-and-transformations/Z-Transform/video2_ZTransformOfDelta.py
@@ -0,0 +1,121 @@
+from manimlib.imports import *
+import numpy as np
+import math
+
+class deltaTransformation(GraphScene):
+ CONFIG = {
+ "x_min": -3,
+ "x_max": 3,
+ "y_min": -5,
+ "y_max": 5,
+ "graph_origin": ORIGIN,
+ "function_color": RED,
+ "axes_color": BLUE,
+ "x_axis_label": "$t$",
+ "y_axis_label": "$f(t)$",
+ "x_labeled_nums": range(-3, 4, 1),
+ # "y_axis_height": 4,
+ # "x_axis_width": 6,
+ }
+ def construct(self):
+ x_each_unit = self.x_axis_width / (self.x_max - self.x_min)
+ y_each_unit = self.y_axis_height / (self.y_max - self.y_min)
+ self.setup_axes(animate=True,scalee=0.8)
+ function=TextMobject("$f(t) = 2{ \delta }_{ 0 }(t)+3{ \delta }_{ 1 }(t)+4{ \delta }_{ 2 }(t)$").scale(0.4).shift(5*RIGHT+3*UP).set_color(RED)
+ self.play(FadeIn(function))
+ twoDGraph=[
+ Line(start=(0,0,0),end=(0,2*y_each_unit,0),color=GREEN),
+ Line(start=(1*x_each_unit,0,0),end=(x_each_unit,3*y_each_unit,0),color=GREEN),
+ Line(start=(2*x_each_unit,0,0),end=(2*x_each_unit,4*y_each_unit,0),color=GREEN)
+ ]
+ groupGraph=VGroup(twoDGraph[1],twoDGraph[2],self.axes,twoDGraph[0])
+ self.play(Write(twoDGraph[0]),ShowCreation(twoDGraph[1]),ShowCreation(twoDGraph[2]))
+ self.wait(1.2)
+ self.play(ApplyMethod(groupGraph.scale,0.7))
+ self.play(ApplyMethod(groupGraph.shift,5*LEFT),ApplyMethod(function.move_to,5*LEFT+3*UP))
+ self.graph_origin=2*RIGHT+2.5*DOWN
+ self.x_axis_width=6
+ self.x_axis_label="$|z|$"
+ self.y_axis_label="$|F(t)|$"
+ self.x_min=-3
+ self.x_max=6
+ self.y_min=-1
+ self.y_max=7
+ self.x_labeled_nums=range(-3,7,1)
+ self.setup_axes(animate=True,scalee=0.6)
+ x_each_unit = self.x_axis_width / (self.x_max - self.x_min)
+ y_each_unit = self.y_axis_height / (self.y_max - self.y_min)
+ rightSideGraphs=[
+ self.get_graph(lambda x:2,x_min=0,x_max=6,color=GREEN),
+ self.get_graph(lambda x:2+3/x,x_min=0.6,x_max=6,color=GREEN),
+ self.get_graph(lambda x:2+(3/x)+(4/x**2),x_min=1.24,x_max=6,color=GREEN)
+ ]
+ graphCoeff=[
+ TextMobject("$2$").scale(0.4).shift(self.graph_origin+x_each_unit*RIGHT*2+UP*y_each_unit*2+DOWN*y_each_unit*0.5).set_color(RED),
+ TextMobject("$2+\\frac { 3 }{ |z| }$").scale(0.4).shift(self.graph_origin+x_each_unit*RIGHT*3+UP*y_each_unit*2).set_color(RED),
+ TextMobject("$2+\\frac { 3 }{ |z| } +\\frac { 4 }{ { |z| }^{ 2 } } $").scale(0.4).shift(self.graph_origin+x_each_unit*RIGHT*3.5+UP*y_each_unit*2).set_color(RED)
+ ]
+ self.play(ReplacementTransform(twoDGraph[0],rightSideGraphs[0]),FadeIn(graphCoeff[0]))
+ self.wait(0.5)
+ self.play(FadeOut(rightSideGraphs[0]),ReplacementTransform(twoDGraph[1],rightSideGraphs[1]),ReplacementTransform(graphCoeff[0],graphCoeff[1]))
+ self.wait(0.5)
+ self.play(FadeOut(rightSideGraphs[1]),ReplacementTransform(twoDGraph[2],rightSideGraphs[2]),ReplacementTransform(graphCoeff[1],graphCoeff[2]))
+
+ self.wait(2)
+
+
+class graphCont(GraphScene,MovingCameraScene):
+ CONFIG = {
+ "x_min": -3,
+ "x_max": 6,
+ "y_min": -1,
+ "y_max": 7,
+ "graph_origin": 2*RIGHT+2.5*DOWN,
+ "function_color": RED,
+ "axes_color": BLUE,
+ "x_axis_label": "$|z|$",
+ "y_axis_label": "$|F(t)|$",
+ "exclude_zero_label": True,
+ "x_labeled_nums": range(-3, 7, 1),
+ "x_axis_width": 6,
+ }
+ def setup(self):
+ GraphScene.setup(self)
+ MovingCameraScene.setup(self)
+
+ def construct(self):
+ x_each_unit = self.x_axis_width / (self.x_max - self.x_min)
+ y_each_unit = self.y_axis_height / (self.y_max - self.y_min)
+
+ coeff=TextMobject("$2+\\frac { 3 }{ |z| } +\\frac { 4 }{ { |z| }^{ 2 } } $").scale(0.4).shift(self.graph_origin+x_each_unit*RIGHT*3.5+UP*y_each_unit*2).set_color(RED)
+ self.setup_axes(scalee=0.6)
+ graph=self.get_graph(lambda x:2+(3/x)+(4/x**2),x_min=1.24,x_max=6,color=GREEN)
+ xAxis=self.get_graph(lambda x:0,x_min=1.24,x_max=6).shift(3*LEFT)
+ self.add(graph)
+ self.add(coeff)
+ self.play(ApplyMethod((self.axes).shift,3*LEFT),ApplyMethod(coeff.shift,3*LEFT),ApplyMethod(graph.shift,3*LEFT))
+ topText=TextMobject("Here we get","output","for","any value of $|z|$").scale(0.4).shift(3*UP+3*RIGHT).set_color_by_tex_to_color_map({"output":YELLOW,"any value of $|z|$":BLUE})
+ topText1=TextMobject("Except for $|z|=0$").scale(0.7).shift(2.5*UP+3*RIGHT).set_color(RED)
+ dot1=Dot(color=WHITE,radius=0.06)
+ dot2=Dot(color=WHITE,radius=0.06)
+ self.play(Write(topText))
+ self.play(MoveAlongPath(dot1,graph),MoveAlongPath(dot2,xAxis),run_time=2)
+ self.play(Write(topText1))
+ self.play(FadeOut(dot1),FadeOut(dot2))
+ self.wait(0.5)
+ path=self.get_graph(lambda x:2+(3/x)+(4/x**2),x_min=1.24,x_max=0.8)
+ path1=self.get_graph(lambda x:0,x_min=1.24,x_max=0.8)
+ graphUpdated=self.get_graph(lambda x:2+(3/x)+(4/x**2),x_min=0.8,x_max=6,color=GREEN)
+ self.camera_frame.save_state()
+ self.play(FadeOut(graph),Write(graphUpdated))
+ self.play(self.camera_frame.set_width, 30,
+ MoveAlongPath(dot1,path),MoveAlongPath(dot2,path1),run_time=2)
+ self.wait(1)
+
+ self.play(FadeOut(dot1),FadeOut(dot2),FadeOut(graphUpdated),FadeIn(graph),self.camera_frame.set_width,15)
+ self.wait(1)
+
+
+
+
+
diff --git a/FSF-2020/calculus/series-and-transformations/Z-Transform/video3_RegionOfConvergence.py b/FSF-2020/calculus/series-and-transformations/Z-Transform/video3_RegionOfConvergence.py
new file mode 100644
index 0000000..bdfd8b3
--- /dev/null
+++ b/FSF-2020/calculus/series-and-transformations/Z-Transform/video3_RegionOfConvergence.py
@@ -0,0 +1,144 @@
+from manimlib.imports import *
+import numpy as np
+import math
+
+class graph1(GraphScene):
+ CONFIG = {
+ "x_min": -3,
+ "x_max": 5,
+ "y_min": -1,
+ "y_max": 1,
+ "graph_origin": ORIGIN,
+ "function_color": RED,
+ "axes_color": BLUE,
+ "x_axis_label": "$n$",
+ "y_axis_label": "$x(n)$",
+ "x_labeled_nums": range(-3, 6, 1),
+ "y_axis_height": 7,
+ "y_tick_frequency": 0.1,
+ }
+ def func(self,x,n):
+ summ=0
+ for i in range(n+1):
+ summ+=(1/(math.pow(x,i)))
+ return summ
+
+ def finalFunc(self,x):
+ if(x!=0):
+ return 1/(1-(1/(2*x)))
+
+
+ def construct(self):
+ x_each_unit = self.x_axis_width / (self.x_max - self.x_min)
+ y_each_unit = self.y_axis_height / (self.y_max - self.y_min)
+ self.setup_axes(animate=True,scalee=0.8)
+ function=TextMobject("$X(t)=\sum _{ n=0 }^{ \infty }{ { (0.5) }^{ n }{ z }^{ -n } }$").scale(0.4).shift(5*RIGHT+3*UP).set_color(RED)
+ self.play(FadeIn(function))
+ twoDGraph=[]
+ for i in range(5):
+ twoDGraph.append(Line(start=(i*x_each_unit,0,0),end=(i*x_each_unit,math.pow(0.5,i)*y_each_unit,0),color=GREEN))
+
+ groupGraph=VGroup(self.axes,twoDGraph[0],twoDGraph[1],twoDGraph[2],twoDGraph[3],twoDGraph[4])
+ self.play(Write(twoDGraph[0]),ShowCreation(twoDGraph[1]),ShowCreation(twoDGraph[2]),ShowCreation(twoDGraph[3]),ShowCreation(twoDGraph[4]))
+ self.wait(1.2)
+
+ self.play(ApplyMethod(groupGraph.scale,0.7))
+ self.play(ApplyMethod(groupGraph.shift,6*LEFT),ApplyMethod(function.move_to,5*LEFT+3*UP))
+
+ someText1=TextMobject("Since it is a","summation","of","infinite terms",", it might").shift(2*RIGHT+2*UP).scale(0.5).set_color_by_tex_to_color_map({"summation":YELLOW,"infinite terms":BLUE})
+ someText2=TextMobject("Converge","or","Diverge").shift(2*RIGHT+0.5*DOWN+2*UP).scale(0.7).set_color_by_tex_to_color_map({"Converge":GREEN,"Diverge":RED})
+ someText3=TextMobject("depending upon","$|z|$").shift(2*RIGHT+UP).scale(0.5).set_color_by_tex_to_color_map({"$|z|$":YELLOW})
+ self.play(Write(someText1))
+ self.play(FadeIn(someText2))
+ self.play(Write(someText3))
+ self.wait(1)
+ self.play(FadeOut(someText1),FadeOut(someText2),FadeOut(someText3))
+
+ self.graph_origin=2*RIGHT+DOWN
+ self.x_axis_width=6
+ self.y_axis_height=5
+ self.y_tick_frequency=1
+ self.x_axis_label="$|z|$"
+ self.y_axis_label="$|X(n)|$"
+ self.x_min=-3
+ self.x_max=5
+ self.y_min=-1
+ self.y_max=5
+ self.x_labeled_nums=range(-3,6,1)
+ self.setup_axes(animate=True,scalee=0.6)
+ x_each_unit = self.x_axis_width / (self.x_max - self.x_min)
+ y_each_unit = self.y_axis_height / (self.y_max - self.y_min)
+ rightSideGraphs=[]
+ xmins=[0,0.25,0.65,0.9,1]
+ for i in range(5):
+ rightSideGraphs.append(self.get_graph(lambda x:self.func(x,i),x_min=xmins[i],x_max=5,color=GREEN))
+ rightSideGraphs.append(self.get_graph(lambda x:1/(1-(1/(2*x))),x_min=0.63,x_max=5,color=GREEN))
+
+ graphCoeff=[
+ TextMobject("$1$").scale(0.4).shift(self.graph_origin+x_each_unit*RIGHT*2+0.65*UP*y_each_unit*2+DOWN*y_each_unit*0.5).set_color(RED),
+ TextMobject("$1+\\frac { 1 }{ 2|z| }$").scale(0.4).shift(self.graph_origin+x_each_unit*RIGHT*2+UP*y_each_unit).set_color(RED),
+ TextMobject("$1+\\frac { 1 }{ 2|z| } +\\frac { 1 }{ { 2|z| }^{ 2 } } $").scale(0.4).shift(self.graph_origin+x_each_unit*RIGHT*2+UP*y_each_unit).set_color(RED),
+ TextMobject("$1+\\frac { 1 }{ 2|z| } +\\frac { 1 }{ { (2|z|) }^{ 2 } } +\\frac { 1 }{ { (2|z|) }^{ 3 } }$").scale(0.4).shift(self.graph_origin+x_each_unit*RIGHT*2+UP*y_each_unit).set_color(RED),
+ TextMobject("$1+\\frac { 1 }{ 2|z| } +\\frac { 1 }{ { (2|z|) }^{ 2 } } +\\frac { 1 }{ { (2|z|) }^{ 3 } } +\\frac { 1 }{ (2|z|)^{ 4 } } $").scale(0.4).shift(self.graph_origin+x_each_unit*RIGHT*2+UP*y_each_unit).set_color(RED),
+ TextMobject("$\\frac { 1 }{ (1-\\frac { 1 }{ 2z } ) } $").scale(0.4).shift(self.graph_origin+x_each_unit*RIGHT*2+UP*y_each_unit).set_color(RED)
+ ]
+
+ self.play(ReplacementTransform(twoDGraph[0],rightSideGraphs[0]),FadeIn(graphCoeff[0]))
+ self.wait(0.5)
+ self.play(FadeOut(rightSideGraphs[0]),ReplacementTransform(twoDGraph[1],rightSideGraphs[1]),ReplacementTransform(graphCoeff[0],graphCoeff[1]))
+ self.wait(0.5)
+ self.play(FadeOut(rightSideGraphs[1]),ReplacementTransform(twoDGraph[2],rightSideGraphs[2]),ReplacementTransform(graphCoeff[1],graphCoeff[2]))
+ self.wait(0.5)
+ self.play(FadeOut(rightSideGraphs[2]),ReplacementTransform(twoDGraph[3],rightSideGraphs[3]),ReplacementTransform(graphCoeff[2],graphCoeff[3]))
+ self.wait(0.5)
+ self.play(FadeOut(rightSideGraphs[3]),ReplacementTransform(twoDGraph[4],rightSideGraphs[4]),ReplacementTransform(graphCoeff[3],graphCoeff[4]))
+ self.wait(0.5)
+ self.play(FadeOut(rightSideGraphs[4]),ShowCreation(rightSideGraphs[5]),ReplacementTransform(graphCoeff[4],graphCoeff[5]))
+
+ self.wait(2)
+ # #self.play(FadeOut(self.axes),FadeOut(function),FadeOut(twoDGraph[0]),FadeOut(twoDGraph[1]),FadeOut(twoDGraph[2]))
+
+
+class graphCont(GraphScene,MovingCameraScene):
+ CONFIG = {
+ "x_min": -3,
+ "x_max": 5,
+ "y_min": -1,
+ "y_max": 5,
+ "graph_origin": 2*RIGHT+DOWN,
+ "function_color": RED,
+ "axes_color": BLUE,
+ "x_axis_label": "$|z|$",
+ "y_axis_label": "$|X(n)|$",
+ "x_labeled_nums": range(-3, 6, 1),
+ "x_axis_width": 6,
+ "y_axis_height": 5
+ }
+ def setup(self):
+ GraphScene.setup(self)
+ MovingCameraScene.setup(self)
+
+ def construct(self):
+ x_each_unit = self.x_axis_width / (self.x_max - self.x_min)
+ y_each_unit = self.y_axis_height / (self.y_max - self.y_min)
+
+ coeff=TextMobject("$\\frac { 1 }{ (1-\\frac { 1 }{ 2z } ) } $").scale(0.4).shift(self.graph_origin+x_each_unit*RIGHT*2+UP*y_each_unit).set_color(RED)
+ self.setup_axes(scalee=0.6)
+ graph=self.get_graph(lambda x:1/(1-(1/(2*x))),x_min=0.63,x_max=5,color=GREEN)
+
+ self.add(graph)
+ self.add(coeff)
+
+ self.play(ApplyMethod((self.axes).shift,3*LEFT),ApplyMethod(coeff.shift,3*LEFT),ApplyMethod(graph.shift,3*LEFT))
+ self.wait(1)
+
+ dashLine=DashedLine(start=self.graph_origin+3*LEFT+0.5*x_each_unit*RIGHT,end=self.graph_origin+3*LEFT+0.5*x_each_unit*RIGHT+y_each_unit*UP*5,color=YELLOW)
+ pt=TextMobject("0.5").scale(0.3).shift(self.graph_origin+3*LEFT+0.5*x_each_unit*RIGHT+DOWN*y_each_unit*0.3)
+ self.play(Write(dashLine))
+ self.play(Write(pt))
+ self.wait(0.6)
+ rectRegion=Rectangle(height=y_each_unit*5,width=x_each_unit*5,fill_color=WHITE,fill_opacity=0.3,opacity=0.3,color=BLACK).shift(1.6*RIGHT*x_each_unit+0.5*DOWN*y_each_unit+1.5*UP)
+ self.play(ShowCreation(rectRegion))
+ text=TextMobject("Region Of Convergence!").scale(0.4).shift(4.6*RIGHT+1.5*UP).set_color(GREEN)
+ self.play(FadeIn(text))
+ self.wait(2)