Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Approximator {
- double a[];
- double sumB[];
- double x[];
- double y[];
- double sumMatrix[][];
- int K;
- public Approximator(double x[], double y[]) {
- this.x = x;
- this.y = y;
- K = this.x.length-1;
- a = new double[K];
- sumB = new double[K];
- sumMatrix = new double[K][K];
- }
- public double[] getApprox() {
- for (int i = 0; i < K; i++) {
- System.out.println();
- for (int j = 0; j < K; j++) {
- for (int k = 0; k < K; k++) {
- sumMatrix[i][j] += Math.pow(x[k], i + j);
- }
- System.out.print(sumMatrix[i][j] + " ");
- }
- }
- System.out.println();
- for (int i = 0; i < K; i++) {
- for (int k = 0; k < K; k++) {
- sumB[i] += Math.pow(x[k], i) * y[i];
- }
- System.out.print(sumB[i] + " ");
- }
- System.out.println();
- GaussMethod gm = new GaussMethod(sumMatrix, sumB);
- double solution[] = gm.getSolution();
- return solution;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement