Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- double f (double x)
- {
- return sin (x);
- }
- double derivative (double (*f) (double), double x)
- {
- const double h = 1E-4;
- return (f (x + h) - f (x - h)) / (2 * h);
- }
- double integral (double (*f) (double), double a, double b)
- {
- double Delta = 1E-4, output = 0;
- for (double x = a; x < b - Delta; x += Delta)
- output += Delta * (f (x) + f (x + Delta)) / 2;
- return output;
- }
- int main (int argc, char** argv)
- {
- double x = 0;
- cout << "f (" << x << ") = " << f (x) << endl;
- cout << "f' (" << x << ") = " << derivative (&f, x) << endl;
- cout << "int (f, 0, M_PI) = " << integral (&f, 0, M_PI) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement