Skip to content

Commit 42e9ccf

Browse files
committed
cleanng up
1 parent 5c99743 commit 42e9ccf

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

doc/Programs/LecturePrograms/programs/IntroProgramming/cpp/derivnofile.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,17 @@
88

99
int 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

0 commit comments

Comments
 (0)