summaryrefslogtreecommitdiff
path: root/FSF-2020/calculus-of-several-variables/multivariable-functions-and-paritial-derivatives/scalar-functions/file2_domain_range.py
blob: 919e68b60ace7ef52009a81217f7b7f0936926d1 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# Plotting Graphs
from manimlib.imports import *

class PlotGraphs(GraphScene):
    CONFIG = {
    "x_min": -5,
    "x_max": 5,
    "y_min": 0,
    "y_max": 4,
    "graph_origin": ORIGIN + 2.5* DOWN,
    "x_labeled_nums": list(range(-5, 6)),
    "y_labeled_nums": list(range(0, 5)),
    }
    def construct(self):

        topic = TextMobject("Domain and Range")
        topic.scale(2)
        topic.set_color(YELLOW)
        self.play(Write(topic))
        self.play(FadeOut(topic))
        self.wait(1)

        scalar_func_R = TextMobject(r"Scalar Valued Functions in $\mathbb{R}$").scale(1.5).set_color_by_gradient(RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE)
        self.play(Write(scalar_func_R))
        self.play(FadeOut(scalar_func_R))
        self.wait(1)


        XTD = self.x_axis_width/(self.x_max- self.x_min)
        YTD = self.y_axis_height/(self.y_max- self.y_min)

        self.setup_axes(animate = True)

        graphobj = self.get_graph(lambda x :  np.sqrt(x + 4), x_min = -4, x_max = 5)
        graph_lab = self.get_graph_label(graphobj, label = r"\sqrt{x + 4}")


        rangeline1 = Arrow(self.graph_origin+2.2*YTD*UP+5*XTD*LEFT, self.graph_origin+4.1*YTD*UP+5*XTD*LEFT)
        rangeline2 = Arrow(self.graph_origin+1.7*YTD*UP+5*XTD*LEFT, self.graph_origin+5*XTD*LEFT)
        rangeline1.set_color(RED)
        rangeline2.set_color(RED)

        rangeMsg = TextMobject(r"Range: $y \geq 0$")
        rangeMsg.move_to(self.graph_origin+2*YTD*UP+5*XTD*LEFT)
        rangeMsg.scale(0.5)
        rangeMsg.set_color(YELLOW)

        domainline1 = Arrow(self.graph_origin+0.6*YTD*DOWN+1.2*XTD*LEFT, self.graph_origin+0.6*YTD*DOWN + 4*XTD*LEFT, buff = 0.1)
        domainline2 = Arrow(self.graph_origin+0.6*YTD*DOWN+1.1*XTD*RIGHT, self.graph_origin+0.6*YTD*DOWN + 5.3*XTD*RIGHT, buff = 0.1)
        domainline1.set_color(PINK)
        domainline2.set_color(PINK)

        domainMsg = TextMobject(r"Domain: $x \geq -4$")
        domainMsg.move_to(self.graph_origin+0.6*YTD*DOWN)
        domainMsg.scale(0.5)
        domainMsg.set_color(GREEN)

        domain_subset = TextMobject(r"Domain $\subset \mathbb{R}$", color = PURPLE).scale(0.7).move_to(self.graph_origin+3.5*YTD*UP+2*XTD*RIGHT)
    
        
        self.play(ShowCreation(graphobj))
        self.play(ShowCreation(graph_lab))
        self.wait(1)
        self.play(GrowArrow(rangeline1))
        self.play(GrowArrow(rangeline2))
        self.play(Write(rangeMsg))
        self.wait(1)
        self.play(GrowArrow(domainline1))
        self.play(GrowArrow(domainline2))
        self.play(Write(domainMsg), Write(domain_subset))
        self.wait(3)




