Quiz Prep

| categories: Quiz Prep

Practice for this week's quiz and for the final exam.

Write functions to solve at least 3 of the following 5 challenges.

  1. Function twomin(x) should take a vector x of numbers, find the two smallest, and return them in a list result being careful to properly handle duplicated items. For example twomin(np.array([1,2,1,3,4]) should return [1,1].
  2. Function dist(p,Q) that takes a point p represented as a 1×d row vector, and a list of n points Q, represented as an n×d matrix, and returns an n×1 vector of the distance from point p to each point q[i,:].
  3. Function pairdist(p,q) that takes two matrices, say m×d and n×d, and returns the m×n matrix of distances between all pairs of rows.
  4. Function isPrime(n) returns True if the number N is prime, False otherwise.
  5. Function isPalindrome(s) returns True if the string s is a palindrome (same read left to right as right to left), False otherwise.