Introductory Programming Fall 2006 For today, you should have: 1) written mysum 2) prepared for a quiz Today: 0) splitting sections Proposal: joint meeting Tuesday in auditorium. two sections on Thursday and Friday Friday 9-10; what about Thursday? 1) mysum 2) program development process 3) Evaluation 3 For next time: 1) finish Eval 3 if you don't finish it today 2) work on the exercise below mysum ----- Write a function named mysum that takes a vector as an input variable and that returns the sum of the elements in the vector. function s = mysum(V) total = 0; n = length(V); for i=1:n total = total + V(i); end s = total; end Program development ------------------- Here is a sequence of steps to follow when you write programs: 1) start with a small, simple program that works 2) add a small number of lines of code 3) test the new code; get it working 4) go to step 2 For example, here is a series of steps for mysum: 1) write a function that always returns the value 17, and call your function from the interpreter 2) write a function that takes a vector as an input variable and returns the length of the vector 3) modify the previous function so it loops through the elements of the vector and prints them 4) add a variable named total that accumulates the sum of the values 5) assign the value of total to the output variable 6) add semi-colons to suppress unnecessary output Exercise -------- Write a function named "findit" that takes two input variables, a vector and a target value. Your function should search the vector and return index of the first location where the target value appears in the vector, or -1 if the target value does not appear in the vector.