codisinmyvines

formysun

Apr 12th, 2021
528
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. double function(double t, double u)
  7. {
  8.     return 4 / (t * t) - (u / t) - (u * u);
  9. }
  10. void priblizhennoe(ofstream&out, double h, double N, double t0, double U0)
  11. {
  12.     double t, u, f, k1, k2, k3, k4;
  13.     u = U0;
  14.     t = t0;
  15.     //cout << "Для t0 = " << t << " U0 = " << u << "\n";
  16.     out << u << "\n";
  17.     for (int i = 0; i < N; i++)
  18.     {
  19.         k1 = function(t, u);
  20.         k2 = function(t + h / 2, u + (h * k1) / 2);
  21.         k3 = function(t + h / 2, u + (h * k2) / 2);
  22.         k4 = function(t + h, u + h * k3);
  23.         u += h * (k1 + (2 * k2) + (2 * k3) + k4) / 6;
  24.         t += h;
  25.         //cout << "При t" << i + 1 << " = " << t << " U" << i + 1 << " равно: " << u << "\n";
  26.         out << u << "\n";
  27.     }
  28. }
  29. void tochnoe(double N, double h, double t0, double U0, double C)
  30. {
  31.     double t, u;
  32.     t = t0;
  33.     u = U0;
  34.     cout << "При t" << 0 << " = " << t << " U" << 0 << " = " << u << "\n";
  35.     for (int i = 0; i < N; i++)
  36.     {
  37.         t = t + h;
  38.         u = (2 * (t * t * t * t + C)) / (t * (t * t * t * t - C));
  39.         cout << "При t" << i + 1 << " = " << t << " U" << i + 1 << " = " << u << "\n";
  40.     }
  41. }
  42. int main()
  43. {
  44.     ofstream out("pribresh.txt");
  45.     setlocale(LC_ALL, "RU");
  46.     double t0, T, h, N, U0;
  47.     cout << "Введите область [to,T]:\n";
  48.     cin >> t0 >> T;
  49.     cout << "Введите N и U0: ";
  50.     cin >> N >> U0;
  51.     h = (T - t0) / N;
  52.     double C;
  53.     C = (t0 * t0 * t0 * t0 * (t0 * U0 - 2)) / (2 + U0 * t0);
  54.     //cout << "Приближенные решения: \n";
  55.     priblizhennoe(out, h, N, t0, U0);
  56.     out.close();
  57.     //cout << "Точные решения: \n";
  58.     //tochnoe(N, h, t0, U0);
  59.     ifstream inout("pribresh.txt");
  60.     ofstream outn100("n100.txt");
  61.     string s;
  62.     while (inout.peek() != EOF)
  63.     {
  64.         inout >> s;
  65.         for (int i = 0; i < s.length(); i++)
  66.             if (s[i] == '.')
  67.                 s[i] = ',';
  68.         outn100 << s << "\n";
  69.     }
  70.     inout.close();
  71.     outn100.close();
  72.  
  73.     return 0;
  74. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×