Quadratic and Reciprocal Equations

Good evening and welcome to this weeks blog posting. For this evening’s post we’re going to discuss quadratic and reciprocal equations a bit, and how we can apply them within Python for data computation and analysis.

Starting with quadratic equations. What makes an equation quadratic? Simply put, an equation becomes quadratic when one of it’s variables are superseded with an exponent of 2. This converts the equation into a quadratic one, in which we are then able to apply the quadratic formula too.

Quadratic formula:

As we can see in the above formula we’re able to input our coefficients into the quadratic formula to obtain it’s answer.

Now that we know what makes an equation quadratic and what the quadratic formula is, let’s put this knowledge into Python code to solve the following:

Solve: x2-5.86 x+ 8.5408

We first start with utilizing the math module library in Python and input our variables:

From there we following the quadratic formula and obtain our answers. You’ll notice a couple of different math functions utilized from the math library; .pow which obtains the power of an input int or decimal based on the exponent passed in, as well as the .sqrt function, which obtains the square root of an int or decimal passed into it. Additionally, we’re utilizing string interpolation (f’…’) in place of wrapping our int’s and decimals in a str() function for ease of printing to the console:

Moving onto Reciprocal equations. This one is extremely simple, basically when talking about reciprocal equations, all we have to do it flip it upside down! For example, if we have 1/2 the reciprocal is 2/1. Furthermore, we’re able to take reciprocal equations and obtain their decimals. For example, if I have 1/2 it’s reciprocal is 2/1, and it’s decimal equivalent is 0.5!

Now let’s put this input Python for another look. We start by creating a list of tuples to show the original fractional value as well as their decimal values upon computation in Python. Finally, we wrap these within a for loop and iterate over the list printing each value in it’s respected decimal form to the console.


Well, that about wraps it up for this weeks blog posting on quadratic and reciprocal equations. You can find the related code to these examples of quadratic and reciprocal equations on my GitHub page. As a little bonus I’ve also included a few Python programs playing with files and additional functions within the math library.

GitHub page: https://github.com/joshsnyder/python-data-science/tree/develop/module4

Leave a comment

Design a site like this with WordPress.com
Get started