Advertisement
Khristina

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

Apr 4th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.16 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.     setlocale(LC_ALL, "Rus");
  27.     for (int i = 1; i < 6; i++)
  28.     {
  29.         R = 1 + pow(10, (-1)*i);
  30.         cout << "R=" << R << endl;
  31.         for (int q = 0; q <= 2 * N; q++)
  32.         {
  33.             double uq = pi * q / (1.0 * N);
  34.             for (int l = 0; l <= 2 * M; l++)
  35.             {
  36.                 double vl = pi * l / (2.0 * M);
  37.                 y11 = sin(vl)*cos(uq);
  38.                 y21 = sin(vl)*sin(uq);
  39.                 y31 = cos(vl);
  40.                 x1 = y11 * R;
  41.                 x2 = y21 * R;
  42.                 x3 = y31 * R;
  43.                 //cout << "x1=" << x1 << endl;
  44.                 //cout << "x2=" << x2 << endl;
  45.                 //cout << "x3=" << x3 << endl;
  46.                 x = pow(pow(x1, 2) + pow(x2, 2) + pow(x3, 2), 0.5);
  47.                 //cout << "x=" << x << endl;
  48.                 // Вычисление K1
  49.                 for (int m = 0; m < M; m++)
  50.                 {
  51.                     double vm = (m + 0.5)*H;
  52.                     for (int n = 0; n < N; n++)
  53.                     {
  54.                         double un = (n + 0.5)*h;
  55.                         y1 = sin(vm)*cos(un);
  56.                         y2 = sin(vm)*sin(un);
  57.                         y3 = cos(vm);
  58.                         etta = sin(vm);
  59.                         xminusy = pow(pow(x1 - y1, 2) + pow(x2 - y2, 2) + pow(x3 - y3, 2), 0.5);
  60.                         K1 = K1 + ((h * H * etta * 1.0 * exp(z * xminusy) / xminusy) / (4 * pi));
  61.                     }
  62.                 }
  63.                 if (abs(x) < 1)
  64.                 {
  65.                     V1 = exp(z) * sin(abs(x)) / abs(x);
  66.                 }
  67.                 else if (abs(x) > 1)
  68.                 {
  69.                     V1 = exp(z * abs(x)) * sin(1) / abs(x);
  70.                 }
  71.                 complex <double> maximum = max(abs(p), abs(K1 - V1) * 1.0 / abs(V1));
  72.                 K1 = 0;
  73.                 p = maximum;
  74.             }
  75.         }
  76.  
  77.         cout << "Относительная погрешность=" << abs(p) << endl;
  78.         //cout << "V1=" << abs(V1) << endl;
  79.         cout << "______________________" << endl;
  80.     }
  81.  
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement