Continuity/ Piecewise Functions in Sagemath

To understand continuity, Sagemath is the best tool to demonstrate it. Just see the plots of piecewise functions and you will come to know whether it is continuous or not.

Continuous Functions :- A function is said to be continuous on an interval when the function is defined at every point on that interval and undergoes no interruptions, jumps, or breaks. If some function f(x) satisfies these criteria from x=a to x=b, for example, we say that f(x) is continuous on the interval [a, b]. The brackets mean that the interval is closed — that it includes the endpoints a and b. In other words, that the interval is defined as a ≤ x ≤ b. An open interval (a, b), on the other hand, would not include endpoints a and b, and would be defined as a < x < b.

To think of it another way, if you can trace a function on an interval without picking up your pen (and without running over any holes), the function is continuous on that interval.

Q:- 1

1) Plot x2 from x=0 to x=1
2) Plot -x+2 from x=1 to x=2
3) Plot x2-3*x+2 from x=2 to x=3
4) Create a black point at (0, 0)
5) Create another black point at (3, 2)
6) Combine the plots and points into a single graph with the given bounds

Sage Code to plot it is:

p1 = plot(x^2, x, 0, 1)
p2 = plot(-x+2, x, 1, 2)
p3 = plot(x^2-3*x+2, x, 2, 3)
pt1 = point((0, 0), rgbcolor='black', pointsize=30)
pt2 = point((3, 2), rgbcolor='black', pointsize=30)
(p1+p2+p3+pt1+pt2).show(xmin=0, xmax=3, ymin=0, ymax=2)

Output is:

As you can see, the function travels from x=0 to x=3 without interruption, and since the two endpoints are closed (designated by the filled-in black circles), f(x) is continuous on the closed interval [0, 3].

Q:-2

1) Plot 2*x from x=0 to x=1
2) Plot -x+3 from x=1 to x=2
3) Plot -(x-3)+2 from x=2 to x=3
4) Create a dashed line to indicate that the function jumps to a y-value of 3 when x is equal to 1
5-10) Create open (faceted) or closed (filled-in) points to indicate whether the intervals are open or closed
11) Combine the plots, line, and points into a graph with the given bounds

Sage code is:

p1 = plot(2*x, x, 0, 1)
p2 = plot(-x+3, x, 1, 2)
p3 = plot(-(x-3)^3+2, x, 2, 3)
l1 = line([(1, 2.1), (1, 2.9)], linestyle='--')
pt1 = point((0, 0), rgbcolor='black', pointsize=30)
pt2 = point((1, 2), rgbcolor='white', faceted=True, pointsize=30)
pt3 = point((1, 3), rgbcolor='black', pointsize=30)
pt4 = point((2, 1), rgbcolor='black', pointsize=30)
pt5 = point((2, 3), rgbcolor='white', faceted=True, pointsize=30)
pt6 = point((3, 2), rgbcolor='black', pointsize=30)
(p1+p2+p3+l1+pt1+pt2+pt3+pt4+pt5+pt6).show(xmin=0, xmax=3, ymin=0, ymax=3)

Output  is:

The function shown in the graph is not continuous on the closed interval [0, 3], since it has discontinuities at both x=1 and x=2. A discontinuity is any x-value at which a function has an interruption, break or jump — something that would require you to pick up your pen if you were tracing the function. The filled-in black circles, again, indicate that the interval includes that point, while the open circles indicate that the interval excludes that point. The dashed line at x=1 shows that f(1) = 3.

Q:- 3

Sage Code:

# exp() means 'e to the ___'
p1 = plot(exp(x/5)-1, x, 0, e)
p2 = plot(ln(x), x, e, e^2)
pt1 = point((0, 0), rgbcolor='black', pointsize=30)
pt2 = point((e, exp(e/5)-1), rgbcolor='black', pointsize=30)
pt3 = point((e, 1), faceted=True, rgbcolor='white', pointsize=30)
pt4 = point((e^2, 2), rgbcolor='black', pointsize=30)
(p1+p2+pt1+pt2+pt3+pt4).show(ymin=0, ymax=2)

Output is:

The function is not continuous on the closed interval [0, e²], as it has a discontinuity at x=e

# exp() means 'e to the ___'
p1 = plot(exp(x/5)-1, x, 0, e)
p2 = plot(ln(x), x, e, e^2)
pt1 = point((0, 0), rgbcolor='black', pointsize=30)
pt2 = point((e, exp(e/5)-1), rgbcolor='black', pointsize=30)
pt3 = point((e, 1), faceted=True, rgbcolor='white', pointsize=30)
pt4 = point((e^2, 2), rgbcolor='black', pointsize=30)
(p1+p2+pt1+pt2+pt3+pt4).show(ymin=0, ymax=2)
Advertisements

About Priyanka Kapoor

Simple, Hardworking & friendly.....
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s