diff options
Diffstat (limited to 'FSF-2020/calculus/intro-to-calculus/riemann-integrals')
6 files changed, 230 insertions, 0 deletions
diff --git a/FSF-2020/calculus/intro-to-calculus/riemann-integrals/README.md b/FSF-2020/calculus/intro-to-calculus/riemann-integrals/README.md new file mode 100644 index 0000000..a9ad0bb --- /dev/null +++ b/FSF-2020/calculus/intro-to-calculus/riemann-integrals/README.md @@ -0,0 +1,18 @@ +rierect1.gif +![rierect1](https://user-images.githubusercontent.com/61246381/87141790-3ad90800-c2c1-11ea-86e4-af05cb93fa2d.gif) + + +rierect2.gif +![rierect2](https://user-images.githubusercontent.com/61246381/87141870-5ba15d80-c2c1-11ea-9307-40acc2884d77.gif) + + +rierect3.gif +![rierect3](https://user-images.githubusercontent.com/61246381/87141949-6e1b9700-c2c1-11ea-9433-4f6be752aa55.gif) + + +RiemannRectanglesAnimation. +![RiemannRectanglesAnimation](https://user-images.githubusercontent.com/61246381/87142531-4a0c8580-c2c2-11ea-8f5e-9e854eae6eec.gif) + + +mimi.gif +![mimi](https://user-images.githubusercontent.com/61246381/87142127-b3d85f80-c2c1-11ea-864e-627e41d87ea2.gif) diff --git a/FSF-2020/calculus/intro-to-calculus/riemann-integrals/RiemannRectanglesAnimation.py b/FSF-2020/calculus/intro-to-calculus/riemann-integrals/RiemannRectanglesAnimation.py new file mode 100644 index 0000000..1757231 --- /dev/null +++ b/FSF-2020/calculus/intro-to-calculus/riemann-integrals/RiemannRectanglesAnimation.py @@ -0,0 +1,66 @@ +from manimlib.imports import * +class RiemannRectanglesAnimation(GraphScene): + CONFIG = { + "y_max": 5, + "x_max": 6, + "x_min": 0, + "y_min": 0, + "x_axis_width": 5, + "y_axis_height": 5, + "init_dx":0.5, + "graph_origin": ORIGIN+2*DOWN+6*LEFT, + } + def construct(self): + self.setup_axes() + def func(x): + return 0.1*(x)*(x-3)*(x-7)+3 + + graph1=self.get_graph(func,x_min=0,x_max=6) + kwargs = { + "x_min" : 1.5, + "x_max" : 5.5, + "fill_opacity" : 0.75, + "stroke_width" : 0.25, + "input_sample_type": "right", + } + flat_rectangles1 = self.get_riemann_rectangles(self.get_graph(lambda x : 0),dx=self.init_dx,start_color=invert_color(PURPLE),end_color=invert_color(ORANGE),**kwargs) + riemann_rectangles_list1 = self.get_riemann_rectangles_list(graph1,6,max_dx=self.init_dx,power_base=2,start_color=PURPLE,end_color=ORANGE,**kwargs) + self.add(graph1) + self.graph_origin = ORIGIN+2*DOWN+1*RIGHT + self.setup_axes() + graph2=self.get_graph(func,x_min=0,x_max=6) + kwargs = { + "x_min" : 1.5, + "x_max" : 5.5, + "fill_opacity" : 0.75, + "stroke_width" : 0.25, + "input_sample_type": "left", + } + flat_rectangles2 = self.get_riemann_rectangles(self.get_graph(lambda x : 0),dx=self.init_dx,start_color=invert_color(PURPLE),end_color=invert_color(ORANGE),**kwargs) + riemann_rectangles_list2 = self.get_riemann_rectangles_list(graph2,6,max_dx=self.init_dx,power_base=2,start_color=PURPLE,end_color=ORANGE,**kwargs) + self.add(graph2) + text1 = TextMobject("Left Riemann sum").move_to(np.array([-3,-2.5,0])) + text2 = TextMobject("Right Riemann sum").move_to(np.array([4,-2.5,0])) + grp1 = VGroup(text1, text2) + text3 = TexMobject(r"n \rightarrow \infty").move_to(np.array([0, -3, 0])) + text4 = TextMobject("Left and Right Riemann sums are equal").move_to(np.array([0, -3, 0])) + text5 = TextMobject("Hence function is Riemann integrable and value of integral equals area covered").move_to(np.array([0, -3, 0])).scale(0.6) + grp2 = VGroup(text1, text2, text3) + # Show Riemann rectangles + self.play(ReplacementTransform(flat_rectangles1,riemann_rectangles_list1[0]), ReplacementTransform(flat_rectangles2, riemann_rectangles_list2[0])) + self.wait() + self.play(ShowCreation(grp1)) + for r in range(1,len(riemann_rectangles_list1)-3): + self.transform_between_riemann_rects(riemann_rectangles_list1[r-1],riemann_rectangles_list1[r],replace_mobject_with_target_in_scene = True,) + self.transform_between_riemann_rects(riemann_rectangles_list2[r-1],riemann_rectangles_list2[r],replace_mobject_with_target_in_scene = True,) + self.play(ShowCreation(text3)) + for r in range(len(riemann_rectangles_list1)-3,len(riemann_rectangles_list1)): + self.transform_between_riemann_rects(riemann_rectangles_list1[r-1],riemann_rectangles_list1[r],replace_mobject_with_target_in_scene = True,) + self.transform_between_riemann_rects(riemann_rectangles_list2[r-1],riemann_rectangles_list2[r],replace_mobject_with_target_in_scene = True,) + self.wait(2) + grp3 = VGroup(graph1, riemann_rectangles_list1[5]) + grp4 = VGroup(graph2, riemann_rectangles_list2[5]) + self.play(ReplacementTransform(grp2, text4)) + self.wait(2) + self.play(ReplacementTransform(text4, text5), ApplyMethod(grp4.shift, 7*LEFT), ApplyMethod(self.axes.shift, 7*LEFT), ) + self.wait(4)
\ No newline at end of file diff --git a/FSF-2020/calculus/intro-to-calculus/riemann-integrals/mimi.py b/FSF-2020/calculus/intro-to-calculus/riemann-integrals/mimi.py new file mode 100644 index 0000000..2471c87 --- /dev/null +++ b/FSF-2020/calculus/intro-to-calculus/riemann-integrals/mimi.py @@ -0,0 +1,53 @@ +class mimi(GraphScene): + CONFIG = { + "y_max": 5, + "x_max": 6, + "x_min": 0, + "y_min": 0, + "x_axis_width": 5, + "y_axis_height": 5, + "init_dx":0.5, + "graph_origin": ORIGIN+2*DOWN+6*LEFT, + } + def construct(self): + self.setup_axes() + def func(x): + return 0.1*(x)*(x-3)*(x-7)+3 + + graph=self.get_graph(func,x_min=0,x_max=6) + kwargs = { + "x_min" : 1.5, + "x_max" : 5.5, + "fill_opacity" : 0.5, + "stroke_width" : 0.25, + } + flat_rectangles = self.get_riemann_rectangles(self.get_graph(lambda x : 0),dx=self.init_dx,**kwargs) + riemann_rectangles_list = self.get_riemann_rectangles_list(graph,8,max_dx=self.init_dx,power_base=2,start_color=PURPLE,end_color=ORANGE,**kwargs, input_sample_type = "right") + riemann_rectangles_list1 = self.get_riemann_rectangles_list(graph,8,max_dx=self.init_dx,power_base=2,start_color=PURPLE,end_color=ORANGE,**kwargs, input_sample_type = "left") + self.add(graph) + self.play(ReplacementTransform(flat_rectangles,riemann_rectangles_list[0]), ReplacementTransform(flat_rectangles,riemann_rectangles_list1[0])) + #self.play(ReplacementTransform(flat_rectangles,riemann_rectangles_list1[0])) + self.wait(2) + kwargs = { + "x_min" : 3, + "x_max" : 3.5, + "fill_opacity" : 0.5, + "stroke_width" : 0.25, + } + riemann_rectangles_list2 = self.get_riemann_rectangles_list(graph,8,max_dx=self.init_dx,power_base=2,start_color=PURPLE,end_color=ORANGE,**kwargs, input_sample_type = "right") + riemann_rectangles_list3 = self.get_riemann_rectangles_list(graph,8,max_dx=self.init_dx,power_base=2,start_color=PURPLE,end_color=ORANGE,**kwargs, input_sample_type = "left") + #self.play(FadeOut(riemann_rectangles_list[0]), FadeOut(riemann_rectangles_list1[0])) + self.play(ReplacementTransform(flat_rectangles,riemann_rectangles_list2[0]), ReplacementTransform(flat_rectangles,riemann_rectangles_list3[0]), FadeOut(riemann_rectangles_list[0]), FadeOut(riemann_rectangles_list1[0])) + minlim = self.get_vertical_line_to_graph(3,graph,DashedLine) + maxlim = self.get_vertical_line_to_graph(3.5,graph,DashedLine) + line2 = Line(self.graph_origin+2.5*RIGHT, self.graph_origin+2.9*RIGHT) + brace1 = Brace(minlim, LEFT) + brace2 = Brace(line2, DOWN) + brace3 = Brace(maxlim, RIGHT) + br1text = brace1.get_text(r"${M}_{i}$").next_to(brace1, LEFT) + br2text = brace2.get_text(r"$\Delta x$").next_to(brace2, DOWN) + br3text = brace3.get_text(r"${m}_{i}$").next_to(brace3, RIGHT) + text1 = TexMobject(r"\Delta x=(b-a)/n").shift(2*RIGHT) + grp3 = VGroup(br1text, br2text, br3text, brace1, brace2, brace3, text1) + self.play(ShowCreation(grp3)) + self.wait(5) diff --git a/FSF-2020/calculus/intro-to-calculus/riemann-integrals/rierect1.py b/FSF-2020/calculus/intro-to-calculus/riemann-integrals/rierect1.py new file mode 100644 index 0000000..748d766 --- /dev/null +++ b/FSF-2020/calculus/intro-to-calculus/riemann-integrals/rierect1.py @@ -0,0 +1,31 @@ +from manimlib.imports import * +class rierect1(GraphScene): + CONFIG = { + "y_max" : 6, + "y_min" : 0, + "x_max" : 4, + "x_min" : 0, + "y_tick_frequency" : 1, + "x_tick_frequency" : 1, + "axes_color" : WHITE, + "num_graph_anchor_points": 3000, #this is the number of points that graph manim + "graph_origin" : ORIGIN+2*DOWN+4*LEFT, + "x_labeled_nums": None,#list(range(-1,2)), + "y_labeled_nums": None,#list(range(0,2)), + "x_axis_label":"$x$", + "y_axis_label":"$f(x)$", + "x_axis_width": 10, + "y_axis_height": 5, + } + def construct(self): + self.setup_axes() + graph1 = self.get_graph(lambda x : (0.1*(1.5*x+1)**2 +0.5), x_min = 0, x_max = 4) + minlim = self.get_vertical_line_to_graph(1,graph1,DashedLine, color = PINK) + maxlim = self.get_vertical_line_to_graph(3,graph1,DashedLine,color = PINK) + x1 = TexMobject(r"{x}_{1}").next_to(minlim, DOWN) + x2 = TexMobject(r"{x}_{2}").next_to(maxlim, DOWN) + rie1 = self.get_riemann_rectangles(graph1, x_min = 1, x_max = 3, dx = 0.4, input_sample_type = "left", fill_opacity = 1, start_color = YELLOW, end_color = YELLOW) + #rie2 = self.get_riemann_rectangles(graph1, x_min = 1, x_max = 3, dx = 0.01, input_sample_type = "right", fill_opacity = 0.5, start_color = PINK, end_color = LIGHT_PINK) + group = VGroup(graph1, minlim, maxlim, x1, x2, rie1) + self.play(ShowCreation(group)) + self.wait(1.5) diff --git a/FSF-2020/calculus/intro-to-calculus/riemann-integrals/rierect2.py b/FSF-2020/calculus/intro-to-calculus/riemann-integrals/rierect2.py new file mode 100644 index 0000000..e300250 --- /dev/null +++ b/FSF-2020/calculus/intro-to-calculus/riemann-integrals/rierect2.py @@ -0,0 +1,31 @@ +from manimlib.imports import * +class rierect2(GraphScene): + CONFIG = { + "y_max" : 6, + "y_min" : 0, + "x_max" : 4, + "x_min" : 0, + "y_tick_frequency" : 1, + "x_tick_frequency" : 1, + "axes_color" : WHITE, + "num_graph_anchor_points": 3000, #this is the number of points that graph manim + "graph_origin" : ORIGIN+2*DOWN+4*LEFT, + "x_labeled_nums": None,#list(range(-1,2)), + "y_labeled_nums": None,#list(range(0,2)), + "x_axis_label":"$x$", + "y_axis_label":"$f(x)$", + "x_axis_width": 10, + "y_axis_height": 5, + } + def construct(self): + self.setup_axes() + graph1 = self.get_graph(lambda x : (0.1*(1.5*x+1)**2 +0.5), x_min = 0, x_max = 4) + minlim = self.get_vertical_line_to_graph(1,graph1,DashedLine, color = PINK) + maxlim = self.get_vertical_line_to_graph(3,graph1,DashedLine,color = PINK) + x1 = TexMobject(r"{x}_{1}").next_to(minlim, DOWN) + x2 = TexMobject(r"{x}_{2}").next_to(maxlim, DOWN) + rie1 = self.get_riemann_rectangles(graph1, x_min = 1, x_max = 3, dx = 0.1, input_sample_type = "left", fill_opacity = 1, start_color = YELLOW, end_color = YELLOW) + #rie2 = self.get_riemann_rectangles(graph1, x_min = 1, x_max = 3, dx = 0.01, input_sample_type = "right", fill_opacity = 0.5, start_color = PINK, end_color = LIGHT_PINK) + group = VGroup(graph1, minlim, maxlim, x1, x2, rie1) + self.play(ShowCreation(group)) + self.wait(1.5) diff --git a/FSF-2020/calculus/intro-to-calculus/riemann-integrals/rierect3.py b/FSF-2020/calculus/intro-to-calculus/riemann-integrals/rierect3.py new file mode 100644 index 0000000..3542358 --- /dev/null +++ b/FSF-2020/calculus/intro-to-calculus/riemann-integrals/rierect3.py @@ -0,0 +1,31 @@ +from manimlib.imports import * +class rierect3(GraphScene): + CONFIG = { + "y_max" : 6, + "y_min" : 0, + "x_max" : 4, + "x_min" : 0, + "y_tick_frequency" : 1, + "x_tick_frequency" : 1, + "axes_color" : WHITE, + "num_graph_anchor_points": 3000, #this is the number of points that graph manim + "graph_origin" : ORIGIN+2*DOWN+4*LEFT, + "x_labeled_nums": None,#list(range(-1,2)), + "y_labeled_nums": None,#list(range(0,2)), + "x_axis_label":"$x$", + "y_axis_label":"$f(x)$", + "x_axis_width": 10, + "y_axis_height": 5, + } + def construct(self): + self.setup_axes() + graph1 = self.get_graph(lambda x : (0.1*(1.5*x+1)**2 +0.5), x_min = 0, x_max = 4) + minlim = self.get_vertical_line_to_graph(1,graph1,DashedLine, color = PINK) + maxlim = self.get_vertical_line_to_graph(3,graph1,DashedLine,color = PINK) + x1 = TexMobject(r"{x}_{1}").next_to(minlim, DOWN) + x2 = TexMobject(r"{x}_{2}").next_to(maxlim, DOWN) + rie1 = self.get_riemann_rectangles(graph1, x_min = 1, x_max = 3, dx = 0.01, input_sample_type = "left", fill_opacity = 1, start_color = YELLOW, end_color = YELLOW) + #rie2 = self.get_riemann_rectangles(graph1, x_min = 1, x_max = 3, dx = 0.01, input_sample_type = "right", fill_opacity = 0.5, start_color = PINK, end_color = LIGHT_PINK) + group = VGroup(graph1, minlim, maxlim, x1, x2, rie1) + self.play(ShowCreation(group)) + self.wait(1.5) |