The program derivative.cc uses three different formulas for approximating the derivative. Three functions (sin(x), log(x), and 1 + x + x3) are built into the program (note: the third function wasn't in the version handed out in class). The three formulas are:
Save the program to your directory either by clicking on the link or using the Unix copy command to copy to your current directory:
cp ~cpsc/public_html/Spring2012/CPSC402A/derivative.cc .The command to compile is:
g++ derivative.cc or g++ derivative.cc -o diffThe first command puts the executable in a file named a.out while the second puts it in a file named diff (you can substitute any name here).
To run the program type:
./a.out or ./diffdepending on what you named the executable.
Run the program as directed below and answer the questions in the book. Also observe the differences in the approximations! You can get a printout to use to answer the question. To do that use script. Recall that you just type script or script filename at the command prompt. Then all output from your commands is put in a logfile named typescript (if you didn't give a filename) or the filename you used. Type exit when you are done.