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 quotes in the output of your procedure.
  2. (2 points) Write a procedure myProduct that takes 2 numbers and computes their product.
  3. (2 points) Write a procedure myPrime that takes one input and returns 1 if the input is prime and 0 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 smallerNum that takes 2 integers and returns the smaller number. Do not use if-then.
  6. (2 points) Write a procedure smallerNum4 that takes 4 inputs and returns the smallest number. Do not use piecewise or if-then. Hint: use smallerNum.
  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 "type" function in Maple. Do not use if-then.
  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. You may use the log2() function if you like. If you wish to do so, first check its syntax 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). 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.