Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- /**
- * Created by IntelliJ IDEA.
- * User: Andrew
- * Date: 28.03.12
- * Time: 0:12
- * To change this template use File | Settings | File Templates.
- */
- public class GridBorderMain {
- public static double getP(double xk) { //change
- // return 2 * xk;
- return 0;
- }
- public static double getQ(double xk) { //change
- return -(xk * xk + 1);
- }
- public static double getA(double h, double xk) {
- return 1 - (h / 2) * getP(xk);
- }
- public static double getB(double h, double xk) {
- return h * h * getQ(xk) - 2;
- }
- public static double getC(double h, double xk) {
- return 1 + (h / 2) * getP(xk);
- }
- public static double getF(double xk) { //change
- return 12 * xk - 2 * Math.pow(xk, 3) - 2 * Math.pow(xk, 5);
- }
- public static void main(String[] args) {
- double h = 0.1;
- double a0 = 1; //alpha0 //change
- double a1 = 3; //alpha1 //change
- double b0 = -1; //beta0 //change
- double b1 = 1; //beta1 //change
- double A = 0;
- double B = 5;
- double l = 0; // [l, g] //change
- double g = 1; //change
- int n = ((int) ((g - l) / h)) + 1;
- double[] a = new double[n];
- double[] b = new double[n];
- double[] c = new double[n];
- double[] x = new double[n];
- double[] y = new double[n];
- double[] d = new double[n];
- double[] ksi = new double[n];
- double[] eta = new double[n];
- for (int i = 1; i < n; i++) {
- x[i] = x[i - 1] + h;
- }
- for (int i = 0; i < n; i++) {
- a[i] = getA(h, x[i]);
- b[i] = getB(h, x[i]);
- c[i] = getC(h, x[i]);
- d[i] = getF(x[i]) * h * h;
- }
- double a1S = a1 / (1 - h / 2 * getP(x[0]));
- double a0S = a0 * h - (a1 - h * getQ(x[0]) / 2) / (1 - h * getP(x[0]) / 2);
- double hAS = h * A + (h * h * getF(x[0]) / 2) / (1 - h * getP(x[0]) / 2);
- double b1S = b1 / (1 + h / 2 * getP(x[0]));
- double b0S = b0 * h - (b1 + h * getQ(x[n - 1]) / 2) / (1 + h * getP(x[n - 1]) / 2);
- double hBS = h * B + (h * h * getF(x[n - 1]) / 2) / (1 + h * getP(x[n - 1]) / 2);
- ksi[1] = -a1S / a0S;
- eta[1] = -hAS / a0S;
- for (int k = 1; k < ksi.length - 1; k++) {
- ksi[k + 1] = c[k] / (b[k] - ksi[k] * c[k]);
- eta[k + 1] = (a[k] * eta[k] - d[k]) / (b[k] - ksi[k] * c[k]);
- }
- y[n - 1] = (hBS - b0S * eta[n - 1]) / (b1S + b0S * ksi[n - 1]);
- for (int i = n - 2; i > 0; i--) {
- y[i] = ksi[i+1]*y[i+1]+eta[i+1];
- }
- y[0] = - ((a1S)/(a0S))*y[1] + hAS/(a0S);
- System.out.println("x: " + Arrays.toString(x));
- System.out.println("a: " + Arrays.toString(a));
- System.out.println("b: " + Arrays.toString(b));
- System.out.println("c: " + Arrays.toString(c));
- System.out.println("d: " + Arrays.toString(d));
- System.out.println("a1* = " + a1S);
- System.out.println("b1* = " + b1S);
- System.out.println("a0* = " + a0S);
- System.out.println("b0* = " + b0S);
- System.out.println("hA* = " + hAS);
- System.out.println("hB* = " + hBS);
- System.out.println("ksi: " + Arrays.toString(ksi));
- System.out.println("eta: " + Arrays.toString(eta));
- System.out.println("y: " + Arrays.toString(y));
- }
- }
Add Comment
Please, Sign In to add comment