If you have not already done so, create a directory for this lab and copy the lab 1 files into it. If you start off in your home directory you can do the following:
mkdir ~/cs371/lab1 cd ~/cs371/lab1 cp ~cs371/lab1/* .and (as with last week) don't forget to type that last period.
Write two similar programs: calc_smallest.m to calculate the smallest representable positive double precision number, and calc_realmax.m to calculate the largest representable double precision number. You can use mach_eps.m from last week as a template. For calc_smallest.m, you might keep dividing a test value by two until some end condition happens, and for calc_realmax.m, you might keep multiplying a test value by two until some end condition happens. You might want to take a look at the finite function in MATLAB for the latter.
Verify calc_realmax against the MATLAB-supplied number. If you have been careful not to use a variable named realmax, then typing that at the MATLAB prompt will return the actual value.
Note: There is a MATLAB value called realmin which will not be the same as the value your calc_smallest.m program returns. I'll explain that at the beginning of lab next week.
One way to approximate pi is to use the fact that arctan(1) = pi/4. Multiplying through by 4 we see that pi = 4*arctan(1). This solution is particularly appealing because the series for arctan(1) is fairly straightforward.
While arctan(1) is also a transcendental value, it has several infinite series representations. We will consider two different series approximations. (I apologize for the ASCII graphics)
Inf --- k arctan(1) = \ (-1) / ------ --- 2k + 1 k=0is due to Gregory (1671) and Leibniz (1674), and arctan(1) = arctan(1/2) + arctan(1/3)
Inf --- 2k+1 2k+1 \ k (1/2) + (1/3) / (-1) --------------------- --- 2k + 1 k=0is due to Hutton (1776).
The program calc_pi.m was prepared for this lab. It is a skeleton which will evaluate two series approximations a number of times and produce two plots: one plot showing the series values after each term and one showing the errors after each term. Using calc_pi.m as a template, add in the required statements (the loop condition and the lines calculating each new element of the series) and then run your program calc_pi. When you are confident that the program works correctly, answer this week's lab questions.
Note: to answer some of the questions you may need to edit calc_pi.m or type things into MATLAB after running it. Make certain that when you're done answering the questions that the file calc_pi.m calculates the Gregory-Leibnitz series to 3 digits of precision and the Hutton series to machine epsilon. Please be sure also that your final program does not generate a lot of clutter on the command window and do not change the commands to generate the plots.
~cs371/submit lab1This is a UNIX program which will copy those files into my directory so I can grade your work. If the script runs successfully, it will print no error messages and say "Files copied successfully." If anything else happens, let me know. When you have completed the questions and turned them in (or e-mailed them) to me, and successfully run the submit program, you are done.