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 88
99int main (int argc, char * argv[])
1010{
11- double derivative;
12- // Read in output file, abort if there are too few command-line arguments
1311 if ( argc <= 2 ){
1412 std::cout << " Bad Usage: " << argv[0 ] <<
15- " read number of integration points " << std::endl;
13+ " read step size and value of x " << std::endl;
1614 exit (1 );
1715 }
1816 // extracting number of mesh points
19- int i = atoi (argv[1 ]);
17+ double h = atof (argv[1 ]);
2018 double x = atof (argv[2 ]); // reading x-value
21- double h = 1.0 /((double ) i); // setting up step size
2219 double Derivative = (exp (x+h)-2 .*exp (x)+exp (x-h))/(h*h);
2320 double RelativeError = log10 (fabs (Derivative-exp (x))/exp (x));
24- std::cout << std::setw (15 ) << std::setprecision (8 ) << " relative error=" << RelativeError << std::endl;
21+ std::cout << std::setw (15 ) << std::setprecision (8 ) << " Log10 of step size= " << log10 (h) << " Log10 of relative error=" << RelativeError << std::endl;
2522 return 0 ;
2623}
2724
You can’t perform that action at this time.
0 commit comments