Advertisement
Khristina

Тест 4 "ур-е Гельмгольца" (внеш. сфера) (старая формула)

Apr 4th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.29 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <conio.h>
  4. #include <string>
  5. #include <cstring>
  6. #include <math.h>
  7. #include <cstdlib>
  8. #include <ctime>
  9. #include <cmath>
  10. #include <algorithm>
  11. #include <complex>
  12. using namespace std;
  13.  
  14. int main()
  15. {
  16.     int M = 50, N = 50;
  17.     complex <double> V1;
  18.     complex <double> K1;
  19.     complex <double> p(0, 0);
  20.     const double pi = 3.14159265358979;
  21.     double x1, x2, x3, x, y1, y2, y3, y11, y21, y31, h = 2.0 * pi / N, H = pi / (1.0 * M), etta, xminusy, R;
  22.     double A = N * h, B = M * H;
  23.     //double tetta, betta, y1pr, y2pr, y3pr;
  24.     // double uq = pi / (1.0 * N), vl = pi / (2.0 * M);
  25.     complex <double> z(0, 1.0); // мнимая единица
  26.     complex< double > z1(1.0, 0);
  27.     setlocale(LC_ALL, "Rus");
  28.     for (int i = 1; i < 6; i++)
  29.     {
  30.         R = 1 + pow(10, (-1)*i);
  31.         cout << "R=" << R << endl;
  32.         for (int q = 0; q <= 2 * N; q++)
  33.         {
  34.             double uq = pi * q / (1.0 * N);
  35.             for (int l = 0; l <= 2 * M; l++)
  36.             {
  37.                 double vl = pi * l / (2.0 * M);
  38.                 y11 = sin(vl)*cos(uq);
  39.                 y21 = sin(vl)*sin(uq);
  40.                 y31 = cos(vl);
  41.                 x1 = y11 * R;
  42.                 x2 = y21 * R;
  43.                 x3 = y31 * R;
  44.                 //cout << "x1=" << x1 << endl;
  45.                 //cout << "x2=" << x2 << endl;
  46.                 //cout << "x3=" << x3 << endl;
  47.                 x = pow(pow(x1, 2) + pow(x2, 2) + pow(x3, 2), 0.5);
  48.                 //cout << "x=" << x << endl;
  49.                 // Вычисление K1
  50.                 for (int m = 0; m < M; m++)
  51.                 {
  52.                     double vm = (m + 0.5)*H;
  53.                     for (int n = 0; n < N; n++)
  54.                     {
  55.                         double un = (n + 0.5)*h;
  56.                         y1 = sin(vm)*cos(un);
  57.                         y2 = sin(vm)*sin(un);
  58.                         y3 = cos(vm);
  59.                         etta = sin(vm);
  60.                         xminusy = pow(pow(x1 - y1, 2) + pow(x2 - y2, 2) + pow(x3 - y3, 2), 0.5);
  61.                         K1 = K1 + ((h * H * etta * 1.0 * exp(z * xminusy) * cos(vm) / xminusy) / (4 * pi));
  62.                     }
  63.                 }
  64.                 if (abs(x) < 1)
  65.                 {
  66.                     V1 = (z - z1) * exp(z) * x3 * (abs(x) * cos(abs(x)) - sin(abs(x))) / ( R * pow(abs(x), 2));
  67.                 }
  68.                 else if (abs(x) > 1)
  69.                 {
  70.                     V1 = (cos(1) - sin(1)) * x3 * (z * abs(x) - z1) * exp(z * abs(x)) / ( R * pow(abs(x), 2));
  71.                 }
  72.  
  73.                 complex <double> maximum = max(abs(p), abs(K1 - V1));
  74.                 K1 = 0;
  75.                 p = maximum;
  76.             }
  77.         }
  78.  
  79.         cout << "Абсолютная погрешность=" << abs(p) << endl;
  80.         //cout << "V1=" << abs(V1) << endl;
  81.         cout << "______________________" << endl;
  82.     }
  83.  
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement