Advertisement
Khristina

Тест 2 "ур-е Лапласа" (внеш. сфера) (старая формула)

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