Software Engineering Development Processes
Total Page:16
File Type:pdf, Size:1020Kb
SOEN 6011
SOFTWARE ENGINEERING DEVELOPMENT PROCESSES
Summer 2015
Instructor: Dr. Pankaj Kamthane
Deliverable 1
A SCIENTIFIC PROJECT IN THE SMALL
Team E
Ishan Monga Ahmed Moumneh Saketh Mudrakola Muhammad Nadir Jithin Nair Rohan Nayak Aman Ohri
Contents Details and contribution
http://soen6471teamg. wikispaces .com/(link here)
Name of Team Member Details of Contributions OK: Monga Ishan OK:
OK: Ahmad Moumneh OK: PIPower(x) function and power function
OK: Rohan Nayak
OK: Nadir
OK: Saketh
1. Introduction
1.1 Purpose
The purpose of this document is to elucidate the initial set of requirements for designing and implementing scientific calculator’s basic transcendental functions. This document also covers the testing results against the requirements. 1.2 Scope
The scope of this document is to address the requirements and different set of choices for implementing the transcendental with the rationale for choosing the particular implementation from the set of different available algorithms. The document is intended for both technical and non-technical stakeholders but a prior knowledge of mathematics’ function is required. This document also contains test results. 1.3 Overview 2.0 Functional Requirements
Functional requirement describes about the functions of a component and its related operations. In our project, the functional operations are the mathematical calculations of various transcendental functions with a set of choices like sine, cosine, tan, x^x, 10^x, root of x, log x.
The calculator must accept and parse the input values from the console The implementations of all the transcendental functions are programmed in Python language. The calculator must also perform primary arithmetic operations (addition, subtraction, multiplication and division) in addition to the transcendental functions. The results generated after the computation should be valid when compared with the actual results.
3.0 Non Functional requirements
Non-Functional requirements describes about the working of the application and also defines the quality attributes of the system. In this project, our calculator exhibits certain non-functional requirements like usability, flexibility, performance.
The calculator must allow the user to enter the values within a specified range. The output of the transcendental functions must be clearly visible on the console The calculator must be user friendly and flexible to operate all the transcendental functions. 4.0 Transcendental functions
Selected functions-
4.1 Sine Function
4.1 Power Function 4.2 Sine (x)
The Sine function is a trigonometric function and is usually defined in the context of a right angle. The precision of the sine function is around 10 digits to reduce the execution time and give the result faster.
The function sin(x) is computed by using the Taylor series method [1] and is given as –
Sin(x) = x – x^3/3! + x^5/5! –x^7/7! + ….
4.2.1 Decision Making
The sine function for a given input can be computed by using different techniques
1) Taylor Series The Taylor series of a function is computed based on the Taylor’s theorem which states that any function satisfying certain conditions can be expressed as a Taylor series [2]. The sine function can be calculated using the Taylor’s function by using the formula –
Sin(x) = x – x^3/3! + x^5/5! – x^7/7! + ….
The Taylor series has been considered for the implementation of the sin(x) function as it has a few advantages over the other methods. It has less number of iterations when compared to the other functions and is easy to implement as it involves basic mathematical calculations.
2) CORDIC Algorithm Coordinate Rotation Digital Computer (CORDIC) algorithm can be used to compute transcendental and trigonometric functions by using table look-up, shift and addition operators [3]. With the help of this algorithm, an adder/subtractor, a small look up table and a shifter the trigonometric functions can be calculated very easily [3]. The vector V (X,Y) is rotated through an angle , a new vector V’(X’,Y’) is formed by
The sine value of the input value can be computed using this formula.
Drawbacks of this Implementation
More number of mathematical operations should be computed to get the value of sine The algorithm takes a longer time to execute due to its iterative nature Less efficient and precise output compared to the Taylor’s series 4.2.2 Algorithm
The Taylor series has been chosen to compute the algorithm for its advantages over the CORDIC algorithm. The formula for computing the algorithm has been mentioned above. A special power function has been constructed which can be reusable for all the functionalities that have been used in the design of the calculator.
Power Function description
The power function is used to compute the even and odd powers of x. Similarly an Independent factorial function has been implemented for reusability while computing the values of sin(x) and cos(x). A description of the working of the algorithm is given as follows – The use of the Taylor series algorithm makes it possible for the computation of any value for the sin angle by using basic arithmetic operations like addition, subtraction, multiplication and division. A polynomial approximation to calculate the value of sin of the angle of x.
4.2.3 Tests and Results
4.2.4 Accuracy and Precision
The accuracy of the result is directly proportional to the results and the total number of terms, more terms give more accuracy. The precision of the result depends on the range of the for condition in the implementation.
4.2.5 Graph 4.2.6 Procedure for computing Sine Function
The procedure takes the following cases –
Case 1:
1) If the value >360, it should be converted into 360(n) +/- x where n = (1,2,3…., n) and then the value of sin x is computed with remainder and go to step 2. 2) If the value is 0 less than or equal to 360, then If the value lies between 0 and 180 then convert the sin into sin (90+/-x) which is cos(x) If the value lies between 180 and 360 then convert the sin into sin (270+/-x) which is –cos(x) The above mentioned implementation is the general method for getting the value of sin(x) and to get the value into the 2-dimensional Cartesian plane.
Case 2:
For further improvement we can consider the following steps – 1) If we can compute and save the values of sin 0, sin 30, sin 45, sin 60, sin 90 and cos 0, cos 30, cos 45, cos 60, cos 90 initially, it would be useful for better accuracy, precision and speed. 2) If we need to calculate the value of sin(47.3), the procedure is illustrated in the following manner: 3) sin(47.3) =sin(45+2.3). 4) sin(45+2.3) is in the form of sin(A+B). 5) sin(A+B) = sin(A)*cos(B) + cos(A)*sin(B). 6) So the expansion for Sin (45+2.3) = Sin (45)*Cos(2.3) + Cos(45)* Sin(2.3) 7) The values of Sin (45) and Cos (45) are already computed and saved so the values Cos (2.3), Sin (2.3) will follows the Taylor series formula. Using Taylor series the values of cos (2.3), sin (2.3) are computed. 8) After getting the values from Taylor series the value for sin (47.3) is known.
4.3 Cos(x)
Just like the Sine function, the Cosine function is also a trigonometric function and is usually defined in the context of a right angle. The common definition of the cosine of an angle in a right triangle is as the ratio of the lengths of the side of the triangle adjacent to the angle and the hypotenuse
4.3.1 Decision Making
1) Taylor Series The computation of the cosine function is done by using the Taylor series expansion and it is defined by the following expression –
The polynomial expression needs to be computed first to evaluate the cosine function. The value obtained can be more precise with a small number and small number of iterations.
2) CORDIC Algorithm The CORDIC implementation can be used to calculate the cosine function as well. It is not used for its drawbacks.
4.3.2 Algorithm
The Taylor series is used to compute the value of cos x. The value obtained after computing this expression is valid for all real values of x. More iterations will help obtain a more precise value. Taylor series is preferred as it gives a more precise result.
4.3.3 Table of Results
4.3.4 Accuracy and Precision
The accuracy of the result is directly proportional to the results and the total number of terms, more terms give more accuracy. The precision of the result depends on the range of the for condition in the implementation.
4.3.5 Graph 4.4 10^X
It is basically an exponential function. It is written as f(x) =10x.
4.4.1 Decision Making
When the exponent increases by 1, the value of the base 10 function increases by a factor of 10. On the other side, if the exponent decreases by 1, then the value of the function becomes 1/10. [1]
4.4.2 Examples
a. If the base is 10 and x = 3:
Log (10 x) = log (10 3) = log 1000 = 3
If the base is 10 and x = 1000:
10 (log x) = 10 (log 1000) = 10 3 = 1000
b. What is 2.45 x 104?
You can calculate it as: 2.45 x (10 × 10 × 10 × 10) = 2.45 x 10,000 = 24,500
c. Negative powers of 10
9 × 10-3 = 9 ÷ 10 ÷ 10 ÷ 10 = 0.009 1 1 1 5.1x ( /10 × /10 × /10) = 5.1 × 0.001 = 0.0051
4.4.3 Algorithm
The user enters the input and the power function is used to compute 10 to the power of x. x is the input entered by the user.
4.4.4 Steps of Procedure
1) User enters the input i.e., value of x. 2) User runs the program. 3) System displays the output value. 4) All the output values can be seen in the console.
4.4.5 Table of Results
4.4.6 Accuracy and Precision The smaller the value of x, the higher the accuracy and precision.
4.4.7 Graph
4.5 X power X function
This function is the most trivial function of all the implemented functions.
4.5.1 Decision Structure
Exponentiation can be done to solve this problem. The entered input is considered as the base as well as the power.
4.5.2 Algorithm
The user enters the input and the power function is used to compute 10 to the power of x. x is the input entered by the user.
4.5.3 Steps of Procedure
1) User enters the input i.e., value of x. 2) User runs the program 3) System displays the output value. 4) All the output values can be seen in the console. 4.5.4 Table of Results
4.5.5 Accuracy and Precision
The smaller the value of x, the higher the accuracy and precision.
4.5.6 Graph
4.6 πx Function
In order to calculate πx we 1st generate the π value and use power function to calculate πx Infinite series allowed mathematicians to compute π with much greater precision than other geometrical techniques.
4.6.1 Decision Structure
Some of the infinite series are
1) Gregory-Leibniz series for π
Given as
π is 4 times Gregory-Leibniz series i.e.,
π=4(1-1/3+1/5-1/7+………………………………..) π=4( )
2) Nilakantha’s series for π
4.6.2 Algorithm
The Gregory-Leibniz function is used to calculate the value of π as it is more efficient. The designed power function is used to compute the value of πx where x is the value entered by the user.
4.6.3 Steps of Procedure
1) User enters the input i.e., value of x. 2) User runs the program. 3) System displays the output value. 4) All the output values can be seen in the console
4.6.4 Table of Results
4.6.5 Accuracy and Precision
The Gregory-Leibniz smaller the value of x, the higher the accuracy and precision.
4.6.6 Graph 4.7 √x
A square root of a number is a number y such that y2 = a. Square is the result of multiplying a number by itself and then finding its root gives us square root of a number. Every non-negative real number has a unique non-negative square root called the principal square root. The term whose root is being considered is known as the radicand. Every positive number has two square roots: √a which is positive and -√a which is negative. Together these two roots are denoted by ± √a.
Square root is given as under:
For all real numbers x
4.7.1 Decision Making
1) Computing √x using Babylonian Method The first algorithm used for approximating √S is known as the Babylonian Method. We chose this method because it is simpler as compared to other methods and more efficient as well. This method is the reduction to the Newton’s method, so it is much simplified and better as compared to Newton’s method. Its working and algorithm is defined in the next section for the algorithm, as we have selected Babylonian Method for the implementation of Square Root function.
2) Computing √x using Newton-Raphson Method Named after Isaac Newton and Joseph Raphson, is a method for finding successively better approximations to the roots (or zeroes) of a real-valued function. Given a function ƒ defined over the reals x, and its derivative ƒ', we begin with a first guess x0 for a root of the function f.
For example, if you wish to find the square root of 16, so this is equivalent to:
X2 = 16
The function to use in Newton’s method is then,
With derivative,
3) Computing √x using Guess, Evaluate, Improve Method This method is simple as compared to others but its implementation is somewhat not that simple. This method basically works on a guessing technique. The guess is then evaluated and after evaluation it is further improved. The three steps involved in this method are as follows: Pick a guess Evaluate the guess If the guess is not near enough, improve it
Example how it works:
Consider a number let’s say 2 is being considered for square root. The square root is going to be a floating point number (square root of 2 = 1.414213562373095). Now if you multiply this number, the square root of 2 by itself, you should expect to have 2 as an answer. Well, that's not going to happen, rather you're going to get (2.0000000000000004). This is happening due to the way that computers handle floating point numbers. In this case if you used the term equals (or == operator) when evaluating the guess you will never make it, and your program will not halt.
4.7.2 Algorithm for Babylonian Method The basic idea is that if x is an overestimate to the square root of a non-negative real number S then will be an underestimate and so the average of these two numbers may reasonably be expected to provide a better approximation. Finding √S is the same as solving the equation f(x) = x2-S. Newton’s method in this case reduces to the Babylonian Method:
If x is our initial guess of √S and e is the error in our estimation, such that S = (x+e) 2, then we can expand the binomial and solve for:
Since the computed error was not exact, this becomes our next best guess. The process of updating is iterated until desired accuracy is obtained. So, it can also be represented as:
4.7.3 Nth Root Algorithm
Nth root algorithm for finding :
1. x0 = 0
2. Do recursive step: . 3. Repeat step 2 until the desired precision is reached. By setting n = 2, this will compute the square root. We adopted this algorithm in order to implement the square root function because it is a fast-con- verging algorithm and it is easy to impelement. 4.8.5 Accuracy and Precision
The precision of the result of square root of x is 106;
4.8.6 Graph \ 4.7.4 Test Results
Input Observed Output Actual Value Relative Error
4.7.5 Graph 4.8 e^x Function
The e^x function is an exponential function with a rate of change which is proportional to the function and is expressed in terms of an exponential function; e is a number which is called as Napier’s number and it’s approximate value is 2.718281828. x is the power value of the exponent e. Based on the exponent e value 2.718281828 and raised to the power of x [].
4.8.1 Decision Making
1) Implementing the power series of any given x
This approach is considers the first 30 terms in the series for a precision of 10 digits for higher values of x. This is a very tedious approach and is not used.
2) Using exp(x)-y=0
This algorithm is used to find the root and will be considered in the future iterations of the project.
3) Using Exponential Property
Exp (x1) can be expressed in 2^y; x1=yln2 Where y.ln2<=x [ln2 is natural logarithm of 2] and y is a whole number. Now find the exp(x2) using the power series where x2=x-x1; The series can be re-written as Exp (x) = 1 + (x/1) (1 + (x/2) (1 + (x/3) (...... ) ) ) Multiply exp(x0) calculated before and exp(x1) which is exp(x). This approach reduces x1 largely to less than 1.
4.8.2 Algorithm
The value can be computed by using the following expression –
4.8.4 Test Results
Input Observed Output Actual Value Relative Error
e1 2.718281826198493 2.718281828459045 e2 7.38905609893065
e3 e4
e5
4.8.5 Accuracy and Precision
4.8.6 Graph
4.1.1 Implementation choices 4.1.2 Decision making and rationale 4.1.2.1 Advantages and disadvantages 4.1.3 Algorithm and implementation 4.1.4 Test results 4.1.5 Precision and accuracy
5.0 Glossary 6.0 REFERENCES