Advertisement
pashaXMorder

Fourier

Jun 20th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <fstream>
  4. #include <cmath>
  5.  
  6. using namespace std;
  7.  
  8. const double PI = 3.1415926535897932384626433832795;
  9. const double step_x = 0.001;
  10. const int max_number = 100;
  11. const double step_t = 0.00001;
  12. const double length = 100;
  13.  
  14. double q_array[max_number];
  15. ////////////////////////////////////////////////////////
  16. //ищем q и в масив
  17. ////////////////////////////////////////////////////////
  18. double f(double x)
  19. {
  20.     return (cos(x) / sin(x)) - x;
  21. }
  22.  
  23. double bissection (int number)
  24. {
  25.     double x_1, x_2, half_x_1_x_2 ;
  26.     x_1 = (number * PI) + step_x;
  27.     x_2 = (number * PI) + PI - step_x;
  28.     while (abs(x_1 - x_2) > step_x) {
  29.         half_x_1_x_2 = (x_1 + x_2) / 2;
  30.         if (f(x_1) * f(half_x_1_x_2) < 0)
  31.             x_2 = half_x_1_x_2;
  32.         else
  33.             x_1 = half_x_1_x_2;
  34.     }
  35.     return abs(x_1 + x_2) / 2;
  36. }
  37.  
  38. void finding_qk () {
  39.     for (int i = 0; i < max_number; i++) {
  40.         ::q_array[i] = 0;
  41.     }
  42.     for (int i = 0; i < max_number; i++) {
  43.         ::q_array[i] = bissection(i);
  44.     }
  45. }
  46.  
  47. double calculate(double q, double x, double t) {
  48.     double result = 0;
  49.     result = (4 / (2 * q + sin(2 * q)))*(sin(q) + 2 * sin(q / 2) * sin(q / 2) / q + 2 * sin(q / 10) * cos(q / 3)) * exp(-t * q * q) * cos(q * x);  
  50.     return result;
  51. }
  52.  
  53. void calculation() {
  54.     double result = 0;
  55.     fstream f;
  56.     ///////////////// 2T
  57.     f.open("C://Users//User//Documents//2T.txt", fstream::trunc | fstream::out);
  58.     for (double j = 0; j < 1; j+= step_x){
  59.         for (int i = 0; i < max_number; i++) {
  60.             result += calculate(q_array[i], j, 2);
  61.         }
  62.         result += -2 + j;
  63.         f << result << endl;
  64.         result = 0;
  65.     }
  66.     f.close(); 
  67.     /////////////////////////
  68.     //////////////////////5T
  69.     f.open("C://Users//User//Documents//5T.txt", fstream::trunc | fstream::out);
  70.     for (double j = 0; j < 1; j += step_x) {
  71.         for (int i = 0; i < max_number; i++) {
  72.             result += calculate(q_array[i], j, 5);
  73.         }
  74.         result += -2 + j;
  75.         f << result << endl;
  76.         result = 0;
  77.     }
  78.     f.close();
  79.     /////////////////////////
  80.     //////////////////////l/3
  81.     f.open("C://Users//User//Documents//l.txt", fstream::trunc | fstream::out);
  82.     for (double j = 0; j < 5; j += step_t) {
  83.         for (int i = 0; i < max_number; i++) {
  84.             result += calculate(q_array[i], (double)1/3, j);
  85.         }
  86.         result += -2 + (double)1/3;
  87.         f << result << endl;
  88.         result = 0;
  89.     }
  90.     f.close();
  91.     /////////////////////////
  92.     //////////////////////T= 0
  93.     f.open("C://Users//User//Documents//0.txt", fstream::trunc | fstream::out);
  94.     for (double j = 0; j < 1; j += step_x) {
  95.         for (int i = 0; i < max_number; i++) {
  96.             result += calculate(q_array[i], j, 0);
  97.         }
  98.         result += -2 + j;
  99.         f << result << endl;
  100.         result = 0;
  101.     }
  102.     f.close();
  103. }
  104.  
  105.    
  106.  
  107. int main() {
  108.     finding_qk();
  109.     calculation();
  110.     fstream f;
  111.     f.open("C://Users//User//Documents//step_x.txt", fstream::trunc | fstream::out);
  112.     for (double i = 0; i < 1; i+=step_x) {
  113.         f << i << endl;
  114.     }
  115.     f.close();
  116.     f.open("C://Users//User//Documents//step_t.txt", fstream::trunc | fstream::out);
  117.     for (double i = 0; i < 5; i += step_t) {
  118.         f << i << endl;
  119.     }
  120.     f.close();
  121.     return 0;
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement