Advertisement
Guest User

Beregning virker

a guest
Apr 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.12 KB | None | 0 0
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <fstream>
  4. #include <iostream>
  5. #include "nr3.h"
  6. #include "svd.h"
  7. #include "utilities.h"
  8.  
  9. using namespace std;
  10. void message(string input) {
  11.     auto sbar = "----------------------------------\n";
  12.     cout << sbar << input << '\n' << sbar;
  13. }
  14. double F(double x, double y, double d) {
  15.     return (0.5 / pow(d * d + (x - y) * (x - y), 3.0 / 2.0));
  16. }
  17. double I1(VecDoub points, double x, double alimit, double h, double d) {
  18.     int N = points.size() / 2;
  19.     double res = 0;
  20.     double y = alimit;
  21.     for (int i = 0; i < N; i++, y = y + h) {
  22.         if (i == 0 || i == N - 1) {
  23.             res += 0.5 * F(x, y, d) * points[i];
  24.         } else {
  25.             res += F(x, y, d) * points[i];
  26.         }
  27.         cout << h << endl;
  28.     }
  29.     return res;
  30. }
  31.  
  32. int main() {
  33.     // JOHNS SETION
  34.     int N = 4;
  35.     // Problem size N
  36.     {
  37.         MatDoub A(2 * N + 2, 2 * N + 2);
  38.         VecDoub b(2 * N + 2);
  39.         const double eps1 = 0.8;
  40.         const double eps2 = 0.6;
  41.         const double T1 = 1000.0;
  42.         const double T2 = 500.0;
  43.         const double d = 1.0;
  44.         const double w = 1.0;
  45.         const double boltz = 1.712 * pow(10, -9);
  46.         double blimit = 0.5 * w;
  47.  
  48.         double alimit = -0.5 * w;
  49.         double h = (blimit - alimit) / N;
  50.         double k1 = (1 - eps1);
  51.         double k2 = (1 - eps2);
  52.         for (int i = 0; i < N + 1; i++) {
  53.             A[i][i] = -1;
  54.             b[i] = -eps1 * boltz * pow(T1, 4);
  55.         }
  56.         for (int i = N + 1; i < 2 * N + 2; i++) {
  57.             A[i][i] = -1;
  58.             b[i] = -eps2 * boltz * pow(T2, 4);
  59.         }
  60.         {
  61.             double y = 0;
  62.             double x;
  63.             int yy = 0;
  64.             int xx = 0;
  65.             for (yy = 0, y = alimit; yy < N + 1; yy++, y = y + h) {
  66.                 for (xx = N + 1, x = alimit; xx < 2 * N + 2; xx++, x = x + h) {
  67.                     // Insert correct value at edges
  68.                     if (yy == 0 || yy == N) {
  69.                         A[xx][yy] = ((h * k2) / 2) * F(x, y, d);
  70.                     } else {
  71.                         A[xx][yy] = (h * k2) * F(x, y, d);
  72.                     }
  73.                 }
  74.             }
  75.         }
  76.  
  77.         {
  78.             double y = 0;
  79.             double x;
  80.             int yy = 0;
  81.             int xx = 0;
  82.             for (xx = 0, y = alimit; xx < N + 1; xx++, y = y + h) {
  83.                 for (yy = N + 1, x = alimit; yy < 2 * N + 2; yy++, x = x + h) {
  84.                     // Insert correct value at edges
  85.                     if (yy == N + 1 || yy == 2 * N + 1) {
  86.                         A[xx][yy] = ((h * k1) / 2) * F(x, y, d);
  87.                     } else {
  88.                         A[xx][yy] = (h * k1) * F(x, y, d);
  89.                     }
  90.                 }
  91.             }
  92.         }
  93.         VecDoub xVec(2 * N + 2);
  94.  
  95.         SVD svddcmp(A);
  96.         svddcmp.solve(b, xVec);
  97.         // Calculate u(x) for x= -1/2 , -1/4,0,1/4,1/2
  98.         // INDSÆT RUTINER TIL AT BRUGE RESULTATET AF xVec:
  99.  
  100.         // SLUT RUTINER TIL AT BRUGE RESULTATET AF xVec:
  101.         util::print(xVec);
  102.     }
  103.     // JOHN SLUT
  104.     return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement