/*
 * Created on Jan 23, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * @author User
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class HW8_Q1 {

    // Output from program:
    //    Rectangular Rule (1 decimal place accuracy for F, 3 for d)	
    //    F = 1480.5578569214188	 d = 13.053576841177287
    
    //    Trapezoidal Rule (15 iterations, 4 decimal places accuracy for F, 6 for d)
    //    Trapezoidal rule roughly gives twice the accuracy of rectangle rule
    //	  because trucation error is quadratic in the number of intervals
    //    against linear for the rectangular rule
    //    F = 1480.5684685087622	 d = 13.053698473355864
    
    //    Simpson's Rule	
    //    F = 1480.568480085906	     d = 13.053698375036577
    //    (Simpson iterations: 15)   (Simpson iterations: 17)
    

	public static void main(String[] args) 
	{  
		FuncSailForce f = new FuncSailForce();
		FuncSailLine zf = new FuncSailLine();
		
		double a =  0; // Lower limit of integration
	    double b = 30; // Upper limit of integration
		
	    int intervals = 15;
	    int epsilon = (int) Math.pow(2,intervals);
	    
	    // Rectangular rule
		double F_Rect = Integration.rect(f , a, b, epsilon);
		double d_Rect = Integration.rect(zf, a, b, epsilon)/F_Rect;
		
		// "Improved" Trapezoidal rule
		double F_Trapz = 0.0;
		double d_Trapz = 0.0;
		for (int i = 1;i <= intervals; i++){
		    F_Trapz = Trapezoid.trapzd(f , a, b, i);
		}
		for (int i = 1;i <= intervals; i++){
		    d_Trapz = Trapezoid.trapzd(zf, a, b, i)/F_Trapz;
		}
		
		// Simpson's rule
		double F_Simp = Simpson.qsimp(f , a, b);
		double d_Simp = Simpson.qsimp(zf, a, b)/F_Simp;
		
		System.out.println("\nRectangular Rule\t");
		System.out.println("F = "+F_Rect+"\t d = "+d_Rect);
		
		System.out.println("\nTrapezoidal Rule\t");
		System.out.println("F = "+F_Trapz+"\t d = "+d_Trapz);
		
		System.out.println("\nSimpson's Rule\t");
		System.out.println("F = "+F_Simp+"\t d = "+d_Simp);
	}
}
