Copy of using 3 methods

# Copy of using 3 methods - rightbound = 1000 leftbound =...

This preview shows pages 1–4. Sign up to view the full content.

Sheet1 Page 1 import java.util.* public class bisection { public static void main(String[] args) p { public ReadCoff { double C2, C1, C0 System.out.println("3 coefficients to define from x to the 2nd to the constant") System.out.println("Enter the 1st Coefficient starting at x to the 2th") Scanner keyboard = new Scanner (System.in) System.out.println("Enter the 1st Coefficient") num = keyboard.nextInt(C2) System.out.println("Enter the 2nd Coefficient") num = keyboard.nextInt(C1) System.out.println("Enter the 3rd Coefficient") num = keyboard.nextInt(C0) } private double get polynomialValue { if((y*y1)<o) return C2*math.power(x,2)+C1*math.power(x,1)+C0 } public void computeZeros() { double x,yvalue, yvalue1 for(x=-3,x<=3 yvalue = getploynomialvalue(x) yvalue1 = getploynomialvalue(x+1) y ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FX =C2*math.power(x,2)+ C1*math.power(x,1)+ C0 midPoint= ((Rightbound + Leftbound)/2)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: rightbound = 1000 leftbound = -1000 difference = rightbound - leftbound While(abs(rightbound - leftbound &gt; .0000001)) { funLeft = C2*(leftbound)^2+ C1*(leftbound)+ C0 funMP = C2*(midPoint)^2+ C1*(midPoint)+ C0 if( funMP * funLeft &lt; 0)// throw out rightbound { rightbound = midPoint difference = rightbound - leftbound } else { leftbound = midPoint Sheet1 Page 2 difference = rightbound - leftbound } } System.out.println(&quot;your zero is. ..&quot; + leftbound) S While(abs(rightbound - leftbound &gt; .0000001))//finds 2nd root funLeft = C2*(leftbound)^2+ C1*(leftbound)+ C0 funMP = C2*(midPoint)^2+ C1*(midPoint)+ C0 if( funMP * funRight &lt; 0)// throw out leftbound { leftbound = midPoint difference = leftbound - rightbound } else { rightbound = midPoint difference = leftbound - rightbound } System.out.println(&quot;your zero is. ..&quot; + rightbound) Sheet1 Page 3 x++) Sheet1 Page 4...
View Full Document

## This note was uploaded on 04/29/2008 for the course C++ 201 taught by Professor Smith during the Spring '08 term at George Mason.

### Page1 / 4

Copy of using 3 methods - rightbound = 1000 leftbound =...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online