First download the code and save it in a file called bisection.m in some directory, say in a directory called NUMERICS Then open MATLAB in the directory NUMERICS and type the commands you see in the "diary" file at http://www.math.ou.edu/~npetrov/diary_bisection.txt After you type a command in MATLAB, simply press "return" to execute it. If you type a semicolumn (;) after a command, the computer will execute it, but will not display the output. The command bisection( inline('2/pi*exp(2*x/pi)+(1-exp(1))*cos(x)'), 0.0, pi/2, 1.0e-5, 100, 1) computes and gives as an output the value of a zero of the function f(x)=2/pi*exp(2*x/pi)+(1-exp(1))*cos(x), or, in other words, the value of a solution of the equation 2/pi*exp(2*x/pi)+(1-exp(1))*cos(x) = 0 , in the interval [0,pi/2]. The tolerance (i.e., the precision with which the code will return the root) is 1.0e-5, i.e., 0.00001. If the code cannot find a solution after 100 iterations, it will stop and will return an error message. The last argument is 1, which tells the code to print out the intermediate results. Instead of calling the function f(x) by using the "inline" sintax, you can equivalently save this function in a separate file. Let's decide to call this function "myfunction", then we have to save in a file called myfunction.m (in the same directory as the file bisection.m). The file myfunction.m should look like this (the content of the file is what is between the two lines): ------------------------------------------------------------ function y = myfunction (x) y = 2/pi*exp(2*x/pi)+(1-exp(1))*cos(x); ------------------------------------------------------------ In that file the empty second line is added just to make the file look prettier; removing this line will have no effect. Once you have saved the file myfunction.m, type on the MATLAB command line bisection( 'myfunction', 0.0, pi/2, 1.0e-5, 100, 1) and the output will be the same as from the call of the program "bisection" by using "inline". You can also call the code using a "handle" to the function "myfunction": bisection( @myfunction, 0.0, pi/2, 1.0e-5, 100, 1) . Some things to explore: * Compare the results of the above run with the result of running bisection( 'myfunction', 0.0, pi/2, 1.0e-14, 100, 0) - what is different? * Finally, if you try to execute bisection( 'myfunction', 0.0, pi/2, 1.0e-20, 100, 0) the computer will complain that you are too greedy.