-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex10.cpp
More file actions
31 lines (24 loc) · 728 Bytes
/
Copy pathex10.cpp
File metadata and controls
31 lines (24 loc) · 728 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "ch4it.hpp"
double f(double x){
return 1 - x - exp(-x);
}
double fder(double x){
return -1 + exp(-x);
}
double g(double x){
return tan(x) - x;
}
double gder(double x){
return 1/(cos(x)*cos(x)) - 1;
}
int main(){
double root = newton(1, f, fder, 1e-8, 1e-9);
cout << "Approximate root of f() near 1 is " << root << endl;
cout << "Residual is " << f(root) << endl;
root = newton(4.5, g, gder, 1e-8, 1e-9);
cout << "Approximate root of g() near 4.5 is " << root << endl;
cout << "Residual is " << g(root) << endl;
root = newton(5, g, gder, 1e-8, 1e-9);
cout << "Approximate root of g() near 5 is " << root << endl;
cout << "Residual is " << g(root) << endl;
}