In addition to defining a function in a standard way, a fast and convenient way to turn a formula (an expression) into a function is to use unapply command (check Maple help center for this command). The following items are about defining functions.
- Define a function midpoint, which returns the average of two arguments given on input. For example, midpoint(2,3) returns 2.5, midpoint(a,b) returns 𝑎+𝑏2.
- b) For two positive natural numbers 𝑎 and 𝑏 we can define the least common multiple lcm(𝑎,𝑏) via their greatest common divisor gcd (𝑎,𝑏), i.e.: lcm(𝑎,𝑏) = 𝑎𝑏gcd (𝑎,𝑏). When 𝑎 and/or 𝑏 are zero, lcm(𝑎; 𝑏)=0. Use the arrow operator and piecewise to define the function my_lcm which returns the least common multiple of two natural numbers.
- c) The quadratic formula allows to write the roots of 𝑝 = 𝑎𝑥2+𝑏𝑥+𝑐 explicitly in terms of 𝑎,𝑏, and 𝑐.