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 myIrem that takes 2 numbers and computes their integer remainder. Thus your procedure should have the same functionality as the Maple function irem, but you must write this without using irem() in any way. Hint: Use the trunc and or frac function.
  3. (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.
  4. (4 points) Write a procedure TwoLargestNum that takes 3 positive integers as inputs and prints the two largest numbers.
  5. (4 points) Write a procedure that takes an integer or real number, and prints "the input is an integer" if the input is an integer, and prints the square of the input to 5 decimal places if the input is a real number. Do not change the value of the reserved variable "Digits". Test your procedure with an integer and a real number (that is not an integer) to show that it works.
  6. (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().
  7. (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.