Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.99 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package polynomial;
  7.  
  8. import java.io.BufferedReader;
  9. import java.io.FileNotFoundException;
  10. import java.io.FileReader;
  11. import java.text.DecimalFormat;
  12. import java.util.Scanner;
  13.  
  14. /**
  15.  *
  16.  * @author casey
  17.  */
  18. public class Polynomial {
  19.  
  20.    
  21.     public static void main(String[] args) throws FileNotFoundException {
  22.        
  23.         Scanner read = new Scanner(new BufferedReader(new FileReader("poly.txt")));
  24.        
  25.             //first line into x array
  26.             String line = read.nextLine();
  27.             System.out.println("LINE: "+line);
  28.             String[] x = line.split("\\s+");
  29.            
  30.             //second line into y array
  31.             line = read.nextLine();
  32.             System.out.println("LINE: "+line);
  33.             String[] y = line.split("\\s+");    
  34.        
  35.         read.close();
  36.        
  37.         Double[][] array = new Double[(x.length)*2][y.length+1];
  38.        
  39.         DecimalFormat df = new DecimalFormat("###.###");  
  40.          int a = 0;
  41.            
  42.         for(int i = 0; i<(x.length*2); i=i+2){  
  43.            
  44.             array[i][0] = Double.parseDouble(x[a]);
  45.             a++;
  46.            
  47.         }
  48.         a=0;
  49.         for(int j = 0; j<(y.length*2); j=j+2){  
  50.             array[j][1] = Double.parseDouble(y[a]);
  51.             a++;
  52.  
  53.         }
  54.        
  55.         //LAGRANGES METHODS
  56.         /*System.out.println("x: ");
  57.         for(int i=0; i<x.length;i++){
  58.             System.out.print(x[i]+ "\t");
  59.         }
  60.         System.out.println("\ny: ");
  61.         for(int i=0; i<y.length;i++){
  62.             System.out.print(y[i]+ "\t");
  63.         }
  64.         System.out.println();
  65.        
  66.         System.out.println("l_0");
  67.         int c = 0;
  68.         Double[] denominator = new Double[x.length];
  69.         int[] values = new int[x.length];
  70.         for(int i = 0; i<x.length;i++){
  71.             values[i] = i;
  72.         }
  73.        
  74.         for(int i = 0; i<1; i++){
  75.         denominator[i] = ((Double.parseDouble(x[c]) - Double.parseDouble(x[c+1])) * (Double.parseDouble(x[c]) - Double.parseDouble(x[c+2]))
  76.                  * (Double.parseDouble(x[c]) - Double.parseDouble(x[c+3])));
  77.         }
  78.         System.out.println("Denominator: "+denominator[0]);*/
  79.        
  80.         //DIVIDED METHOD
  81.        
  82.        
  83.        
  84.        
  85.        
  86.         System.out.println("x\t"+"f[]\t"+"f[,]\t"+"f[,,]\t"+"f[,,,]");
  87.         int j = 0;
  88.         int i = 0;
  89.        
  90.         for(j=2; j<3; ){
  91.            
  92.           for(i = 0; i <=x.length; i=i+2){  
  93.             array[i+1][j] = ((array[i+2][j-1]) - (array[i][j-1])) /((array[i+2][j-2]) - (array[i][j-2]));
  94.              
  95.           }
  96.           i = 1;
  97.           j++;
  98.           System.out.println("PRINT: i"+i+" j"+j);
  99.         }
  100.        
  101.        
  102.        
  103.        i=6;
  104.        j=0;
  105.             //array[i-2][j+3] = ((array[i-1][j+2]) - (array[i-3][j+2])) /((array[i][j]) - (array[i-4][j]));
  106.             //array[i-4][j+3] = ((array[i-3][j+2]) - (array[i-5][j+2])) /((array[i-2][j]) - (array[i-6][j]));
  107.             //array[i-3][j+4] = ((array[i-2][j+3]) - (array[i-4][j+3])) /((array[i][j]) - (array[i-6][j]));
  108.            
  109.        
  110.        
  111.         for(int s = 0; s<x.length*2; s++){
  112.             for(int t = 0; t<y.length+1; t++){
  113.                 //System.out.println("Piece: "+df.format(array[0][0]));
  114.                  System.out.print((array[s][t])+"\t");
  115.             }
  116.             System.out.println();
  117.         }
  118.         //3 + (1/2)(x-1) +  (1/3)(x-1)(x-3/2) - 2(x-1)(x-3/2)x
  119.         //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])+")+"
  120.              //   +df.format(array[3][4])+"(x-"+array[4][0]+")(x-"+(array[0][0]+")"+"(x-"+(array[2][0])+")");
  121.         //System.out.println("Interloping Polynomial is: "+polynomial);
  122.     }
  123.    
  124.    
  125.    
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement