SHARE
TWEET

Untitled

a guest Nov 17th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cfloat>
  3. #include <cmath>
  4. #define N 10
  5.  
  6. using namespace std;
  7.  
  8. double dx = 0.1;
  9. double Y0 = -1;
  10. double yp = 2;
  11.  
  12. class DifferentialEquation{
  13.     double precision;
  14.     double init;
  15.     double derivative;
  16. public:
  17.     DifferentialEquation(double _p, double _i, double _d){
  18.         precision = _p;
  19.         init = _i;
  20.         derivative = _d;
  21.     }
  22.  
  23.     double * calculatingY(){
  24.         double values[N] = {0};
  25.         values[0] = init;
  26.  
  27.         for(int i=1; i<N; i++){
  28.             values[i] = values[i-1] + precision*pow(values[i-1], derivative);
  29.         }
  30.  
  31.         double *result = values;
  32.         return result;
  33.     }
  34. };
  35.  
  36. int main(){
  37.     DifferentialEquation R(dx, Y0, yp);
  38.  
  39.     double *primaryFunc;
  40.     primaryFunc = R.calculatingY();
  41.  
  42.     //for(int i=0; i<N; i++){
  43.     //    cout << primaryFunc[i] << endl;
  44.     //}
  45.     // Nie mam pojęcia dlaczego powyższy zakomentowany sposób wypisania danych daje inne wartości niż poniższy
  46.  
  47.     cout << primaryFunc[0] << endl << primaryFunc[1] << endl << primaryFunc[2] << endl << primaryFunc[3] << endl << primaryFunc[4] << endl << primaryFunc[5] << endl << primaryFunc[6] << endl << primaryFunc[7] << endl << primaryFunc[8] << endl << primaryFunc[9];
  48.  
  49.     return 0;
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top