File tree Expand file tree Collapse file tree
doc/Programs/LecturePrograms/programs/IntroProgramming/cpp Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ std::ofstream ofile;
1212int main (int argc, char * argv[])
1313{
1414 char *outfilename;
15- double derivativex[ 1000 ] ;
15+ double derivative ;
1616 // Read in output file, abort if there are too few command-line arguments
1717 if ( argc <= 3 ){
1818 std::cout << " Bad Usage: " << argv[0 ] <<
Original file line number Diff line number Diff line change 1+ #include < iostream>
2+ #include < cmath>
3+ #include < fstream>
4+ #include < iomanip>
5+ // Note: not using namespace for std
6+
7+ // Begin of main program
8+
9+ int main (int argc, char * argv[])
10+ {
11+ double derivative;
12+ // Read in output file, abort if there are too few command-line arguments
13+ if ( argc <= 2 ){
14+ std::cout << " Bad Usage: " << argv[0 ] <<
15+ " read number of integration points" << std::endl;
16+ exit (1 );
17+ }
18+ // extracting number of mesh points
19+ int i = atoi (argv[1 ]);
20+ double x = atof (argv[2 ]); // reading x-value
21+ double h = 1.0 /((double ) i); // setting up step size
22+ double Derivative = (exp (x+h)-2 .*exp (x)+exp (x-h))/(h*h);
23+ double RelativeError = log10 (fabs (Derivative-exp (x))/exp (x));
24+ std::cout << std::setw (15 ) << std::setprecision (8 ) << " relative error=" << RelativeError << std::endl;
25+ return 0 ;
26+ }
27+
You can’t perform that action at this time.
0 commit comments