Practice
The factorial operation for an integer N involves computing the product of all numbers from 1 to N. Thus, 5! = 5*4*3*2*1. We can approach writing a program to compute the factorial operation in two ways: (1) an iterative approach, where one defines the full set of numbers to be multipled and then carries out the multiplication one step at a time; and (2) a recursive approach, where a function is written that will call itself to do the computation. Examples of these two approaches, for computation of the Fibonacci Sequence, were presented in Lecture.
For practice, let's prepare a script for each of these approaches. First write a script for the iterative approach that prompts the user for the value, N, and returns the result. Then write a MATLAB function that takes the value N as its argument and calls itself, recursively, to compute the factorial result.
Assignment
Implement the bisector search algorithm to find the value of the root of cosine in the domain 0 to 3. In Lecture we provided the basic algorithm implemented in MATLAB. Your assignment here is to write a script that will carry out this search for the specific case of cosine in the region specified (0 to 3). Be sure to check the value derived against the known value (pi/2).
The name of the program file should be something like exercise5.m so that it can be distinguished from other submissions.
Please write your name in a comment field near the beginning of the script.
Copy your completed program into the directory ~schloerb/ph281/username, where username is your user name. See this link for examples of how to copy a file to this directory.