Python
Use Roblib.py





  1. Basic
  2. Draw
  3. Sympy
This Python help is for KalMooc and RobMOOC.







Basic

Greak symbols

See Unicode https://en.wikipedia.org/wiki/List_of_Unicode_characters
For instance to get theta : shift + ctr + U03B8
U+03B1 alpha; U+03B2 beta; U+03B3; Gamma 0419; U+03B4 Delta; U+03B5 Epsilon; U+03B6 Zeta; U+03B7 Eta; U+03B8 Theta; U+03BB Lambda; U+03BC Mu; U+03BD Nu; U+03BE Xi; U+03C0 Pi; U+03C1 Rho; U+03C3 Sigma; U+03C4 Tau; U+03C6 Phi; U+03C8 Psi; U+03C9 Omega U+0393 Gamma

Array-matrices

A = array([[0, 0, 0],[0,0,-1],[0,1,0]])
M = expm(A) # exponential of a matrix
x=array([[1], [2]]) #vector
y= M@x #multiplication in Python 3

Unpack

x = array([[0],[1],[2],[3]])
xr,yr,thetar,vr=x.flatten()

def f(x,y): return x+y
f(*[4,5]) # returns 9

Pole placement

A = array([[0,0,1,0],[0,0,0,1],[0,2,0,0],[0,3,0,0]])
B = array([[0,0,4,5]]).T
poles = [-2,-2.1,-2.2,-2.3]
K = place_poles(A,B,poles).gain_matrix

Random vector

x=array([[1], [2]])
G=array([[1, 0], [0, 1]]) #covariance matrix
y=mvnrnd2(x,G) #MultiVariable Normal RaNDom





Draw

ax=init_figure(-30,30,-30,30)
x = array([[-30],[0],[1],[1]])
draw_tank(x,'red')





Sympy

from sympy import Symbol, symbols, cos, pprint
from sympy.printing.latex import print_latex
from sympy.core.function import UndefinedFunction, Function
from sympy.plotting import plot3d
y = Symbol("y")
x = Symbol("x")
f = Function("f")
expr = f(x,y).diff(x,y)
print_latex(expr)
print_latex((1/cos(x)).series(x, 0, 10))
x,y, alpha = symbols('x y alpha')
plot3d(cos(x*3)*cos(y*5)-y, (x, -1, 1), (y, -1, 1))
from sympy.interactive.printing import init_printing
init_printing(use_unicode=False, wrap_line=False)
from sympy.matrices import Matrix, eye, zeros, ones, diag, GramSchmidt
M = Matrix([[1,0,0], [0,0,0]]);
A=Matrix([M, (1, 0, -1)])
B=Matrix([[1, 2, 3]])
C=Matrix([1, 2, 3])
pprint(A)
A1=A.evalf()
A2=A1.tolist()

from sympy import pi
from sympy.matrices import rot_axis3
theta = pi/3
R=rot_axis3(theta)
pprint(R)
R1=R.evalf()
R2=R1*R1*R1
R3=R2.tolist()
print(R2)
print(R3)

??