Download - Polynomial
��������� ��������� ��� ���! ����"�#���� �������
$��������%&'�
���������������������� ���(���
31
������������������ �
� ���������
� ������� ��������������
� ������� ��������������
� �������������� ��
� �� � ������ �������
� ������� ��������������
� ������� ��������������
� ����������� ��
� ������ ���������
� �� � ������ �������
� ������� ��������������
� ������� ��������������
4
������������������ ������� ��
02 =++ cbxax
5
������������������ ������� ��������)
aacbb
x2
42 −±−=
6
������������������ ��� ��� � �����)
acb 42 −=∆
7
X1 X2x
y
� ���� ����� ���)�" ��������� ��*
8
&�������*�������)�"�( ������� ��
1 Day After
1 Week After
Initial Request
9
&�������*�������)�"�( ������� ��
1 Day After
1 Week After
Few Weeks Later
1 Day After
Initial Request Evolution Request
101
������������������ �
� ���������
� ������� ��������������
� ������� ��������������
� �������������� ��
� �� � ������ �������
� ������� ��������������
� ������� ��������������
� ����������� ��
� ������ ���������
� �� � ������ �������
� ������� ��������������
� ������� ��������������
11
x
j
X1 X2
������� ����� ���)�" ��������� ��&
12
&�������*�������)�"�( ������� ��
1 Day After
1 Week After
Initial Request
13
&�������*�������)�"�( ������� ��
1 Day After
1 Week After
Few Weeks Later
1 Day After
Initial Request Evolution Request
141
������������������ �
� ���������
� ������� ��������������
� ������� ��������������
� �������������� ��
� �� � ������ �������
� ������� ��������������
� ������� ��������������
� ����������� ��
� ������ ���������
� �� � ������ �������
� ������� ��������������
� ������� ��������������
15
�� ��� ����� ���)�&���+��*����������,�
X1 X2
X XX
x
y
16
&�������*�������)�"�( ������� ��
1 Day After
1 Week After
Initial Request
17
&�������*�������)�"�( ������� ��
1 Day After
1 Week After
Few Weeks Later ?
1 Day After
Initial Request Evolution Request
181
������������������ �
� ���������
� ������� ��������������
� ������� ��������������
� �������������� ��
� �� � ������ �������
� ������� ��������������
� ������� ��������������
� ����������� ��
� ������ ���������
� �� � ������ �������
� ������� ��������������
� ������� ��������������
19
�������������� ��Start
Computes discriminantDelta = b * b – 4 * a * c
DiscriminantSign
Computes single rootComputes roots
print roots print root print no roots
Input coefficients a,b,c
End
< 0
= 0
> 0
201
������������������ �
� ���������
� ������� ��������������
� ������� ��������������
� �������������� ��
� �� � ������ �������
� ������� ��������������
� ������� ��������������
� ����������� ��
� ������ ���������
� �� � ������ �������
� ������� ��������������
� ������� ��������������
21
�����������
delta = (b*b) - (4*a*c); // discrimant computation
if (delta < 0.0) { System.out.println (" No roots");
}
else if (delta > 0.0) { System.out.println (" Two roots :"); System.out.println (" x1 = " + (-b + Math.sqrt(delta))/ (2.0 * a)); System.out.println (" x2 = " + (-b - Math.sqrt(delta))/ (2.0 * a));
}
else { System.out.println (“ Single root: "); System.out.println (" x = " + (-b / (2.0 * a)));
}
221
������������������ �
� ���������
� ������� ��������������
� ������� ��������������
� �������������� ��
� �� � ������ �������
� ������� ��������������
� ������� ��������������
� ����������� ��
� ������ ���������
� �� � ������ �������
� ������� ��������������
� ������� ��������������
23
�������������� ��Start
Computes discriminantDelta = b * b – 4 * a * c
DiscriminantSign
Computes single rootComputes roots
print roots print root print no roots
Input coefficients a,b,c
End
< 0
= 0
> 0
24
�������������� ���&���(������
Start
Computes discriminantDelta = b * b – 4 * a * c
DiscriminantSign
Computes double rootComputes roots
print roots print root print roots
Input coefficients a,b,c
End
< 0
= 0
> 0
Computes Complex roots
25
�����������
delta = (b*b) - (4*a*c); // discrimant computation
if (delta < 0.0) { System.out.println (" No roots");
}
else if (delta > 0.0) { System.out.println (" Two roots :"); System.out.println (" x1 = " + (-b + Math.sqrt(delta))/ (2.0 * a)); System.out.println (" x2 = " + (-b - Math.sqrt(delta))/ (2.0 * a));
}
else { System.out.println (“ Single root: "); System.out.println (" x = " + (-b / (2.0 * a)));
}
26
������������" ������� " ��� ��
delta = (b*b) - (4*a*c); // discrimant computation
if (delta < 0.0) { System.out.println (" No roots");
}
else if (delta > 0.0) { System.out.println (" Two roots :"); System.out.println (" x1 = " + (-b + Math.sqrt(delta))/ (2.0 * a)); System.out.println (" x2 = " + (-b - Math.sqrt(delta))/ (2.0 * a));
System.out.println (" Complex roots"); System.out.println (" x1 real part = " + (-b / (2.0*a))); System.out.println (" x2 imaginary part = " + (-b - Math.sqrt(-delta))/ (2.0*a)+ "i"); System.out.println (" x2 real part = " + (-b / (2.0*a))); System.out.println (" x2 imaginary part= " + (-b - Math.sqrt(-delta))/ (2.0*a)+ "i");
}
else { System.out.println (“ Single root: "); System.out.println (" x = " + (-b / (2.0 * a)));
}
271
������������������ �
� ���������
� ������� ��������������
� ������� ��������������
� �������������� ��
� �� � ������ �������
� ������� ��������������
� ������� ��������������
� ����������� ��
� ������ ���������
� �� � ������ �������
� ������� ��������������
� ������� ��������������
28
����� �����,��� ���)�&���+��*����������,�
X1 X2
X XX
x
y
29
DiscriminatSign
Computes roots case 2 2Computes root case 1
End
< 0
= 0
> 0
X == X1( /X1/ <= X & X <=
/X2/ )
Return True Return False Return True Return False Return False
F FTT
&���+��*����������,��)�������������� ��
30
&�������*�������)�"�( ������� ��
1 Day After
1 Week After
Initial Request
31
&�������*�������)�"�( ������� ��
1 Day After
1 Week After
Few Weeks Later ?
1 Day After
Initial Request Evolution Request
32
�������&���
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("delta > 0"); 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);
} }
331
������������������ �
� ���������
� ������� ��������������
� ������� ��������������
� �������������� ��
� �� � ������ �������
� ������� ��������������
� ������� ��������������
� ����������� ��
� ������ ���������
� �� � ������ �������
� ������� ��������������
� ������� ��������������
34
� �����������-����)����� ��-���
���������� �� � �� � � �
�� �� � ��� ������������� �� � �� � � �
� � ��� ��� ����������� �� � �� � � �
� ��� ������������� �� � �� � � �
35
� �����������-����)����� ��-���
���������� �� � �� � � �
�� �� � ��� ������������� �� � �� � � �
� � ��� ��� ����������� �� � �� � � �
� ��� ������������� �� � �� � � �
� � � �� � �� ��
36
� ������� ���-����# �������� ��
���������� �� � �� � � �
computeRoots()
Double aDouble bDouble c
�� �� � ��� ������������� �� � �� � � �
computeRoots()
� � ��� ��� ����������� �� � �� � � �
computeRoots()
� ��� ������������� �� � �� � � �
computeRoots()
� � � �� � �� ��
37
��� ���-����&���� ���# �������������
���������� �� � �� � � �
computeRoots()create()
�� �� � ��� ������������� �� � �� � � �
computeRoots()
� � ��� ��� ����������� �� � �� � � �
computeRoots()
� ��� ������������� �� � �� � � �
computeRoots()
381
������������������ �
� ���������
� ������� ��������������
� ������� ��������������
� �������������� ��
� �� � ������ �������
� ������� ��������������
� ������� ��������������
� ����������� ��
� ������ ���������
� �� � ������ �������
� ������� ��������������
� ������� ��������������
39
���� ��-���
���������� �� � �� � � �
� � � �� � �� ��
40
���� ��-���)������� ������������������� �� � �� � � �
� � � �� � �� ��
���������� �� � �� � � �� � �� �� ������
41
���� ��-���)������� ������������������� �� � �� � � �
� � � �� � �� ��
���������� �� � �� � � �� � �� ��
42
� ������� ���-����# �������� ��
���������� �� � �� � � �
computeRoots()
Double aDouble bDouble c
�� �� � ��� ������������� �� � �� � � �
computeRoots()
� � ��� ��� ����������� �� � �� � � �
computeRoots()
� ��� ������������� �� � �� � � �
computeRoots()
� � � �� � �� ��
43
� ��� � ����
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; }
}
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 NoRootPolynome(a,b,c,theDiscriminant); }
}
45
�����������*��� ��������&�����
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); }
}
461
������������������ �
� ���������
� ������� ��������������
� ������� ��������������
� �������������� ��
� �� � ������ �������
� ������� ��������������
� ������� ��������������
� ����������� ��
� ������ ���������
� �� � ������ �������
� ������� ��������������
� ������� ��������������
47
��� ���-����# �������� ��
���������� �� � �� � � �
computeRoots()
Double aDouble bDouble c
�� �� � ��� ������������� �� � �� � � �
computeRoots()
� � ��� ��� ����������� �� � �� � � �
computeRoots()
� ��� ������������� �� � �� � � �
computeRoots()
� � � �� � �� ��
48
&������������)�� ����*���������� �
void computesRoots() {
System.out.println (" Single root: ");
System.out.println (" x = " + (-b / (2.0*a)));
}
49
��� ���-����# �������� ��
���������� �� � �� � � �
computeRoots()
Double aDouble bDouble c
�� �� � ��� ������������� �� � �� � � �
computeRoots()
� � ��� ��� ����������� �� � �� � � �
computeRoots()
� ��� ������������� �� � �� � � �
computeRoots()
� � � �� � �� ��
50
&������������)��#��*����������� �
void computesRoots() {
System.out.println (" Two roots :");
System.out.println (" x1 = " + (-b + Math.sqrt(discriminant.value()))/ (2.0*a));
System.out.println (" x2 = " + (-b - Math.sqrt(discriminant.value()))/ (2.0*a));
}
51
��� ���-����# �������� ��
���������� �� � �� � � �
computeRoots()
Double aDouble bDouble c
�� �� � ��� ������������� �� � �� � � �
computeRoots()
� � ��� ��� ����������� �� � �� � � �
computeRoots()
� ��� ������������� �� � �� � � �
computeRoots()
� � � �� � �� ��
52
&������������)�.��*���������� �
void computesRoots() {
System.out.println (" No roots");
}
531
������������������ �
� ���������
� ������� ��������������
� ������� ��������������
� �������������� ��
� �� � ������ �������
� ������� ��������������
� ������� ��������������
� ����������� ��
� ������ ���������
� �� � ������ �������
� ������� ��������������
� ������� ��������������
54
��� ���-����# �������� ��
���������� �� � �� � � �
computeRoots()
Double aDouble bDouble c
�� �� � ��� ������������� �� � �� � � �
computeRoots()
� � ��� ��� ����������� �� � �� � � �
computeRoots()
� ��� ������������� �� � �� � � �
computeRoots()
� � � �� � �� ��
55
��� ���-����# �������� ��
���������� �� � �� � � �
computeRoots()
Double aDouble bDouble c
�� �� � ��� ������������� �� � �� � � �
computeRoots()
� � ��� ��� ����������� �� � �� � � �
computeRoots()
� � � � �� �� ��� ����������� �� � �� � � �
computeRoots()
� � � �� � �� ��
56
&������������)�&���(�*����������� �
void computesRoots() {
System.out.println (" Complex roots");
System.out.println (" x1 real part = " + (-b / (2.0*a)));
System.out.println (" x1 imaginary part = “
+ (-b + Math.sqrt(-discriminant.value()))/ (2.0*a)+ "i");
System.out.println (" x2 real part = " + (-b / (2.0*a)));
System.out.println (" x2 imaginary part = “
+ (-b - Math.sqrt(-discriminant.value()))/ (2.0*a)+ "i");
}
571
������������������ �
� ���������
� ������� ��������������
� ������� ��������������
� �������������� ��
� �� � ������ �������
� ������� ��������������
� ������� ��������������
� ����������� ��
� ������ ���������
� �� � ������ �������
� ������� ��������������
� ������� ��������������
58
��� ���-���
���������� �� � �� � � �
computeRoots()isInBetweenRoots()
�� �� � ��� ������������� �� � �� � � �
computeRoots()isInBetweenRoots()
� � ��� ��� ����������� �� � �� � � �
computeRoots()isInBetweenRoots()
� ��� ������������� �� � �� � � �
computeRoots()isInBetweenRoots()
59
/���+����������������)�� ��������
boolean isInBetweenRoots(double x) {
return (x == x1);
}
60
��� ���-���
���������� �� � �� � � �
computeRoots()isInBetweenRoots()
�� �� � ��� ������������� �� � �� � � �
computeRoots()isInBetweenRoots()
� � ��� ��� ����������� �� � �� � � �
computeRoots()isInBetweenRoots()
� ��� ������������� �� � �� � � �
computeRoots()isInBetweenRoots()
61
/���+����������������)��#�������
boolean isInBetweenRoots(double x) {
return (Math.abs(x1) <= Math.abs(x)) &&
(Math.abs(x) <= Math.abs(x2));
}
62
��� ���-���
���������� �� � �� � � �
computeRoots()isInBetweenRoots()
�� �� � ��� ������������� �� � �� � � �
computeRoots()isInBetweenRoots()
� � ��� ��� ����������� �� � �� � � �
computeRoots()isInBetweenRoots()
� ��� ������������� �� � �� � � �
computeRoots()isInBetweenRoots()
63
/���+����������������)���������
boolean isInBetweenRoots(double x) {
return false;
}
64
����0�� ��111