H's


In [67]:
from sympy.abc import*
from sympy import *
from tools import*
from nlcontrol import*

s = Symbol('s')
c = Symbol('c')

a1 = Symbol('a1')
a2 = Symbol('a2')
a3 = Symbol('a3')
a4 = Symbol('a4')

In [14]:
solve(a1 - 3,a1)


Out[14]:
$$\left [ 3\right ]$$

In [19]:
M = Matrix([a1,a2,a3]).T
M

g = Matrix([[c, 0],[s,0], [0,1]])
m = M*g
solve(m[0],a1)


Out[19]:
$$\left [ - \frac{a_{2} s}{c}\right ]$$

In [51]:
from sympy import Matrix, solve_linear_system

x, y, z = symbols('x, y, z')
A = Matrix(( (c, s, 0, 0), (0, 0, 1, 0) ))
solve_linear_system(A, x, y, z)


---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-51-b549b9f19b98> in <module>()
      3 x, y, z = symbols('x, y, z')
      4 A = Matrix(( (c, s, 0, 0), (0, 0, 1, 0) ))
----> 5 solve_linear_system(A, [x,y,z])

/Users/kike/anaconda/lib/python2.7/site-packages/sympy/solvers/solvers.pyc in solve_linear_system(system, *symbols, **flags)
   2007             # we want to change the order of colums so
   2008             # the order of variables must also change
-> 2009             syms[i], syms[k] = syms[k], syms[i]
   2010             matrix.col_swap(i, k)
   2011 

IndexError: list index out of range

In [57]:
solve([Eq(a1*c + a2*s, 0), Eq(a3, 0)], [a1,a2,a3])


Out[57]:
$$\left \{ a_{1} : - \frac{a_{2} s}{c}, \quad a_{3} : 0\right \}$$

In [53]:
x1, x2, x3, x4 = symbols('x_1, x_2, x_3, x_4')
u1, u2, u3, u4 = symbols('u_1, u_2, u_3, u_4')

#M = Matrix([cos(x3), 0],[sin(x3), 0], [tan(x4), 0], [0, 1] )

In [81]:
solve([Eq(a1*cos(x3) - a3*tan(x4), 0)], [a1])


Out[81]:
$$\left \{ a_{1} : \frac{a_{3} \tan{\left (x_{4} \right )}}{\cos{\left (x_{3} \right )}}\right \}$$

In [73]:
A = Matrix(( (c, s, 0, 0), (0, 0, 1, 0) ))
solve_linear_system(A, x1, x2, x3)


M = Matrix([[cos(x3), 0],[sin(x3), 0], [tan(x4), 0], [0, 1]] )
M.nullspace()


Out[73]:
$$\left [ \right ]$$

In [84]:
f = 1 -x2 - (x3**2)/(1+x1)**2
f


Out[84]:
$$- x_{2} - \frac{x_{3}^{2}}{\left(x_{1} + 1\right)^{2}} + 1$$

In [85]:
simplify(f)


Out[85]:
$$- x_{2} - \frac{x_{3}^{2}}{\left(x_{1} + 1\right)^{2}} + 1$$

In [86]:



Out[86]:
$$- \frac{1}{\left(x_{1} + 1\right)^{2}} \left(x_{1}^{2} x_{2} - x_{1}^{2} + 2 x_{1} x_{2} - 2 x_{1} + x_{2} + x_{3}^{2} - 1\right)$$

In [87]:
expand(f)


Out[87]:
$$- x_{2} - \frac{x_{3}^{2}}{x_{1}^{2} + 2 x_{1} + 1} + 1$$

In [88]:
expand((x1+1)**2)


Out[88]:
$$x_{1}^{2} + 2 x_{1} + 1$$

In [90]:
f2 = (2+x1)/(1+x1)*(-x3 + (x2*x3)/(1+x1**2) +u1)
f2


Out[90]:
$$\frac{1}{x_{1} + 1} \left(x_{1} + 2\right) \left(u_{1} + \frac{x_{2} x_{3}}{x_{1}^{2} + 1} - x_{3}\right)$$

In [91]:
simplify(f2)


Out[91]:
$$\frac{\left(x_{1} + 2\right) \left(x_{2} x_{3} + \left(u_{1} - x_{3}\right) \left(x_{1}^{2} + 1\right)\right)}{\left(x_{1} + 1\right) \left(x_{1}^{2} + 1\right)}$$

In [92]:
expand(f2)


Out[92]:
$$\frac{u_{1} x_{1}}{x_{1} + 1} + \frac{2 u_{1}}{x_{1} + 1} + \frac{x_{1} x_{2} x_{3}}{x_{1}^{3} + x_{1}^{2} + x_{1} + 1} - \frac{x_{1} x_{3}}{x_{1} + 1} + \frac{2 x_{2} x_{3}}{x_{1}^{3} + x_{1}^{2} + x_{1} + 1} - \frac{2 x_{3}}{x_{1} + 1}$$

In [93]:
solve(a1*(2 + x1) -1 -x1, a1)


Out[93]:
$$\left [ \frac{x_{1} + 1}{x_{1} + 2}\right ]$$

In [ ]: