Jupyter Notebooks for Engineering Classes
I have one more “traditional” engineering class in my time at Ohio State which is ECE 2020: Introduction to Analogue Circuits. I took digital circuits a couple semesters ago, and that class was basically boolean expressions but with little lines connecting to boxes. This class is more resistors/inductors/capacitors/I never took a class on complex numbers oh God. So, there’s a little more algebra involved, and it becomes especially unwieldy when we start using complex numbers for the phasor domain.
But I knew there were symbolic solvers out there (Wolfram Alpha, for one), and I was feeling more comfortable with Jupyter notebooks, so I decided to use Sympy to do all of my homework for ECE 2020 in a notebook.
Here’s how I set it up:
- Set up a virtual environment (preferably in Python3)
- Install iPython, Jupyter and Sympy
- Create a notebook
- Use Sympy and
cmathto solve the hard problems
Setting up a Virtual Environment
Assuming you have
python3 installed on your machine (if you don’t, look here (or anywhere on the internet) for instructions):
We need Jupyter and Sympy (Jupyter will install iPython as a dependency):
Then we need to create a kernel for Jupyter that corresponds to this virtual environment:
Create a notebook
This will launch the web interface. From here, I navigate to my class folder and create a new notebook with my school kernel
I always import Sympy and
cmath, and set up j to mean
And here’s an example of how I would do an ECE problem:
First, set up my constants.
Next, I set up values that depend on constants.
Finally, I use Sympy to solve for variables in multiple equations.
Note: You need to set up
sym.Symbol()for Sympy to solve for it.
Note 2: The results from Sympy are not type
complex; they must be cast before being used with other
complexnumbers, or you end up with weird results.
And this is how it all might look within a Jupyter notebook:
This is how I avoid doing any hard math in my ECE class.
Please email me if you have any comments or want to discuss further.
Sam Stevens, 2020