Advertisement
Khristina

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

Apr 4th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.71 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 <complex>
  11. using namespace std;
  12.  
  13. int main()
  14. {
  15.     int M = 100, N = 100;
  16.     complex< double> V0;
  17.     long double K0 = 0, S0 = 0;
  18.     const double pi = 3.14159265358979;
  19.     double x1, x2, x3, x, y1, y2, y3, y11, y21, y31, h = 2.0 * pi / N, H = pi / (1.0 * M), etta, xminusy, R;
  20.     double A = N * h, B = M * H;
  21.     double tetta, betta, y1pr, y2pr, y3pr;
  22.     double uq = pi / (1.0 * N), vl = pi / (2.0 * M);
  23.     complex< double > z(0, 1.0); // мнимая единица
  24.     complex< double > z1(1.0, 0);
  25.     for (int i = 1; i < 6; i++)
  26.     {
  27.         R = 1 - pow(10, (-1)*i);
  28.         cout << "R=" << R << endl;
  29.         y11 = sin(vl)*cos(uq);
  30.         y21 = sin(vl)*sin(uq);
  31.         y31 = cos(vl);
  32.         x1 = y11 * R;
  33.         x2 = y21 * R;
  34.         x3 = y31 * R;
  35.         cout << "x1=" << x1 << endl;
  36.         cout << "x2=" << x2 << endl;
  37.         cout << "x3=" << x3 << endl;
  38.         x = pow(pow(x1, 2) + pow(x2, 2) + pow(x3, 2), 0.5);
  39.         cout << "x=" << x << endl;
  40.         // Вычисление K0
  41.         for (int m = 0; m < M; m++)
  42.         {
  43.             double vm = (m + 0.5)*H;
  44.             for (int n = 0; n < N; n++)
  45.             {
  46.                 double un = (n + 0.5)*h;
  47.                 y1 = sin(vm)*cos(un);
  48.                 y2 = sin(vm)*sin(un);
  49.                 y3 = cos(vm);
  50.                 etta = sin(vm);
  51.                 xminusy = pow(pow(x1 - y1, 2) + pow(x2 - y2, 2) + pow(x3 - y3, 2), 0.5);
  52.                 K0 = K0 + ((h * H * etta * 1.0  * cos(vm) / xminusy) / (4 * pi));
  53.             }
  54.         }
  55.         // Вычисление S0
  56.         /* for (int m = 0; m < M; m++)
  57.         {
  58.             double vm = (m + 0.5)*H;
  59.             for (int n = 0; n < N; n++)
  60.             {
  61.                 double un = (n + 0.5)*h;
  62.                 y1pr = cos(un) * cos(vm);
  63.                 y2pr = sin(un) * cos(vm);
  64.                 y3pr = (-1)*sin(vm);
  65.                 betta = sqrt(pow(y1pr, 2) + pow(y2pr, 2) + pow(y3pr, 2));
  66.  
  67.                 // Вычисление I(H)
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.                 tetta = 1.0 / betta;
  75.                 y1 = sin(vm)*cos(un);
  76.                 y2 = sin(vm)*sin(un);
  77.                 y3 = cos(vm);
  78.                 etta = sin(vm);
  79.                 xminusy = pow(pow(x1 - y1, 2) + pow(x2 - y2, 2) + pow(x3 - y3, 2), 0.5);
  80.                 S0 = S0 + (etta * tetta);
  81.             }
  82.         } */
  83.  
  84.         cout << "K0=" << K0 << endl;
  85.         if (abs(x) < 1)
  86.         {
  87.             V0 = (z - z1) * exp(z) * cos(x3 / R) * (abs(x) * cos(abs(x)) - sin(abs(x))) / pow(abs(x),2);
  88.         }
  89.         else if (abs(x) > 1)
  90.         {
  91.             V0 = (cos(1) - sin(1)) * cos(x3 / R) * (z * abs(x) - z1) / pow(abs(x), 2);
  92.         }
  93.  
  94.         cout << "V0=" << abs(V0) << endl;
  95.         cout << "______________________" << endl;
  96.     }
  97.  
  98.     return 0;
  99. }
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106. #include "pch.h"
  107. #include <iostream>
  108. #include <conio.h>
  109. #include <string>
  110. #include <cstring>
  111. #include <math.h>
  112. #include <cstdlib>
  113. #include <ctime>
  114. #include <cmath>
  115. #include <algorithm>
  116. #include <complex>
  117. using namespace std;
  118.  
  119. int main()
  120. {
  121.     int M = 50, N = 50;
  122.     complex <double> V1;
  123.     complex <double> K1;
  124.     complex <double> p(0, 0);
  125.     const double pi = 3.14159265358979;
  126.     double x1, x2, x3, x, y1, y2, y3, y11, y21, y31, h = 2.0 * pi / N, H = pi / (1.0 * M), etta, xminusy, R;
  127.     double A = N * h, B = M * H;
  128.     //double tetta, betta, y1pr, y2pr, y3pr;
  129.     // double uq = pi / (1.0 * N), vl = pi / (2.0 * M);
  130.     complex <double> z(0, 1.0); // мнимая единица
  131.     complex< double > z1(1.0, 0);
  132.     setlocale(LC_ALL, "Rus");
  133.     for (int i = 1; i < 6; i++)
  134.     {
  135.         R = 1 - pow(10, (-1)*i);
  136.         cout << "R=" << R << endl;
  137.         for (int q = 0; q <= 2 * N; q++)
  138.         {
  139.             double uq = pi * q / (1.0 * N);
  140.             for (int l = 0; l <= 2 * M; l++)
  141.             {
  142.                 double vl = pi * l / (2.0 * M);
  143.                 y11 = sin(vl)*cos(uq);
  144.                 y21 = sin(vl)*sin(uq);
  145.                 y31 = cos(vl);
  146.                 x1 = y11 * R;
  147.                 x2 = y21 * R;
  148.                 x3 = y31 * R;
  149.                 //cout << "x1=" << x1 << endl;
  150.                 //cout << "x2=" << x2 << endl;
  151.                 //cout << "x3=" << x3 << endl;
  152.                 x = pow(pow(x1, 2) + pow(x2, 2) + pow(x3, 2), 0.5);
  153.                 //cout << "x=" << x << endl;
  154.                 // Вычисление K1
  155.                 for (int m = 0; m < M; m++)
  156.                 {
  157.                     double vm = (m + 0.5)*H;
  158.                     for (int n = 0; n < N; n++)
  159.                     {
  160.                         double un = (n + 0.5)*h;
  161.                         y1 = sin(vm)*cos(un);
  162.                         y2 = sin(vm)*sin(un);
  163.                         y3 = cos(vm);
  164.                         etta = sin(vm);
  165.                         xminusy = pow(pow(x1 - y1, 2) + pow(x2 - y2, 2) + pow(x3 - y3, 2), 0.5);
  166.                         K1 = K1 + ((h * H * etta * 1.0 * exp(z * xminusy) * cos(vm) / xminusy) / (4 * pi));
  167.                     }
  168.                 }
  169.                 if (abs(x) < 1)
  170.                 {
  171.                     V1 = (z - z1) * exp(z) * x3 * (abs(x) * cos(abs(x)) - sin(abs(x))) / ( R * pow(abs(x), 2));
  172.                 }
  173.                 else if (abs(x) > 1)
  174.                 {
  175.                     V1 = (cos(1) - sin(1)) * x3 * (z * abs(x) - z1) * exp(z * abs(x)) / ( R * pow(abs(x), 2));
  176.                 }
  177.  
  178.                 complex <double> maximum = max(abs(p), abs(K1 - V1));
  179.                 K1 = 0;
  180.                 p = maximum;
  181.             }
  182.         }
  183.  
  184.         cout << "Абсолютная погрешность=" << abs(p) << endl;
  185.         //cout << "V1=" << abs(V1) << endl;
  186.         cout << "______________________" << endl;
  187.     }
  188.  
  189.     return 0;
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement