<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">/*
   Assignment #2  CS100B
   
   SheetPile.java
   --calculates sheet pile depth using the lhs/rhs, bisecton, and
     Newton's methods
   
   Author:		CS100B Student
   CUID:		123456
   Section:		99, Sunday, 10:00pm, CS100B TA
   
   Signature:	        My Signature
*/   

// class LHS_RHS
//   
// use the lhs/rhs method to find the root in the sheet pile equation
// the result is saved in "root"
class LHS_RHS {

    public static void main(String[] args){

        // given constants
	final double TOLERANCE = 0.001;
        final double GAMMA = 18.0;
        final double PHI = 30.0;
        final double L = 3.0;
        final double P = 30.0;
	
	// variable declaration
        double root;		// root of the equation
        int iterations;		// number of iterations to each root
	
        // pick a starting value and call it root
        root = 3.0;
        iterations = 0;

	// compute values of constants (note that arguments of trig.
	// functions must be in radians)
        double Ka = Math.tan((45 - PHI/2)*Math.PI/180);
        Ka *= Ka;		              // tan^2
        double Kp = Math.tan((45 + PHI/2)*Math.PI/180);
        Kp *= Kp;
		
        // pick a step size
        double increment = 0.00001;	 
   
        // initial values of the polynomial
        double lhs = 1000, rhs = 0.0;	   

        // get lhs and rhs and test if approx equal
        while(Math.abs(lhs - rhs) &gt; TOLERANCE) {

	    // evaluate left-hand side (the function itself) 
	    //by substituting root to the equation
	    lhs = Math.pow(root,4) -
	    8*P*Math.pow(root,2)/((GAMMA*(Kp - Ka))) -
	             12*P*L*root/((GAMMA*(Kp - Ka))) -
		     Math.pow((2*P/((GAMMA*(Kp - Ka)))),2);

	    // increase the guessed root by the incremental value
	    root += increment;

	    iterations += 1;

	}

	// display the results
  
        System.out.println("\nThe lhs/rhs method was used to " +
			   "solve the problem!\n");
        System.out.println("The root, " + root + " was obtained in " +
			   iterations + " iterations.\n");

    } // main method
} // LHS_RHS class

</pre></body></html>