Using Python as a math shell

Python can be used as a MATLAB-like shell for math and stuff.

The following components are needed (in order of decreasing importance):

  • IPython
  • NumPy
  • Matplotlib
  • SciPy
  • SymPy

IPython makes the Python shell behave more like tools such as MATLAB.

We need to set up an IPython profile that automatically imports the aforementioned math-related libraries.

First, create a new IPython profile:

$ ipython profile create math

Then, add a startup script to this profile. Create a Python file in the startup directory, which is found at ~/.ipython/profile_math/startup In this file, import all the necessary math libraries. Here's an example:

0-init.py
import numpy as np
import scipy
import sympy
import matplotlib.pyplot as plt

To run this profile, run the following command:

ipython --profile=math

In order to not have to run that command every time, you can create a bash alias. Add this line to ~/.bashrc:

alias matpy-shell="ipython --profile=math"
  • kb/python_math_shell.txt
  • Last modified: 2024-04-30 04:03
  • by 127.0.0.1