Solving Quadratics

So to start off a new area of discovery I have decided to start to learn Python.

To start off this undertaking I downloaded Python 2.7.3 from python/download and started to play around with IDLE, python’s Integrated DeveLopment Environment (IDE).

As a project to work on to learn this new language I decided to make a simple console application that try’s to calculates the value of X for a given quadratic.  To do this it will use the quadratic formula


So to do this I first need the values of a, b, and c as per the formula.    Image

for example a = 1, b = -9, and c = 20.

The first step logical step was to cut the equation into 3 chunks:

  1. The Discriminant (Δ); b^2 – 4ac
    1. sqrB = pow(b, 2)
      AC = 4*a*c
      Delta = math.sqrt(sqrB – AC)
    2. the “pow(x,y)” function returns the first term to the power of the second, i.e. b^2
    3. the math.sqrt is a function of the math module which square roots the contents of the brackets, or to use the technical name, parentheses.
  2. The Numerator; -b +- √Δ
    1. NumeratorPlus = -b + Delta
      NumeratorMinus = -b – Delta
  3. The Denominator; 2a
    1. Denominator = 2*a

Then with the necessary components the values of X can then be calculated by:

XPlus = NumeratorPlus / Denominator
XMinus = NumeratorMinus / Denominator

and then be outputed on the screen using the print command:

print (“Your answer is, X = “), XPlus, (“Or X = “), XMinus

notice the comma’s after each component which are needed.

And so the final step was to allow the user to enter in values:

print (“Please separate the quadratic equation into aX^2 + bX + C = 0”)
a=input(“Please Enter the Value of a : “)
b=input(“Please Enter the Value of b : “)
c=input(“Please Enter the Value of c : “)

The “input” function is important as it prints the given prompt to the output and then reads in the data entered by the user and assigns it to the variable.

This is different to the “raw_input” function which is not syntax sensitive.

And so the final code looks like:

import math
from time import sleep

print (“Please seperate the quadratic equation into aX^2 + bX + C = 0”)
a=input(“Please Enter the Value of a : “)
b=input(“Please Enter the Value of b : “)
c=input(“Please Enter the Value of c : “)

sqrB = pow(b, 2)
AC = 4*a*c
Delta = math.sqrt(sqrB – AC)
NumeratorPlus = -b + Delta
NumeratorMinus = -b – Delta

Denominator = 2*a
XPlus = NumeratorPlus / Denominator
XMinus = NumeratorMinus / Denominator

print (“Your answer is, X = “), XPlus, (“Or X = “), XMinus




Adjustable Voltage Regulator Problems

So yesterday I had no lectures, so instead of spending my time working on assignments that I don’t have, I decided to go into the engineering lab and prototype the MIC2941 adjustable voltage regulator circuit.
The datasheet for the 2941 contains a example circuit with maths to go with it. This circuit should be capable of outputting between 1.2v and 26v, perfect for what I want to do.
Datasheet example circuit

So in the lab I found the components I needed, and set to work.


In order to calculate the values on R1 and R2 I used the equation provided, Vout=Vref(1+(R1/R2)) re-arranging so that, R1/R2=(Vout/Vref)-1. With this I then had a ratio that I could scale to any values I wanted.

Due to the output voltage being limited to between 1.2v and Vin – 1v I chose to aim for a output of 15v initially, because the power supply unit’s (PSU’s) my university have on workbenches only go up to 20v.
So with that value in mind I calculated R1/R2 = 11.195 to 3dp, therefore I selected a pre-set 2kΩ for R2 and a variable 22kΩ for R1. In theory I should then be getting approximate output voltages of:

14.76v at full rotation
7.995v at centre point
1.5375v at low rotation

ImageAs seen in the video below, with the reference voltage at 1.2 – 1.3v (poor resolution on the power supply’s behalf) and 19.9v on the input, the output voltage seems to fluctuate between 6.6v and then back up to 15.1v and back down.

My plan in the next couple of days is to hock it up to the oscilloscope and investigate the input current, which was limited to 0.5A by the PSU.