summaryrefslogtreecommitdiff
path: root/FSF-2020/calculus/intro-to-calculus/riemann-integrals/mimi.py
blob: 2471c875355254423d8ccb2fd267d2e5de7241db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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)