Most viewed recipes by Fouad Teniou http://code.activestate.com/recipes/users/4155345/views/2011-02-02T12:53:01-08:00ActiveState Code RecipesOdd-Even Recursion (Python) 2009-06-27T05:10:15-07:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/576747-odd-even-recursion/ <p style="color: grey"> Python recipe 576747 by <a href="/recipes/users/4155345/">Fouad Teniou</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). Revision 6. </p> <p>Odd-Even Recursion program is a recursive function, which does produce a positive or a negative set of odd or even numbers. However, the function return numbers which are lower or greater than the value of the number entered by the user until it reaches its base case value, where the function returns a value and the recursion stops. Though solving repetitive problems requires a powerful method and yet recursion allows the design of faster recursive algorithms. Recursion method could be used to solve higher-level mathematics' problems, such as sequences and it is a branch in the computer science study.</p> Anagrams, vowels, and consonants. (Python) 2011-01-19T12:22:10-08:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/577265-anagrams-vowels-and-consonants/ <p style="color: grey"> Python recipe 577265 by <a href="/recipes/users/4155345/">Fouad Teniou</a> (<a href="/recipes/tags/text/">text</a>). Revision 7. </p> <p>An anagram could be a word, or a sentence, of which the letters could be rearranged to form a different word, or a different sentence.</p> <p>However, vowels and consonants could be combined to form a syllable.</p> <p>Though, counting the numbers of vowels and consonants forming a word or a phrase, is a writing technique to enhance the writing style, and balance the phonetic. </p> <p>My program Anagrams, vowels, and consonants, allows you to compute the numbers of vowels, and consonants forming a word, a sentence, or a full text, and rearrange the letters forming every word within a text in every possible combination, thus, finding anagrams for each word within the sentence.</p> nth-Root (Python) 2011-01-29T12:29:38-08:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/576857-nth-root/ <p style="color: grey"> Python recipe 576857 by <a href="/recipes/users/4155345/">Fouad Teniou</a> (<a href="/recipes/tags/mathematics/">mathematics</a>). Revision 5. </p> <p>I realised a lack of an nth root function within Python maths' modules, even though, you could fulfil the task by using the power function, and I wrote nth-Root program. However, I used Newton’s method Xn+1 = Xn - f(Xn)/f’(Xn) , n = 1,2,3... and worked out myself the formula to solve the equation X^(b) - a for nth-root(a) as follows: Xn+1 = 1/b((b-1)Xn + a/Xn^(b-1)). Though my program nth-Root uses a generator to generate each value approximation in the sequence from its predecessor, and it display the nth root value once two equal values are generated. Nowadays Scientifics’ calculators display 9 digits to the right of a decimal point and my program nth-Root displays a 16 figures precision to the right of a decimal point.</p> Circle (Python) 2011-02-02T12:53:01-08:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/576531-circle/ <p style="color: grey"> Python recipe 576531 by <a href="/recipes/users/4155345/">Fouad Teniou</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). Revision 18. </p> <p>Circle is a program for students and tutors in higher education. Circle program provide the user with the standard form ( x –x0)^2 + (y-y0)^2 = r^2, radius and centre(x0,y0), once the user input the Constants' values of the circle Equation of the form Ax^2 + Ay^2 + Dx + Ey + F = 0. if r^2 = 0, Circle program point and display that the graph is the single point (x0,y0), and if r^2 &lt; 0 , Circle program point that the equation has no real solutions, thus no graph. However Circle program also does compute and display the reverse method if the user input the radius and centre values, it display both forms of the circle equation </p> Maclaurin's_series_exponential(x) (Python) 2010-07-07T12:52:28-07:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/577293-maclaurins_series_exponentialx/ <p style="color: grey"> Python recipe 577293 by <a href="/recipes/users/4155345/">Fouad Teniou</a> (<a href="/recipes/tags/mathematics/">mathematics</a>). </p> <p>C. Maclaurin. A Scottish mathematician gained his master degree at age 17, and his major mathematics' work arise from his special knowledge in Newton's ideas and the formulation of Newton's methods.</p> <p>However, C. Maclaurin also contributed to the astronomy science and helped to improve maps and invented some mechanical devices .</p> <p>My mathematics python's programs is a set of Maclaurin's series to compute some of the most important functions in calculus.</p> <p>Though, the computation of an infinite sum which give the value of a function in terms of the derivatives evaluated at a special case where x0 = 0,in contrast with Taylor series. </p> <p>The natural exponential function e^x has a constant base e and a variable x and Maclaurin's series to approximate the natural exponential converge on the interval ]-inf , + inf [.</p> Quadratic (Python) 2011-01-28T12:46:37-08:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/576407-quadratic/ <p style="color: grey"> Python recipe 576407 by <a href="/recipes/users/4155345/">Fouad Teniou</a> (<a href="/recipes/tags/algorithm/">algorithm</a>). Revision 19. </p> <p>Quadratic can be used by students for solving quadratic equations ax^2+bx+c a!=0, which are given by the quadratic formula x = -b + SQUARE-ROOT(b^2-4<em>a</em>c)/2<em>a and x = -b - SQUARE-ROOT(b^2-4</em>a<em>c)/2</em>a However,if b^2-4<em>a</em>c is negative the solutions are not real but complex numbers of the form a+bj. Though, both real and complex solutions are called using Quadratic</p> Converter (Python) 2009-03-07T04:42:51-08:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/573457-converter/ <p style="color: grey"> Python recipe 573457 by <a href="/recipes/users/4155345/">Fouad Teniou</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). Revision 8. </p> <p>Converter can be used to convert fundamental measures, metric, mass, liquid and temperature. The output is set to give the best conversion accuracy and layout that could be used for professional projects</p> Ellipse (Python) 2009-02-14T04:09:28-08:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/576513-ellipse/ <p style="color: grey"> Python recipe 576513 by <a href="/recipes/users/4155345/">Fouad Teniou</a> (<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/algorithms/">algorithms</a>). Revision 8. </p> <p>In early 1600 Johannas Kepler conclude that all the planets in the solar system move in elliptical orbits with the sun at a focus, thus, the importance of ellipse in science. Ellipse is a Python program for students and tutors at higher levels of education . There are two equations of an ellipse : x^2/a^2 + y^2/b^2 and: x^2/b^2 + y^2/a^2 the foci are on the x axis or y axis. From Ellipse program the student will be able to sketch the ellipse, by drawing a box with (a) and (-a) units on the major axis and ( b) and (-b) units on the minor axis. Since Ellipse program determine the values of a and b and the position of the foci c. c = Square-Root (a^2 – b^2)</p> Binary_Decimal Recursion (Python) 2010-02-23T04:39:41-08:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/577034-binary_decimal-recursion/ <p style="color: grey"> Python recipe 577034 by <a href="/recipes/users/4155345/">Fouad Teniou</a> (<a href="/recipes/tags/mathematics/">mathematics</a>). Revision 5. </p> <p>The most commonly used number system is the denary number system, a system of numbers to base 10. However, All the others numbers systems are used in the computing field. And the binary number system, a system of numbers to base 2 uses only two digits 0 and 1, and any position in a binary number system increases by powers of 2 in contrast with the decimal system, which increases by powers of 10. <strong>Though, the binary number system was invented by a Chinese poet and philosopher Shao Yong in the 11th century.</strong> Solving repetitive problems requires a powerful method and yet recursion allows the design of faster recursive algorithms. Recursion method could be used to solve higher-level mathematics problems, such as sequences and it is a branch in computer science study.</p> Rectangle_Method (Python) 2011-01-20T12:28:15-08:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/576897-rectangle_method/ <p style="color: grey"> Python recipe 576897 by <a href="/recipes/users/4155345/">Fouad Teniou</a> (<a href="/recipes/tags/mathematics/">mathematics</a>). Revision 6. </p> <p>My program Rectangle_Method could be used for finding areas of an interval [a,b] under a curve y = f(x) by dividing the interval [a,b] into n equal subintervals and constructing a rectangle for each subinterval. However, the greater the number of subintervals (n) the better is the approximation of the area, though, we should choose an X_k value to find the height of a rectangle in each subinterval, thus, assessing the curve y = f(x). The left endpoint, the right endpoint or the midpoint approximations of each subinterval could be used to compute the area under the curve y = f(x). The rectangle method ( midpoint approximation ) could be used to approximate mathematics' functions, such as integrals, ln, log, trigonometric functions ( sin, cos, tan, cot ), the value of Pi and other functions with accuracy, the higher the value of (n) the more accurate the result, and my mathematics' program Rectangle Method could be used for this purpose.</p> Pycol (Python) 2011-01-22T15:03:42-08:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/576374-pycol/ <p style="color: grey"> Python recipe 576374 by <a href="/recipes/users/4155345/">Fouad Teniou</a> (<a href="/recipes/tags/algorithms/">algorithms</a>). Revision 59. </p> <p>Pycol can be used by students to compute trigonometric functions,(Sine,Cosine,Tangent,Cosecant,Secant, and Cotangent) of an angle(X) expressed in degrees rather than radians, since this is not available in Python math or cmath modules. Yet it is a standard method of measuring such ratios at colleges,universities and all mathematics books including Calculus. Pycol can also be used to express angles from degrees into radians and vice versa, and into degrees, minutes, and seconds</p> EOQ (Python) 2009-02-17T03:20:33-08:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/576651-eoq/ <p style="color: grey"> Python recipe 576651 by <a href="/recipes/users/4155345/">Fouad Teniou</a> (<a href="/recipes/tags/financial/">financial</a>, <a href="/recipes/tags/management/">management</a>). Revision 3. </p> <p>Economic order quantity (EOQ) model is used in stock control by many companies rather than other stock control systems such as the Just-in-Time model. Though, ACCA’s students will benefit from this program while preparing their ACCA course and exam in financial management towards their ACCA professional qualification, yet financial management professionals already holding posts within companies using this system will be able to compare different sets of item quantities and rates to reduce their company’s total cost of holding and ordering such items.</p> Factorial-Lambda (Python) 2011-01-27T12:40:22-08:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/576616-factorial-lambda/ <p style="color: grey"> Python recipe 576616 by <a href="/recipes/users/4155345/">Fouad Teniou</a> (<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/math/">math</a>). Revision 4. </p> <p>If n is a positive integer,factorial(n!) is the product of all the positive integers from 1 up to the given integer. However, different types of functions are applied,including the anonymous lambda to generate the factorial number, because it is simple and returns a value ( a new function ), which can be assigned a name.</p> Sphere (Python) 2010-05-06T12:28:12-07:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/577218-sphere/ <p style="color: grey"> Python recipe 577218 by <a href="/recipes/users/4155345/">Fouad Teniou</a> (<a href="/recipes/tags/mathematics/">mathematics</a>). Revision 3. </p> <p>A sphere is a ball, similar to a circle in three dimension, and all its surface’s points are equidistant from the centre.</p> <p>However, the distance from the centre point to the surface is called the radius, and the equation of the sphere is : (x-a)² + (y-b)² + (z-c)² = r² .</p> <p>(a,b,c) are the coordinates of the centre and r is the radius.</p> Maclaurin's_series_sin (Python) 2010-07-07T12:05:33-07:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/577287-maclaurins_series_sin/ <p style="color: grey"> Python recipe 577287 by <a href="/recipes/users/4155345/">Fouad Teniou</a> (<a href="/recipes/tags/mathematics/">mathematics</a>). </p> <p>C. Maclaurin. A Scottish mathematician gained his master degree at age 17, and his major mathematics' work arise from his special knowledge in Newton's ideas and the formulation of Newton's methods.</p> <p>However, C. Maclaurin also contributed to the astronomy science and helped to improve maps and invented some mechanical devices.</p> <p>My mathematics python's programs is a set of Maclaurin's series to compute some of the most important functions in calculus.</p> <p>Though, the computation of an infinite sum which give the value of a function in terms of the derivatives evaluated at a special case where x0 = 0,in contrast with Taylor series. </p> <p>It is assumed that the angle is expressed in radian while using the Maclaurin's series to approximate the trigonometric functions sine and cosine, thus, converting the angle into degrees in my program could be useful for students who prefer using degrees.</p> Maclaurin's_series_ln(x) (Python) 2010-07-15T11:16:30-07:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/577300-maclaurins_series_lnx/ <p style="color: grey"> Python recipe 577300 by <a href="/recipes/users/4155345/">Fouad Teniou</a> (<a href="/recipes/tags/mathematics/">mathematics</a>). Revision 8. </p> <p>C. Maclaurin. A Scottish mathematician gained his master degree at age 17, and his major mathematics' work arise from his special knowledge in Newton's ideas and the formulation of Newton's methods.</p> <p>However, C. Maclaurin also contributed to the astronomy science and helped to improve maps and invented some mechanical devices .</p> <p>My mathematics python's programs is a set of Maclaurin's series to compute some of the most important functions in calculus.</p> <p>Though, the computation of an infinite sum which give the value of a function in terms of the derivatives evaluated at a special case where x0 = 0,in contrast with Taylor series. </p> <p>The maclaurin's series approximation for ln(1+x) is used to approximate ln(x) by detucting the maclaurin's series for ln(1-x). ln(1+x) - ln(1-x) = ln(1+x/1-x)and by letting y = (1+x/1-x), y could take any positive value.</p> <p>y = 1+x/1-x, therefore x = y-1/y+1 </p> <p>-1 &lt; x &lt; 1 </p> DVM_Versus_CAPM (Python) 2011-01-26T14:26:06-08:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/576708-dvm_versus_capm/ <p style="color: grey"> Python recipe 576708 by <a href="/recipes/users/4155345/">Fouad Teniou</a> (<a href="/recipes/tags/corporate_finance/">corporate_finance</a>, <a href="/recipes/tags/financial_management/">financial_management</a>). Revision 5. </p> <p>Cost of equity could be found using my program DVM_Versus_CAPM by either methods, the DVM ( Dividend Valuation Model ) or the CAPM ( Capital asset pricing model ). However, value of the share (Company value) could also be found using my program, if the cost of equity Ke is known, whether assuming a constant dividend where Po = D/Ke or a constant growth g where Po = Do(1+g)/Ke-g. Though, the growth rate g is estimated in two different ways, by using the extrapolating growth formula, based on the past dividend history or by applying the Gordon’s growth model (g = r x b). Projects undertaken by firms will have different risk profiles, and so is the company return required, since it reflect this risk, thus, the DVM model assumptions conflict, and yet the DVM high sensitivity to these assumptions. Nevertheless, using the CAPM (Ke = Rf + Beta(Rm - Rf), the investors will require different rates of return for different projects depending of the risk of each project. Rf is the risk free rate, ( Rm - Rf) is the average risk premium, and Beta is the systematic risk of investment. Beta of the share could be measured or obtained from the commercial information suppliers such as Datastream, and the more volatile the business the higher is Beta. My program DVM_Versus_CAPM will be of a value to ACCA’s students and also to students of Corporate Finance.</p> Maclaurin's_series_cos(2x) (Python) 2010-08-03T12:23:33-07:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/577344-maclaurins_series_cos2x/ <p style="color: grey"> Python recipe 577344 by <a href="/recipes/users/4155345/">Fouad Teniou</a> (<a href="/recipes/tags/mathematics/">mathematics</a>). Revision 2. </p> <p>C. Maclaurin. A Scottish mathematician gained his master degree at age 17, and his major mathematics' work arise from his special knowledge in Newton's ideas and the formulation of Newton's methods.</p> <p>However, C. Maclaurin also contributed to the astronomy science and helped to improve maps and invented some mechanical devices .</p> <p>My mathematics python's programs is a set of Maclaurin's series to compute some of the most important functions in calculus.</p> <p>Though, the computation of an infinite sum which give the value of a function in terms of the derivatives evaluated at a special case where x0 = 0,in contrast with Taylor series. </p> <p>There are several ways of finding Maclaurin’s series, and I used the multiplication and the division to develop my own maclaurin’s series for cos(2x) and cos²(x).</p> <p>Cos(2x) = 2cos²(x) - 1 and cos²(x) = (cos(2x)+1)/2</p> <p>However, integration and differentiation could also be used to find Maclaurin’s series. </p> Maclaurin's_series_ln(1+x) (Python) 2010-07-07T12:28:36-07:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/577290-maclaurins_series_ln1x/ <p style="color: grey"> Python recipe 577290 by <a href="/recipes/users/4155345/">Fouad Teniou</a> . </p> <p>C. Maclaurin. A Scottish mathematician gained his master degree at age 17, and his major mathematics' work arise from his special knowledge in Newton's ideas and the formulation of Newton's methods.</p> <p>However, C. Maclaurin also contributed to the astronomy science and helped to improve maps and invented some mechanical devices.</p> <p>My mathematics python's programs is a set of Maclaurin's series to compute some of the most important functions in calculus.</p> <p>Though, the computation of an infinite sum which give the value of a function in terms of the derivatives evaluated at a special case where x0 = 0,in contrast with Taylor series. </p> <p>The Maclaurin's series for ln(1+x) could be used to approximate the natural logarithm ln(x).</p> Maclaurin's_series_cos (Python) 2010-07-07T11:56:52-07:00Fouad Teniouhttp://code.activestate.com/recipes/users/4155345/http://code.activestate.com/recipes/577285-maclaurins_series_cos/ <p style="color: grey"> Python recipe 577285 by <a href="/recipes/users/4155345/">Fouad Teniou</a> (<a href="/recipes/tags/mathematics/">mathematics</a>). Revision 2. </p> <p>Maclaurin. A Scottish mathematician gained his master degree at age 17, and his major mathematics' work arise from his special knowledge in Newton's ideas and the formulation of Newton's methods.</p> <p>However, C. Maclaurin also contributed to the astronomy science and helped to improve maps and invented some mechanical devices .</p> <p>My mathematics python's programs is a set of Maclaurin's series to compute some of the most important functions in calculus.</p> <p>Though, the computation of an infinite sum which give the value of a function in terms of the derivatives evaluated at a special case where x0 = 0,in contrast with Taylor series. </p> <p>It is assumed that the angle is expressed in radian while using the Maclaurin's series to approximate the trigonometric functions sine and cosine, thus, converting the angle into degrees in my program could be useful for students who prefer using degrees.</p>