Math/CSE 1560 Lab 6

Exercise: Writing for-loops in Maple

Objective
The objective of this exercise is to test your familiarity with solving problems using for-loops in Maple.

Grading
This lab exercise is worth 10% 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. No printouts will be accepted.

Starting off:

  1. 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.
  2. On the first 2 lines, enter your name and student number as comments -- start the lines with character #. Then save the file as `lab6.mw` by clicking on `File` and then `save as`.

Problems
Note: Some of these problems can be solved using seq() or map(), For this assignment you must use for-loops instead.

  1. (4 points) Write a procedure that takes a list and returns a list containing the odd numbered elements of the list given. For example, when called on the list [1,2,3,4,5] it should return [1,3,5].
    Test your program with an odd length list and an even length list.
  2. (4 points) Write a procedure that takes a list of numbers and returns a list of indices i satisfying L[i]>L[i-1]+1.
  3. (4 points) Write a procedure that takes a list and returns a list containing outliers. For this question, we define outliers as those elements that lie outside the range [0.5*mean,1.5*mean]. Write your own code to find the mean.
    For example, consider L=[1,2,3,6]. Then the mean is 3. So outliers are numbers less than 1.5 or higher than 4.5. Thus the outliers are 1 and 6.
  4. (4 points) Let us define a list to be square if it is of even kength and the first half is identical to the second half. For exmple [1,2,1,2] is a square list but [1,2,3,1,2] is not. Write a procedure that takes a list and returns true if the list is square and false otherwise. You should not use seq() or an additional list.
  5. (4 points) Write a procedure that takes a list and a positive integer n and returns a list containing n concatenated copies of the given list.
    For example, when called on the list [1,2,3,4] and n=3, it should return [1,2,3,4,1,2,3,4,1,2,3,4].

Final steps

  1. Save your worksheet.
  2. Submit the assignment as lab 6 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.