Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- using namespace std;
- int main() {
- vector<pair<double, double>> f;
- f.push_back(pair<double, double>(1.0, 0.0));
- f.push_back(pair<double, double>(1.5, 0.40547));
- f.push_back(pair<double, double>(2.0, 0.69315));
- f.push_back(pair<double, double>(2.5, 0.91629));
- f.push_back(pair<double, double>(3.0, 1.0986));
- for (auto & p : f) {
- cout << p.first << "\t" << p.second << endl;
- }
- double x1 = f[2].first;
- double y1 = f[2].second;
- double x0 = f[1].first;
- double y0 = f[1].second;
- double x2 = f[3].first;
- double y2 = f[3].second;
- cout << "first order:" << endl;
- cout << "\tleft:\t y'(t) = " << (y1 - y0) / (x1 - x0) << endl;
- cout << "\tright:\t y'(t) = " << (y2 - y1) / (x2 - x1) << endl;
- cout << "\tcenter:\t y'(t) = " << (y2 - y0) / 2 / (x2 - x0) << endl;
- cout << "second order:" << endl;
- // cout << "\tleft:\t y'(t) = " << (y1 - y0) / (x1 - x0);
- // cout << "\tright:\t y'(t) = " << (y2 - y1) / (x2 - x1);
- cout << "\tcenter:\t y''(t) = " << (y2 - 2*y1 + y0) / pow((x2 - x0), 2) << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment