Premise:Perhaps you dossed down at the back sit in your class when your teacher in kindergarten taught your class members quadratic equation. This is a quick review of what they have learnt.
An equation of the general form:
She (your teacher during your kindergarten days) also said that one can solve a quadratic equation using any of the following methods:
1. FactorizationShe said that the formula method can solve any type of quadratic equation and for that reason she renamed it to be; ALMIGHTY FORMULA. This raised a very serious issue during the class because those that are very religious like you are, starts shouting: No! No! No! When one of them was asked he said, "How can just an ordinary formula be called Almighty".
2. Completing the Square
3. Formula
4. Graph
However, the issue is not our problem here, but to write out the steps that solve quadratic equation using the formula. Only to wake up from your sleep, you found the class empty, everyone has already left the class, and what remains in the class was just the formula that caused the problem and here it is again standing below:
The above formula is the formula which can be applied in the formula method to get the actual roots x, of the equation. The roots x, of the equation is the two values of the unknown that will satisfy the equation. So, that you escaped from it by sleeping in your class does not mean that you have finally escaped the trouble.
The quantity:
Is called the discriminant of the quadratic equation. The roots of a quadratic equation depend on the value of the discriminant which can either be positive, negative or zero.
From here, using the discriminant let us establish a rule:
1. If b * b - (4) * (a) * (c) > 0. Then the roots are real and distinct or different.
2. If b * b - (4) * (a) * (c) = 0 Then the roots are real and equal or coincident.
3. If b * b - (4) * (a) * (c) < 0 Then the roots are imaginary or complex.
If you have written a prgramme (or an algorithm) that solve quadratic equation and you did not consider item 3 above then you algorithm is not thorough.
So using the rule we can finally write our algorithm:
Solution:
Major Steps
1. Request Data
2. Calculate Data
3. Display Roots
Stepwise Refinement
1. Request Data
1.1 Request a
1.2 Request b
1.3 Request c
2. Calculate Root
2.1 discriminant = b * b - 4 * a * c
2.2 IF discriminant > 0 THEN
2.2.1 puppy = SquareRoot(discriminant)
2.2.2 firstRoot = (-b + puppy) / (2 * a)
2.2.3 secondRoot = (-b - puppy) / (2 * a)
2.3 ELSEIF discriminant = 0 THEN
2.3.1 doubleRoot = -b / (2 * a)
ELSE
2.4 discriminant < 0 THEN
2.4.1 puppy = SquareRoot(-discriminant)
2.4.2 RealPart = -b / (2 * a)
2.4.3 ImaginaryPart = puppy / (2 * a)
3. Display Root
3.1 IF line 2.2 THEN
3.1.1 Display firstRoot, secondRoot
3.2 ELSEIF line 2.3 THEN
3.2.1 Display doubleRoot
ELSE
3.3 Display RealPart, ImaginaryPart
1. Request Data
2. Calculate Data
3. Display Roots
Stepwise Refinement
1. Request Data
1.1 Request a
1.2 Request b
1.3 Request c
2. Calculate Root
2.1 discriminant = b * b - 4 * a * c
2.2 IF discriminant > 0 THEN
2.2.1 puppy = SquareRoot(discriminant)
2.2.2 firstRoot = (-b + puppy) / (2 * a)
2.2.3 secondRoot = (-b - puppy) / (2 * a)
2.3 ELSEIF discriminant = 0 THEN
2.3.1 doubleRoot = -b / (2 * a)
ELSE
2.4 discriminant < 0 THEN
2.4.1 puppy = SquareRoot(-discriminant)
2.4.2 RealPart = -b / (2 * a)
2.4.3 ImaginaryPart = puppy / (2 * a)
3. Display Root
3.1 IF line 2.2 THEN
3.1.1 Display firstRoot, secondRoot
3.2 ELSEIF line 2.3 THEN
3.2.1 Display doubleRoot
ELSE
3.3 Display RealPart, ImaginaryPart
Explanation:I observe that my conditional statements changed. The way i normally make use of condition(s) changed at line 2.2, 2.3 and 2.4. However we are familiar with line 2.2.
If observed closely that we have three (3) conditions above that we used in making a test.
First one is: line 2.2: IF discriminant > 0 THEN obey lines 2.2.1, 2.2.2 and 2.2.3. So if the test is true; that the value of discriminant is greater than zero; then the next actions/steps to perform/obey/follow are the lines below it (lines 2.2.1, 2.2.2 and 2.2.3).
Line 2.3: ELSEIF discriminant = 0 THEN obey line 2.3.1. ELSEIF is a Qbasic (a compiler from Microsoft) keyword/syntax (a control programme control structure or construct) for given multiple conditions. In java it is written: "else If ". Therefore it shows that the condition/test at line 2.2 is different from that at line 2.3. Line 2.3 will execute/obey if line 2.2 is false.
If the algorithm finds lines 2.3 and 2.3 to be false ELSE it will check the condition at line 2.4. Therefore ELSE (“else” in Java) shows that we or the algorithm have reached the end of the conditions/test, and that is how it use in many programming languages.
Suppose we have 5 conditions this is the programme constructs for them:
IF <condition(s)> THENNote that statement-1 to statement n are multiple statements under a particular condition(s) however it can also be one statement only.
statement-1
statement-2
statement-3
...
statement-n
ELSEIF <condition(s)> THEN
statement-1
...
statement-n
ELSEIF <condition(s)> THEN
statement-1
...
statement-n
ELSEIF <condition(s)> THEN
statement-1
...
statement-n
ELSE
statement-1
...
statement-n
END
IF (checks the first condition(s) and)
ELSEIF (checks the second condition(s))
ELSEIF (checks the third condition(s))
ELSEIF (checks the fourth condition(s))
ELSE (checks the fifth condition(s)).
If any of the conditions above is true the statement below it is what will be obeyed.
In line 3.0: To display the root we have to make a test to know which of the conditions; “2.2, 2.3 and 2.4”; we are to display.
Line 3.1 say if it was line 2.2 that was obeyed above then obey 3.1.1, line 3.2: ELSEIF line 2.3 then obey line 3.2.1, ELSE obey lines 3.3. Line 3.1 to 3.3 May not be represented as it is above in a standard programming language. They will (i.e. lines 3.1.1, 3.2.1 and 3.3) be under the above conditions 2.2, 2.3 and 2.4 respectively.
Every other things (i.e the arithmetic) in the algorithm is what your teacher taught your class members while you are asleep.
The next examples will be the application of what we have learned so far!
SHARE THIS POST WITH YOUR FRIENDS...::
Tweet
0 comments:
Leave a Reply