Engineering 7:
Prof. Alexandre Bayen
Introduction to Programming for Engineers
Spring 2011
Lab 3: Iteration
Date Assigned: 5:00pm, Friday – Feb 11.
Date Due: 5:00pm, Friday – Feb 18.
Note:
Do not write a function that calls other m-files you have written. If you want to call other functions you
have written, write them as subfunctions. For example, in Problem 5.11, you are asked to write a function that
computes numbers that are both Fibonacci and prime. If you wish to write a separate function that computes
only Fibonacci or prime numbers, make them subfunctions of myNFibPrimes.
Problem 1: Do Problem 5.3 in the Reader.
You may assume that A is a one-dimensional array with no duplicate entries and that N is a strictly positive
integer smaller than the length of A.
Test Cases:
>> x = [7,9,10,5,8,3,4,6,2,1];
>> M = myNMax(x, 3)
M =
10
9
8
Problem 2:
Write a function with header
[Q] = myTrigOddEven(M)
where Q(i,j) = sin(
π
/M(i,j)) if M(i,j) is
odd, and Q(i,j) = cos(
π
/M(i,j)) if M(i,j) is even. You may assume that M is a two-dimensional matrix of strictly
positive integers.
Test Cases: