Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package polynomial;
- import java.io.BufferedReader;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.text.DecimalFormat;
- import java.util.Scanner;
- /**
- *
- * @author casey
- */
- public class Polynomial {
- public static void main(String[] args) throws FileNotFoundException {
- Scanner read = new Scanner(new BufferedReader(new FileReader("poly.txt")));
- //first line into x array
- String line = read.nextLine();
- System.out.println("LINE: "+line);
- String[] x = line.split("\\s+");
- //second line into y array
- line = read.nextLine();
- System.out.println("LINE: "+line);
- String[] y = line.split("\\s+");
- read.close();
- Double[][] array = new Double[(x.length)*2][y.length+1];
- DecimalFormat df = new DecimalFormat("###.###");
- int a = 0;
- for(int i = 0; i<(x.length*2); i=i+2){
- array[i][0] = Double.parseDouble(x[a]);
- a++;
- }
- a=0;
- for(int j = 0; j<(y.length*2); j=j+2){
- array[j][1] = Double.parseDouble(y[a]);
- a++;
- }
- //LAGRANGES METHODS
- /*System.out.println("x: ");
- for(int i=0; i<x.length;i++){
- System.out.print(x[i]+ "\t");
- }
- System.out.println("\ny: ");
- for(int i=0; i<y.length;i++){
- System.out.print(y[i]+ "\t");
- }
- System.out.println();
- System.out.println("l_0");
- int c = 0;
- Double[] denominator = new Double[x.length];
- int[] values = new int[x.length];
- for(int i = 0; i<x.length;i++){
- values[i] = i;
- }
- for(int i = 0; i<1; i++){
- denominator[i] = ((Double.parseDouble(x[c]) - Double.parseDouble(x[c+1])) * (Double.parseDouble(x[c]) - Double.parseDouble(x[c+2]))
- * (Double.parseDouble(x[c]) - Double.parseDouble(x[c+3])));
- }
- System.out.println("Denominator: "+denominator[0]);*/
- //DIVIDED METHOD
- System.out.println("x\t"+"f[]\t"+"f[,]\t"+"f[,,]\t"+"f[,,,]");
- int j = 0;
- int i = 0;
- for(j=2; j<3; ){
- for(i = 0; i <=x.length; i=i+2){
- array[i+1][j] = ((array[i+2][j-1]) - (array[i][j-1])) /((array[i+2][j-2]) - (array[i][j-2]));
- }
- i = 1;
- j++;
- System.out.println("PRINT: i"+i+" j"+j);
- }
- i=6;
- j=0;
- //array[i-2][j+3] = ((array[i-1][j+2]) - (array[i-3][j+2])) /((array[i][j]) - (array[i-4][j]));
- //array[i-4][j+3] = ((array[i-3][j+2]) - (array[i-5][j+2])) /((array[i-2][j]) - (array[i-6][j]));
- //array[i-3][j+4] = ((array[i-2][j+3]) - (array[i-4][j+3])) /((array[i][j]) - (array[i-6][j]));
- for(int s = 0; s<x.length*2; s++){
- for(int t = 0; t<y.length+1; t++){
- //System.out.println("Piece: "+df.format(array[0][0]));
- System.out.print((array[s][t])+"\t");
- }
- System.out.println();
- }
- //3 + (1/2)(x-1) + (1/3)(x-1)(x-3/2) - 2(x-1)(x-3/2)x
- //String polynomial = array[0][1]+"+"+array[1][2]+"(x-"+array[0][0]+")+"+df.format(array[2][3])+"(x-"+(array[0][0])+")"+"(x-"+(array[2][0])+")+"
- // +df.format(array[3][4])+"(x-"+array[4][0]+")(x-"+(array[0][0]+")"+"(x-"+(array[2][0])+")");
- //System.out.println("Interloping Polynomial is: "+polynomial);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement