Math/CSE 1560 Lab 4

Exercise: Writing procedures in Maple

Objective
The objective of this exercise is to test your familiarity with writing your own proceduires in Maple.

Grading
This lab exercise is worth 5% of the course. It is meant to be completed in the lab, individually (Collaboration is NOT allowed for this exercise).

NOTE: This is a 2 hour lab. The submission server will close shortly after 4:30 pm. You will not be able to submit your work after that time.

Starting off:

  1. Log in to a Gauss lab (aka AML) computer. If you have trouble, ask a system support staff. The TA will not be able to help you wih account/login/password issues.
  2. Open Maple 12 by clicking on the icon marked as such. If Maple does not start, let the TA know immediately. If asked, choose to start a new worksheet.
  3. You should now see the standard 2-d or math view of Maple.
  4. On the first 2 lines, enter your name and student number as comments -- start the lines with character # to indicate to Maple that these are not to be interpreted as Mathematical statements. Then save the file as`lab4.mw` by clicking on `File` and then `save as`.

Problems

  1. (2 points) Write a procedure printPair that takes 2 inputs m,n and prints the following sentence -- you entered m and n. So printPair(5,6) should result in the statement "You entered 5 and 6". Do not worry if you have some quotation marks in the output of your procedure.
  2. (2 points) Write a procedure myIquo that takes 2 numbers and computes their integer quotient. Thus your procedure should have the same functionality as the Maple function iquo, but you must write this without using iquo() in any way. Hint: Use the trunc function.
  3. (2 points) Write a procedure myPrime that takes one input and returns 2 if the input is prime and 3 otherwise. Do not use if-then.
  4. (4 points) Write a procedure only1prime that takes two inputs and returns 1 if exactly one of the inputs is a prime number and 0 otherwise. Do not use if-then or isprime(). Use myPrime from the previous question.
  5. (2 points) Write a procedure largerNum that takes 2 integers and returns the larger number. Do not use if-then, or the Maple max() function.
  6. (2 points) Write a procedure largerNum4 that takes 4 inputs and returns the largest number. Do not use piecewise, max or if-then. Hint: use largerNum.
  7. (2 points) Write a procedure isInteger that takes a single input and returns 1 if the input is an integer and 0 otherwise. You may use the "frac" function in Maple. Do not use if-then or type().
  8. (4 points) Write a procedure powerOf2 that takes a single input and returns 1 if the input is a power of 2 and 0 otherwise. Do not use if-then. You may use the log2() function if you like. If you wish to do so, first check its syntax by typing ?log2. Or try it out by typing "with(MTM): log2(3)" (do not enter the double quotes in Maple).

Final steps

  1. Save your worksheet.
  2. Submit the assignment as lab 4 in Moodle (the URL is moodle.math.yorku.ca - NOTE: there is no "www" in the URL). You can upload several times, but remember to submit using the "send for marking" at the end ONCE - otherwise it may not be sent.
  3. You are done with this assignment! Remember to logout before you leave the lab.