daily pastebin goal
46%
SHARE
TWEET

Untitled

a guest Jun 19th, 2017 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Approximator {
  2.  
  3.     double a[];
  4.     double sumB[];
  5.     double x[];
  6.     double y[];
  7.     double sumMatrix[][];
  8.     int K;
  9.  
  10.     public Approximator(double x[], double y[]) {
  11.         this.x = x;
  12.         this.y = y;
  13.         K = this.x.length-1;
  14.         a = new double[K];
  15.         sumB = new double[K];
  16.         sumMatrix = new double[K][K];
  17.     }
  18.  
  19.     public double[] getApprox() {
  20.         for (int i = 0; i < K; i++) {
  21.             System.out.println();
  22.             for (int j = 0; j < K; j++) {
  23.                 for (int k = 0; k < K; k++) {
  24.                     sumMatrix[i][j] += Math.pow(x[k], i + j);
  25.                 }
  26.                 System.out.print(sumMatrix[i][j] + " ");
  27.             }
  28.         }
  29.         System.out.println();
  30.         for (int i = 0; i < K; i++) {
  31.             for (int k = 0; k < K; k++) {
  32.                 sumB[i] += Math.pow(x[k], i) * y[i];
  33.             }
  34.             System.out.print(sumB[i] + " ");
  35.         }
  36.         System.out.println();
  37.         GaussMethod gm = new GaussMethod(sumMatrix, sumB);
  38.         double solution[] = gm.getSolution();
  39.         return solution;
  40.     }
  41. }
RAW Paste Data
Top