Dr. Straight's Maple Examples Example II: Calculus Operations and Functions Functions Covered: diff, dsolve, implicitdiff, implicitplot, int, limit, odeplot, piecewise, plot, solve, subs, sum, taylor Let's begin by evaluating several limits. sqrt x2 C4 K2 O limit , x=0 ; 2 x O limit O limit 1 4 (1) 0 (2) e (3) 3 (4) 1Kcos t , t=0 ; t 1C 1 n n , n =N ; 3 O limit 6 x C5 , x=N ; 2 x C7 x2 C9 x C11 3 Let's investigate the vertical and horizontal asymptotes of f(x) = sqrt(4x2 + 3)/(2x - 1). 2 sqrt 4$x C3 O f d x/ ; 2$x K1 f := x/ O limit f x , x = O limit f x , x = 1 , left ; 2 1 , right ; 2 4 x2 C3 2 x K1 (5) KN (6) N (7) K1 (8) O limit f x , x =KN ; O limit f x , x = N ; 1 (9) Thus, the line x = 1/2 is a vertical asymptote and the lines y = -1 and y = 1 are horizontal asymptotes. Next, we use the piecewise command to define a "piecewise" function and investigate its continuity at x = 1. O g d x/piecewise x ! 1, 3$x C1, x R 1, 5 Kx2 ; g := x/piecewise x ! 1, 3 x C1, 1 % x, 5 Kx2 (10) O g 1 ; 4 (11) O limit g x , x = 1, left ; 4 (12) 1 O limit g x , x = 1, right ; (13) 4 Therefore, g(x) is continuous at x = 1. A more detailed discussion of the plot command is coming up later; for now, I want to plot y = g(x) to make sure the piecewise command is working as expected. O plot g x , x =K3 ..5 ; K3 K2 0 K1 1 2 3 4 5 x K5 K10 K15 K20 The diff function is used for differentiation. Here are a couple of simple examples: O diff 5$x3 C4$x2 C7, x ; 15 x2 C8 x (14) O diff tan x , x ; 1 Ctan x 2 (15) O simplify % ; 1 (16) cos x 2 Apparently, Maple has something against the secant function. Also, be careful! When Maple says tan(x)2 it means (tan x)2, not tan(x2). 2 One can also use the differentiation template found on the "Expression" palette: d 2 O tan x ; dx 2 2 tan x 1 Ctan x I don't like Maple's syntax for higher-order derivatives; I prefer to iterate diff: 2 O diff diff sin x , x , x ; 2 2 2 cos x K2 sin x or 2 d O sin x ; d x2 Ksin x The diff function is also used for partial differentiation: 3 2 y O f d x, y /x Cx $y Ce ; f := x, y /x3 Cx2 y Cey O diff f x, y , x ; 3 x2 C2 x y O diff f x, y , y ; x2 Cey O diff diff f x, y , y , x ; 2x or O v vx v f x, y vy (17) (18) (19) (20) (21) (22) (23) ; (24) 2x or O v2 f x, y ; vxvy 2x (25) Look above at the graph of y = g(x). It appears that g(x) is not differentiable at x = 1. Let's see what Maple says. O g x ; 3 x C1 x !1 (26) 5 Kx2 1 %x O diff g x , x ; 3 x !1 undefined x=1 K2 x 1 !x (27) Cool! To perform implicit differentiation, use the implicitdiff function. For example, suppose we want to find the slope of the line tangent to the ellipse x2 + 4y2 = 25 at the point (3,-2). We first use implicitdiff to get dy/dx: 3 2 2 O implicitdiff x C4$y = 25, y, x ; 1 x (28) 4 y We then substitute x = 3 and y = -2 into this expression to get the slope m of the tangent line: O subs x = 3, y =K2 , % ; 3 (29) 8 So, the equation of the tangent line is 3x - 8y = 25. Again, a more detailed discussion of graphing is a "coming attraction," but let's use the implicitplot command to graph the ellipse and the tangent line. 2 2 O with plots : implicitplot x C4$y = 25, 3$x K8$y = 25 , x =K3 ..9, y =K4 ..2 ; K 2 1 0 K2 2 4 6 8 x K1 y K2 K3 K4 Note that this command is in the "plots" package, so we need to open the package before invoking the command. Let's move on to integration. To integrate something, we use the int function. There are two forms, one for indefinite integration, the other for definite integration. Here are some examples: 1 O int ,x ; 2 2 a Cx ln x C a2 Cx2 4 (30) Note that Maple doesn't bother with the "plus a constant." 1 O int , x = 0 ..4 ; 9 Cx2 1 2 K K6 ln 2 C2 ln 3 π C2 π ln 9 8 (31) π Why did Maple get such a weird answer? I don't know, but let's try simplifying it: O simplify % ; ln 3 That's better! We can also integrate using the templates provided on the "Expression" palette: 1 O dx; 2 2 a Cx x arctan a a (32) (33) 3 1 O 2 1 Cx 0 dx; 1 π 3 (34) π (35) Maple can even handle improper integrals: Kx2 , x =KN ..N ; O int e 1 1 O 0 dx; x (36) 2 Maple's good, but it can't do everything. For example: O int 1 Cln x , x = 1 ..2 ; 1 1 K1 K I eK1 π erf I C2 ln 2 C1 C I eK1 π erf I ln 2 C1 (37) 2 2 "erf" is the "error function." If Maple is unable to evaluate a definite integral exactly, ask yourself if you would be happy with an approximation. If so, you can apply evalf to your int: O evalf int 1 Cln x , x = 1 ..2 ; 1.174326172 (38) or give the limits of integration as type "float:" O int 1 Cln x , x = 1.0 ..2.0 ; 1.174326172 (39) Either way, Maple will perform "numeric" integration to find an approximation. I don't like Maple's syntax for multiple integrals. Instead, I recommend using the integral template to get what you want. 5 2 3 2 2 25 Kx K4$y O dx dy; 0 0 (40) 100 π 4 cos 2 θ O r dr dθ; π 0 K 4 1 π (41) 8 In an earlier example, we saw the sum function in action. In calculus, we consider infinite sums, or "infinite series." The sum function can be used to determine whether a series converges or not. Here are some well-known convergent series: n 1 O sum , n = 0 ..N ; 2 2 (42) 1 O sum 2 , n = 1 ..N ; n 1 2 π (43) 6 O sum n C1 K1 n , n = 1 ..N ; (44) ln 2 What happens if we enter a divergent series, such as the harmonic series? 1 O sum , n = 1 ..N ; n N (45) Maple says: divergent! The taylor function is used for Taylor series. Specifically, taylor(f(x),x=a,n) returns the Taylor polynomial of degree n - 1 for f(x) about x = a. Here are some examples: O taylor ex, x = 0, 5 ; 1 2 1 3 1 4 1 Cx C x C x C x CO x5 2 6 24 O taylor ln x , x = 1, 6 ; 1 1 1 1 x K1 K x K1 2 C x K1 3 K x K1 4 C x K1 5 CO 2 3 4 5 O taylor sin x , x = 0, 11 ; 1 3 1 1 1 xK x C x5 K x7 C x9 CO x11 6 120 5040 362880 1 3 1 1 1 O h d x/x K x C x5 K x7 C x9; 6 120 5040 362880 1 3 1 1 1 5 h := x/x K x C x K x7 C x9 6 120 5040 362880 6 x K1 6 (46) (47) (48) (49) π ; 6 3 5 7 9 1 1 1 1 1 πK π C π K π C π 6 1296 933120 1410877440 3656994324480 O evalf % ; 0.5000000003 O h O evalf sin π 6 (50) (51) ; 0.5000000000 (52) Powerful stuff! To solve differential equations, we employ the dsolve function. This is not my area of expertise, so I'll be brief, and encourage others to add their "two cents." For our first example, we solve the first-order ODE dy/dt = y - t2 + 1 subject to the initial condition y(0) = 1/2: 1 2 O dsolve diff y t , t = y t Kt C1, y 0 = ; 2 1 t y t = 1 C2 t Ct2 K e (53) 2 For this initial-value problem, Maple was able to obtain an exact solution. But, if not, we could ask Maple to solve the ODE numerically, storing the solution in soln: 1 2 O soln d dsolve diff y t , t = y t Kt C1, y 0 = , numeric ; 2 soln := proc x_rkf45 ... end proc (54) We can then plot the solution using the odeplot command: O with plots : odeplot soln, t, y t , t = 0 ..2 ; 7 5 4 y 3 2 1 0 0.5 1 t 1.5 2 Since that worked out, let's try solving the second-order equation y'' + y' = t + 2, subject to the initial conditions y(0) = 1 and y'(0) = 0: d2 d O diffeq d y t C y t = t C2; 2 dt dt d2 d diffeq := 2 y t C y t = t C2 (55) dt dt O dsolve diffeq ; 1 2 y t = t KeKt _C1 Ct C_C2 (56) 2 Note that we get the general solution: y = t2/2 - ae-t + t + b. To get a particular solution, we need some initial conditions. O initcond d y 0 = 1, D y 0 = 0; initcond := y 0 = 1, D y 0 = 0 (57) O dsolve diffeq, initcond ; 1 2 y t = t CeKt Ct (58) 2 O 8
© Copyright 2026 Paperzz