class PlotSineGraphs(GraphScene):
    CONFIG = {
    "x_min": -8,
    "x_max": 8,
    "y_min": -1,
    "y_max": 1,
    "graph_origin": ORIGIN,
    "x_labeled_nums": list(range(-8, 9)),
    "y_labeled_nums": list(range(-1, 2)),
    }
    def construct(self):
        


        XTD = self.x_axis_width/(self.x_max- self.x_min)
        YTD = self.y_axis_height/(self.y_max- self.y_min)

        self.setup_axes(animate = True)

        sineobj = self.get_graph(lambda x :  np.sin(x), x_min = -7, x_max = 8)
        sine_lab = self.get_graph_label(sineobj, label = "\\sin(x)")


        rangeline1 = Arrow(8*XTD*LEFT,1*YTD*UP+8*XTD*LEFT, buff = 0)
        rangeline2 = Arrow(8*XTD*LEFT,1*YTD*DOWN+8*XTD*LEFT, buff = 0)
        rangeline1.set_color(RED)
        rangeline2.set_color(RED)

        rangeMsg = TextMobject(r"Range: $-1 \leq y \leq  1$")
        rangeMsg.move_to(1.1*YTD*UP+8.5*XTD*LEFT)
        rangeMsg.scale(0.5)
        rangeMsg.set_color(YELLOW)


        domainline1 = Arrow(1.1*YTD*DOWN+2*XTD*LEFT, 1.1*YTD*DOWN + 8.5*XTD*LEFT)
        domainline2 = Arrow(1.1*YTD*DOWN+2*XTD*RIGHT, 1.1*YTD*DOWN + 8.5*XTD*RIGHT)
        domainline1.set_color(PINK)
        domainline2.set_color(PINK)

        domainMsg = TextMobject(r"Domain: $[-\infty, \infty]$")
        domainMsg.move_to(1.1*YTD*DOWN)
        domainMsg.scale(0.5)
        domainMsg.set_color(GREEN)

        domain_subset = TextMobject(r"Domain $\subseteq \mathbb{R}$", color = PURPLE).scale(0.7).move_to(self.graph_origin+0.8*YTD*UP+4.5*XTD*RIGHT)

        self.play(ShowCreation(sineobj))
        self.play(ShowCreation(sine_lab))
        self.wait(1)
        self.play(GrowArrow(rangeline1))
        self.play(GrowArrow(rangeline2))
        self.play(Write(rangeMsg))
        self.wait(1)
        self.play(GrowArrow(domainline1))
        self.play(GrowArrow(domainline2))
        self.play(Write(domainMsg), Write(domain_subset))
        self.wait(3)


        

        
class Paraboloid(ThreeDScene):
    def construct(self):

        scalar_func_R2 = TextMobject(r"Scalar Valued Functions in $\mathbb{R}^2$").scale(1.5).set_color_by_gradient(RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE)
        self.play(Write(scalar_func_R2))
        self.play(FadeOut(scalar_func_R2))
        self.wait(1)

        axes = ThreeDAxes() 

        paraboloid = ParametricSurface(
            lambda u, v: np.array([
                2*np.sin(u)*np.cos(v),
                2*np.sin(u)*np.sin(v),
                2*2*np.sin(u)*np.sin(u)
            ]),u_min=0,u_max=PI/2,v_min=0,v_max=2*PI,checkerboard_colors=[GREEN_C, GREEN_E],
            resolution=(15, 32)).scale(1)

        domain = Polygon(np.array([-5,-5,0]),np.array([5,-5,0]),np.array([5,5,0]),np.array([-5,5,0]),np.array([-5,-5,0]), color = BLUE_C, fill_color = BLUE_C, fill_opacity = 0.2)
        domain_lab = TextMobject(r"$Domain: \mathbb{R}^2$", color = YELLOW_C).scale(0.7).move_to(1*DOWN + 2*LEFT)
        
        rangef = Line(np.array([0, 0,0]), np.array([0, 0,5]), color = RED_C)
        rangef_lab = TextMobject(r"$Range: z \geq 0$", color = RED_C).scale(0.7).move_to(2*UP + 1.5*RIGHT)

        func = TextMobject(r"$z = f(x,y) = x^2+y^2$").scale(0.7).move_to(3*UP + 4*LEFT).set_color_by_gradient(RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE)
        
        self.set_camera_orientation(phi=60 * DEGREES, theta = 0*DEGREES)
        self.begin_ambient_camera_rotation(rate=0.3)

        self.add(axes)

        axis = TextMobject(r"X",r"Y",r"Z")
        axis[0].move_to(6*RIGHT)
        axis[1].move_to(6*UP)
        axis[2].move_to(np.array([0,0,3.7]))

        self.add_fixed_orientation_mobjects(axis[2])
        self.add_fixed_orientation_mobjects(axis[0])
        self.add_fixed_orientation_mobjects(axis[1]) 



        self.add_fixed_in_frame_mobjects(func)
        self.play(Write(paraboloid))
        self.play(ShowCreation(domain))
        self.add_fixed_in_frame_mobjects(domain_lab)
        self.wait()
        self.play(ShowCreation(rangef))
        self.add_fixed_in_frame_mobjects(rangef_lab)
        self.wait(5)