dmkozyrev

diff.cpp

Dec 2nd, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     vector<pair<double, double>> f;
  9.     f.push_back(pair<double, double>(1.0, 0.0));
  10.     f.push_back(pair<double, double>(1.5, 0.40547));
  11.     f.push_back(pair<double, double>(2.0, 0.69315));
  12.     f.push_back(pair<double, double>(2.5, 0.91629));
  13.     f.push_back(pair<double, double>(3.0, 1.0986));
  14.    
  15.     for (auto & p : f) {
  16.         cout << p.first << "\t" << p.second << endl;
  17.     }
  18.    
  19.     double x1 = f[2].first;
  20.     double y1 = f[2].second;
  21.    
  22.     double x0 = f[1].first;
  23.     double y0 = f[1].second;
  24.    
  25.     double x2 = f[3].first;
  26.     double y2 = f[3].second;
  27.    
  28.     cout << "first order:" << endl;
  29.     cout << "\tleft:\t y'(t) = "    << (y1 - y0) / (x1 - x0) << endl;
  30.     cout << "\tright:\t y'(t) = "   << (y2 - y1) / (x2 - x1) << endl;
  31.     cout << "\tcenter:\t y'(t) = "  << (y2 - y0) / 2 / (x2 - x0) << endl;
  32.    
  33.     cout << "second order:" << endl;
  34.     // cout << "\tleft:\t y'(t) = "    << (y1 - y0) / (x1 - x0);
  35.     // cout << "\tright:\t y'(t) = "   << (y2 - y1) / (x2 - x1);
  36.     cout << "\tcenter:\t y''(t) = "  << (y2 - 2*y1 + y0) / pow((x2 - x0), 2) << endl;
  37.     return 0;
  38. }
Add Comment
Please, Sign In to add comment