Question
In class a while back we wrote a program that estimates the value of using numerical integration. The program we wrote in class performed the
In class a while back we wrote a program that estimates the value of using numerical integration. The program we wrote in class performed the integration by summing areas from left to right, but one could also sum areas from right to left, which might change the result.1For this problem your mission is to write a C program that explores how the accuracy of the estimate varies with the number of ``slices'' and whether the two methods (left-to-right and right-to-left) produce different results. More specifically, your program should take as input a file containing different values for this number of slices and produce a file containing, for each input value, the input value and two output values, one for left-to-right and one for right-to-left, with each the absolute value of the difference between the estimated value of and the best-available value of as produced by acos(-1.0).
The program should get the names of the input and output files from its command-line arguments (not by prompting the user as most of our programs have done) and should print appropriate error messages if fewer than two command-line arguments are given or if it cannot open the specified files. It should also print appropriate error messages if the input file contains anything other than positive integers. (Probably it should also check that the input values are in ascending order, but you don't need to do that.)
So for example if file estimate-pi-in.txt contains the following:
10000 20000 30000 40000
calling the program with the command
./a.out estimate-pi-in.txt estimate-pi-out.txt
should produce a file estimate-pi-out.txt containing the following:
10000 8.3334095180020995031e-10 8.3333073774838339887e-10 20000 2.0833246239249092469e-10 2.0834134417668792594e-10 30000 9.2581942112701653969e-11 9.2588603450849404908e-11 40000 5.2116977400373798446e-11 5.2073012568598642247e-11
For this problem I think you will get best results if you ``print'' (to the output file) the two computed values with %g rather than %f, and in particular it may be useful to say you want more than the default number of significant figures -- I used %22.20g. You should also use more values than I did in the example, and you could consider having each value be twice the preceding one rather than a fixed amount more. Try different choices until you get a set of input that produces output that seems meaningful.
2 20 points) In class a while back we wrote a program that estimates the value of using umarical p integration. The program ww wrote in class performed the integration by summing areas from lelh to right, but one could also sun areas from right to left, which might change the reat For this problem your mission is to write a C r rightu an) produce eseret t i sults. More specit aiy yor peo program that explores bow the atcuracy of the ostimate varies wh the number of slicesand wather the wo methods am should take as input a hle datung dd rent valu" or this naber of shes as prodce a na du tanng 1 h pe value velbe and two output valos one for left to-right and one for right to-Jefht, with esch the aboolute value of the difference betwoon the estimated value of You will then se gupiat to generete s plot showing the resulting data in graphicel form and the best evailahle value of r as produoed by-. The program should get the sames of the input and output ls from its command ine commardHline arguments are given ce if it cannet open the speciied files. values are in ascending order, but you don't need to do thst.) l ruments (not by prompting the user smest of our programs have donel and should prit appropertate erroe messages wr th It should also print appropriate error messages if the input file costains anything other then positive integers. (Probably t shoud also check thet the input So for example if fke sate i-.et contains the following calling the prsgrum with the command shald produce a fileetei-stt containing the following For this probiem 1 think you will gut best nesults i you lto the output file) the two igures-Id s , You shald also use more vians than 1 dld in the example and you could consider having eack value be twice the preceding one rather tha sgut bat prsuces ouput that seems meaningal values with sg rather than s, and in perticular it mey be usefal to say you want more then the deaul number of significant fisd amount mone. Try differtl you goet a set Turn in your program and, for at east n set of ieput vals (you might wast to try more thas onel The inpt file (the cnn your ogram us as The file of o commends used to creste a Y don't need to turn in your programs outpst file, or the plot, since with the above Lcan crato hnts You should probably start by coping relevant parts ofsampleprupumeaumnus You may find sample program simplee fut.c 2 20 points) In class a while back we wrote a program that estimates the value of using umarical p integration. The program ww wrote in class performed the integration by summing areas from lelh to right, but one could also sun areas from right to left, which might change the reat For this problem your mission is to write a C r rightu an) produce eseret t i sults. More specit aiy yor peo program that explores bow the atcuracy of the ostimate varies wh the number of slicesand wather the wo methods am should take as input a hle datung dd rent valu" or this naber of shes as prodce a na du tanng 1 h pe value velbe and two output valos one for left to-right and one for right to-Jefht, with esch the aboolute value of the difference betwoon the estimated value of You will then se gupiat to generete s plot showing the resulting data in graphicel form and the best evailahle value of r as produoed by-. The program should get the sames of the input and output ls from its command ine commardHline arguments are given ce if it cannet open the speciied files. values are in ascending order, but you don't need to do thst.) l ruments (not by prompting the user smest of our programs have donel and should prit appropertate erroe messages wr th It should also print appropriate error messages if the input file costains anything other then positive integers. (Probably t shoud also check thet the input So for example if fke sate i-.et contains the following calling the prsgrum with the command shald produce a fileetei-stt containing the following For this probiem 1 think you will gut best nesults i you lto the output file) the two igures-Id s , You shald also use more vians than 1 dld in the example and you could consider having eack value be twice the preceding one rather tha sgut bat prsuces ouput that seems meaningal values with sg rather than s, and in perticular it mey be usefal to say you want more then the deaul number of significant fisd amount mone. Try differtl you goet a set Turn in your program and, for at east n set of ieput vals (you might wast to try more thas onel The inpt file (the cnn your ogram us as The file of o commends used to creste a Y don't need to turn in your programs outpst file, or the plot, since with the above Lcan crato hnts You should probably start by coping relevant parts ofsampleprupumeaumnus You may find sample program simplee fut.c
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started