1. HOME

  2. PDF (letter size)

  3. PDF (legal size)

my sympy and python cheat sheet

Nasser M. Abbasi

June 13, 2021   Compiled on June 13, 2021 at 12:22 Noon

Contents

 1 How to solve a first order ODE?
 2 How to solve a first oder ODE with initial condition?
 3 How to solve a second order ODE?
 4 How to solve and ODE and convert the result to latex string?
 5 How to solve a PDE in sympy?
 6 How to check if something is derivative?
 7 How to find function name and its arguments in a proc?

1 How to solve a first order ODE?

Solve \( y'(x)=1+2 x\) for \(y(x)\)


2 How to solve a first oder ODE with initial condition?

Solve \( y'(x)=1+2 x\) for \(y(x)\) with \(y(0)=3\)


3 How to solve a second order ODE?

Solve \( 9 y{\relax (x )} + \frac {d^{2}}{d x^{2}} y{\relax (x )} = 0\)


gives

\[ y{\relax (x )} = C_{1} \sin {\left (3 x \right )} + C_{2} \cos {\left (3 x \right )} \]

4 How to solve and ODE and convert the result to latex string?

Solve \( y'(x)=1+2 x\) for \(y(x)\) with \(y(0)=3\)


\[ y{\relax (x )} = x^{2} + x + 3 \]

5 How to solve a PDE in sympy?

PDE solving is still limited in sympy. Here is how to solve first order pde

Solve \( u_t(x,t)=u_x(x,t)\)


\[ u{\left (x,t \right )} = F{\left (t + x \right )} \]

6 How to check if something is derivative?


This also works, which seems to be the more prefered way


7 How to find function name and its arguments in a proc?

Suppose one passes \(y(x)\) to a function, and the function wants to find the name of this function and its argument. Here is an example


This prints