Guest User

Untitled

a guest
Aug 14th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.14 KB | None | 0 0
  1. import java.util.Arrays;
  2.  
  3. /**
  4.  * Created by IntelliJ IDEA.
  5.  * User: Andrew
  6.  * Date: 28.03.12
  7.  * Time: 0:12
  8.  * To change this template use File | Settings | File Templates.
  9.  */
  10. public class GridBorderMain {
  11.     public static double getP(double xk) {      //change
  12. //      return 2 * xk;
  13.         return 0;
  14.     }
  15.  
  16.     public static double getQ(double xk) {      //change
  17.         return -(xk * xk + 1);
  18.     }
  19.  
  20.     public static double getA(double h, double xk) {
  21.         return 1 - (h / 2) * getP(xk);
  22.     }
  23.  
  24.     public static double getB(double h, double xk) {
  25.         return h * h * getQ(xk) - 2;
  26.     }
  27.  
  28.     public static double getC(double h, double xk) {
  29.         return 1 + (h / 2) * getP(xk);
  30.     }
  31.  
  32.     public static double getF(double xk) {      //change
  33.         return 12 * xk - 2 * Math.pow(xk, 3) - 2 * Math.pow(xk, 5);
  34.     }
  35.  
  36.  
  37.     public static void main(String[] args) {
  38.         double h = 0.1;
  39.         double a0 = 1;  //alpha0                //change
  40.         double a1 = 3;  //alpha1                //change
  41.         double b0 = -1; //beta0                 //change
  42.         double b1 = 1;  //beta1                 //change
  43.         double A = 0;
  44.         double B = 5;
  45.  
  46.         double l = 0;   // [l, g]              //change
  47.         double g = 1;                          //change
  48.         int n = ((int) ((g - l) / h)) + 1;
  49.  
  50.         double[] a = new double[n];
  51.         double[] b = new double[n];
  52.         double[] c = new double[n];
  53.         double[] x = new double[n];
  54.         double[] y = new double[n];
  55.         double[] d = new double[n];
  56.  
  57.         double[] ksi = new double[n];
  58.         double[] eta = new double[n];
  59.  
  60.  
  61.         for (int i = 1; i < n; i++) {
  62.             x[i] = x[i - 1] + h;
  63.         }
  64.  
  65.         for (int i = 0; i < n; i++) {
  66.             a[i] = getA(h, x[i]);
  67.             b[i] = getB(h, x[i]);
  68.             c[i] = getC(h, x[i]);
  69.             d[i] = getF(x[i]) * h * h;
  70.         }
  71.  
  72.         double a1S = a1 / (1 - h / 2 * getP(x[0]));
  73.         double a0S = a0 * h - (a1 - h * getQ(x[0]) / 2) / (1 - h * getP(x[0]) / 2);
  74.         double hAS = h * A + (h * h * getF(x[0]) / 2) / (1 - h * getP(x[0]) / 2);
  75.  
  76.         double b1S = b1 / (1 + h / 2 * getP(x[0]));
  77.         double b0S = b0 * h - (b1 + h * getQ(x[n - 1]) / 2) / (1 + h * getP(x[n - 1]) / 2);
  78.         double hBS = h * B + (h * h * getF(x[n - 1]) / 2) / (1 + h * getP(x[n - 1]) / 2);
  79.  
  80.  
  81.         ksi[1] = -a1S / a0S;
  82.         eta[1] = -hAS / a0S;
  83.  
  84.         for (int k = 1; k < ksi.length - 1; k++) {
  85.             ksi[k + 1] = c[k] / (b[k] - ksi[k] * c[k]);
  86.             eta[k + 1] = (a[k] * eta[k] - d[k]) / (b[k] - ksi[k] * c[k]);
  87.         }
  88.  
  89.         y[n - 1] = (hBS - b0S * eta[n - 1]) / (b1S + b0S * ksi[n - 1]);
  90.  
  91.         for (int i = n - 2; i > 0; i--) {
  92.             y[i] = ksi[i+1]*y[i+1]+eta[i+1];
  93.         }
  94.  
  95.         y[0] = - ((a1S)/(a0S))*y[1] + hAS/(a0S);
  96.  
  97.  
  98.         System.out.println("x: " + Arrays.toString(x));
  99.         System.out.println("a: " + Arrays.toString(a));
  100.         System.out.println("b: " + Arrays.toString(b));
  101.         System.out.println("c: " + Arrays.toString(c));
  102.         System.out.println("d: " + Arrays.toString(d));
  103.  
  104.         System.out.println("a1* = " + a1S);
  105.         System.out.println("b1* = " + b1S);
  106.         System.out.println("a0* = " + a0S);
  107.         System.out.println("b0* = " + b0S);
  108.         System.out.println("hA* = " + hAS);
  109.         System.out.println("hB* = " + hBS);
  110.  
  111.  
  112.         System.out.println("ksi: " + Arrays.toString(ksi));
  113.         System.out.println("eta: " + Arrays.toString(eta));
  114.         System.out.println("y: " + Arrays.toString(y));
  115.  
  116.     }
  117. }
Add Comment
Please, Sign In to add comment