Successfully reported this slideshow.
Upcoming SlideShare
×

# Polynomial

675 views

Published on

Published in: Education, Technology
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

### Polynomial

1. 1. ! quot;# ( \$ %' &
2. 2. 1 3
3. 3. ax + bx + c = 0 2 4
4. 4. ) − b ± b − 4ac 2 x= 2a 5
5. 5. ) ∆ = b − 4ac 2 6
6. 6. )quot; * y X1 X2 x 7
7. 7. & * ) quot;( Initial Request 1 Day After 1 Week After 8
8. 8. & * ) quot;( Initial Request Evolution Request 1 Day After Few Weeks Later 1 Day 1 Week After After 9
9. 9. 1 10
10. 10. )quot; & j X1 X2 x 11
11. 11. & * ) quot;( Initial Request 1 Day After 1 Week After 12
12. 12. & * ) quot;( Initial Request Evolution Request 1 Day Few Weeks Later After 1 Day 1 Week After After 13
13. 13. 1 14
14. 14. )& +* , y X1 X2 x X X X 15
15. 15. & * ) quot;( Initial Request 1 Day After 1 Week After 16
16. 16. & * ) quot;( Initial Request Evolution Request 1 Day After Few Weeks Later ? 1 Day 1 Week After After 17
17. 17. 1 18
18. 18. Start Input coefficients a,b,c Computes discriminant Delta = b * b – 4 * a * c <0 >0 Discriminant Sign =0 Computes roots Computes single root print roots print root print no roots End 19
19. 19. 1 20
20. 20. delta = (b*b) - (4*a*c); // discrimant computation if (delta < 0.0) { System.out.println (quot; No rootsquot;); } else if (delta > 0.0) { System.out.println (quot; Two roots :quot;); System.out.println (quot; x1 = quot; + (-b + Math.sqrt(delta))/ (2.0 * a)); System.out.println (quot; x2 = quot; + (-b - Math.sqrt(delta))/ (2.0 * a)); } else { System.out.println (“ Single root: quot;); System.out.println (quot; x = quot; + (-b / (2.0 * a))); } 21
21. 21. 1 22
22. 22. Start Input coefficients a,b,c Computes discriminant Delta = b * b – 4 * a * c <0 >0 Discriminant Sign =0 Computes roots Computes single root print roots print root print no roots End 23
23. 23. & ( Start Input coefficients a,b,c Computes discriminant Delta = b * b – 4 * a * c <0 >0 Discriminant Sign =0 Computes Complex roots Computes roots Computes double root print roots print root print roots End 24
24. 24. delta = (b*b) - (4*a*c); // discrimant computation if (delta < 0.0) { System.out.println (quot; No rootsquot;); } else if (delta > 0.0) { System.out.println (quot; Two roots :quot;); System.out.println (quot; x1 = quot; + (-b + Math.sqrt(delta))/ (2.0 * a)); System.out.println (quot; x2 = quot; + (-b - Math.sqrt(delta))/ (2.0 * a)); } else { System.out.println (“ Single root: quot;); System.out.println (quot; x = quot; + (-b / (2.0 * a))); } 25
25. 25. quot; quot; delta = (b*b) - (4*a*c); // discrimant computation if (delta < 0.0) { System.out.println (quot; No rootsquot;); } else if (delta > 0.0) { System.out.println (quot; Two roots :quot;); System.out.println (quot; x1 = quot; + (-b + Math.sqrt(delta))/ (2.0 * a)); System.out.println (quot; x2 = quot; + (-b - Math.sqrt(delta))/ (2.0 * a)); System.out.println (quot; Complex rootsquot;); System.out.println (quot; x1 real part = quot; + (-b / (2.0*a))); System.out.println (quot; x2 imaginary part = quot; + (-b - Math.sqrt(-delta))/ (2.0*a)+ quot;iquot;); System.out.println (quot; x2 real part = quot; + (-b / (2.0*a))); System.out.println (quot; x2 imaginary part= quot; + (-b - Math.sqrt(-delta))/ (2.0*a)+ quot;iquot;); } else { System.out.println (“ Single root: quot;); System.out.println (quot; x = quot; + (-b / (2.0 * a))); } 26
26. 26. 1 27
27. 27. , )& +* , y X1 X2 x X X X 28
28. 28. & +* ,) Discriminat Sign <0 >0 =0 Computes root case 1 Computes roots case 2 2 T F T F ( /X1/ <= X & X <= X == X1 /X2/ ) Return True Return False Return True Return False Return False End 29
29. 29. & * ) quot;( Initial Request 1 Day After 1 Week After 30
30. 30. & * ) quot;( Initial Request Evolution Request 1 Day After Few Weeks Later ? 1 Day 1 Week After After 31
31. 31. & static boolean isInBetweenRoots(double x,double a,double b, double c) { double delta, x1, x2; delta = (b*b) - (4*a*c); if (delta < 0.0) return false; else if (delta > 0.0) { System.out.print(quot;delta > 0quot;); x1 = (-b + Math.sqrt(delta))/ (2.0*a); x2 = (-b - Math.sqrt(delta))/ (2.0*a); return (Math.abs(x1) <= Math.abs(x)) && (Math.abs(x) <= Math.abs(x2)); } else { x1 = -b / (2.0 * a); return (x == x1); } } 32
32. 32. 1 33
33. 33. - ) - 6HFRQG 2UGHU 3 RO QRP L D O 6L QJ O H 5 RRW 7 Z R 5 RRW V 1 R 5 RRW 6HFRQG 2UGHU 6HFRQG 2UGHU 6HFRQG 2UGHU 3 RO QRP L D O 3 RO QRP L D O 3 RO QRP L D O 34
34. 34. - ) - 6HFRQG 2UGHU 3 RO QRP L D O ' L V FUL P L QD QW 6L QJ O H 5 RRW 7 Z R 5 RRW V 1 R 5 RRW 6HFRQG 2UGHU 6HFRQG 2UGHU 6HFRQG 2UGHU 3 RO QRP L D O 3 RO QRP L D O 3 RO QRP L D O 35
35. 35. - # 6HFRQG 2UGHU 3 RO QRP L D O ' L V FUL P L QD QW Double a Double b Double c computeRoots() 6L QJ O H 5 RRW 7 Z R 5 RRW V 1 R 5 RRW 6HFRQG 2UGHU 6HFRQG 2UGHU 6HFRQG 2UGHU 3 RO QRP L D O 3 RO QRP L D O 3 RO QRP L D O computeRoots() computeRoots() computeRoots() 36
36. 36. - & # 6HFRQG 2UGHU 3 RO QRP L D O computeRoots() create() 6L QJ O H 5 RRW 7 Z R 5 RRW V 1 R 5 RRW 6HFRQG 2UGHU 6HFRQG 2UGHU 6HFRQG 2UGHU 3 RO QRP L D O 3 RO QRP L D O 3 RO QRP L D O computeRoots() computeRoots() computeRoots() 37
37. 37. 1 38
38. 38. - ' L V FUL P L QD QW 6HFRQG 2UGHU 3 RO QRP L D O 39
39. 39. - ) 6HFRQG 2UGHU 3 RO QRP L D O 6HFRQG 2UGHU 3 RO QRP L D O ) D FW RU ' L V FUL P L QD QW 40
40. 40. - ) 6HFRQG 2UGHU 3 RO QRP L D O 6HFRQG 2UGHU 3 RO QRP L D O ) D FW RU ' L V FUL P L QD QW 41
41. 41. - # 6HFRQG 2UGHU 3 RO QRP L D O ' L V FUL P L QD QW Double a Double b Double c computeRoots() 6L QJ O H 5 RRW 7 Z R 5 RRW V 1 R 5 RRW 6HFRQG 2UGHU 6HFRQG 2UGHU 6HFRQG 2UGHU 3 RO QRP L D O 3 RO QRP L D O 3 RO QRP L D O computeRoots() computeRoots() computeRoots() 42
42. 42. class Discriminant { private double delta; public Discriminant (double a, double b, double c) { delta = (b * b) - (4.0 * a * c); } public double value () { return delta; } } 43
43. 43. ) * static Polynome create( double a, double b, double c) { Discriminant theDiscriminant = new Discriminant(a,b,c); double delta = theDiscriminant.value(); Polynome polynome; if (delta == 0.0) { return polynome = new SingleRootPolynome(a,b,c,theDiscriminant) ; } else if (delta > 0.0) { return polynome = new TwoRootsPolynome(a,b,c,theDiscriminant) ; } else { return polynome = new NoRootPolynome(a,b,c,theDiscriminant); } } 44
44. 44. * & static Polynome create( double a, double b, double c) { Discriminant theDiscriminant = new Discriminant(a,b,c); double delta = theDiscriminant.value(); Polynome polynome; if (delta == 0.0) { return polynome = new SingleRootPolynome(a,b,c,theDiscriminant) ; } else if (delta > 0.0) { return polynome = new TwoRootsPolynome(a,b,c,theDiscriminant) ; } else { return polynome = new ComplexRootsPolynome(a,b,c,theDiscriminant); } } 45
45. 45. 1 46
46. 46. - # 6HFRQG 2UGHU 3 RO QRP L D O ' L V FUL P L QD QW Double a Double b Double c computeRoots() 6L QJ O H 5 RRW 7 Z R 5 RRW V 1 R 5 RRW 6HFRQG 2UGHU 6HFRQG 2UGHU 6HFRQG 2UGHU 3 RO QRP L D O 3 RO QRP L D O 3 RO QRP L D O computeRoots() computeRoots() computeRoots() 47
47. 47. & ) * void computesRoots() { System.out.println (quot; Single root: quot;); System.out.println (quot; x = quot; + (-b / (2.0*a))); } 48
48. 48. - # 6HFRQG 2UGHU 3 RO QRP L D O ' L V FUL P L QD QW Double a Double b Double c computeRoots() 6L QJ O H 5 RRW 7 Z R 5 RRW V 1 R 5 RRW 6HFRQG 2UGHU 6HFRQG 2UGHU 6HFRQG 2UGHU 3 RO QRP L D O 3 RO QRP L D O 3 RO QRP L D O computeRoots() computeRoots() computeRoots() 49
49. 49. & ) #* void computesRoots() { System.out.println (quot; Two roots :quot;); System.out.println (quot; x1 = quot; + (-b + Math.sqrt(discriminant.value()))/ (2.0*a)); System.out.println (quot; x2 = quot; + (-b - Math.sqrt(discriminant.value()))/ (2.0*a)); } 50
50. 50. - # 6HFRQG 2UGHU 3 RO QRP L D O ' L V FUL P L QD QW Double a Double b Double c computeRoots() 6L QJ O H 5 RRW 7 Z R 5 RRW V 1 R 5 RRW 6HFRQG 2UGHU 6HFRQG 2UGHU 6HFRQG 2UGHU 3 RO QRP L D O 3 RO QRP L D O 3 RO QRP L D O computeRoots() computeRoots() computeRoots() 51
51. 51. & ). * void computesRoots() { System.out.println (quot; No rootsquot;); } 52
52. 52. 1 53
53. 53. - # 6HFRQG 2UGHU 3 RO QRP L D O ' L V FUL P L QD QW Double a Double b Double c computeRoots() 6L QJ O H 5 RRW 7 Z R 5 RRW V 1 R 5 RRW 6HFRQG 2UGHU 6HFRQG 2UGHU 6HFRQG 2UGHU 3 RO QRP L D O 3 RO QRP L D O 3 RO QRP L D O computeRoots() computeRoots() computeRoots() 54
54. 54. - # 6HFRQG 2UGHU 3 RO QRP L D O ' L V FUL P L QD QW Double a Double b Double c computeRoots() 6L QJ O H 5 RRW 7 Z R 5 RRW V & RP S O H[ 5 RRW V 6HFRQG 2UGHU 6HFRQG 2UGHU 6HFRQG 2UGHU 3 RO QRP L D O 3 RO QRP L D O 3 RO QRP L D O computeRoots() computeRoots() computeRoots() 55
55. 55. & )& (* void computesRoots() { System.out.println (quot; Complex rootsquot;); System.out.println (quot; x1 real part = quot; + (-b / (2.0*a))); System.out.println (quot; x1 imaginary part = “ + (-b + Math.sqrt(-discriminant.value()))/ (2.0*a)+ quot;iquot;); System.out.println (quot; x2 real part = quot; + (-b / (2.0*a))); System.out.println (quot; x2 imaginary part = “ + (-b - Math.sqrt(-discriminant.value()))/ (2.0*a)+ quot;iquot;); } 56
56. 56. 1 57
57. 57. - 6HFRQG 2UGHU 3 RO QRP L D O computeRoots() isInBetweenRoots() 6L QJ O H 5 RRW 7 Z R 5 RRW V 1 R 5 RRW 6HFRQG 2UGHU 6HFRQG 2UGHU 6HFRQG 2UGHU 3 RO QRP L D O 3 RO QRP L D O 3 RO QRP L D O computeRoots() computeRoots() computeRoots() isInBetweenRoots() isInBetweenRoots() isInBetweenRoots() 58
58. 58. /+ ) boolean isInBetweenRoots(double x) { return (x == x1); } 59
59. 59. - 6HFRQG 2UGHU 3 RO QRP L D O computeRoots() isInBetweenRoots() 6L QJ O H 5 RRW 7 Z R 5 RRW V 1 R 5 RRW 6HFRQG 2UGHU 6HFRQG 2UGHU 6HFRQG 2UGHU 3 RO QRP L D O 3 RO QRP L D O 3 RO QRP L D O computeRoots() computeRoots() computeRoots() isInBetweenRoots() isInBetweenRoots() isInBetweenRoots() 60
60. 60. /+ )# boolean isInBetweenRoots(double x) { return (Math.abs(x1) <= Math.abs(x)) && (Math.abs(x) <= Math.abs(x2)); } 61
61. 61. - 6HFRQG 2UGHU 3 RO QRP L D O computeRoots() isInBetweenRoots() 6L QJ O H 5 RRW 7 Z R 5 RRW V 1 R 5 RRW 6HFRQG 2UGHU 6HFRQG 2UGHU 6HFRQG 2UGHU 3 RO QRP L D O 3 RO QRP L D O 3 RO QRP L D O computeRoots() computeRoots() computeRoots() isInBetweenRoots() isInBetweenRoots() isInBetweenRoots() 62
62. 62. /+ ) boolean isInBetweenRoots(double x) { return false; } 63
63. 63. 01 11 64