```python
import sympy
from sympy import *
import matplotlib.pyplot as plt
import scipy.integrate
import numpy
print(sympy.__version__)

print(scipy.__version__)
print(numpy.__version__)
```

    1.7.1
    1.5.2
    1.19.2

```python
n, k = symbols("n, k", integer=True, positive=True)

Uu, Psi_theta_theta = symbols('Uu, Psi_theta_theta', real=True, positive=True)

h, hT, Rk = symbols('h, hT, Rk', real=True, positive=True)

#s,t=var('s, t')
#f = t^5*exp(t)*sin(t)
cr,ps,mR,omega,dr,Ir,Texte,msT,d,cUo,Vo,Omega= symbols('cr, ps, mR, omega, dr, Ir, Texte, msT, d, cUo, Vo, Omega',
                                                       real=True, positive=True)

Omega = omega

theta, tau = symbols('theta, tau')

#qk = symbols('qk', cls=Function)
qk = Function('qk')(tau)
pk = Function('pk')(tau)

#f = (x^2 + sin(a*w)).function(a,x,w); f

u = (cos(n* theta) * qk + pk *sin(n *theta))* Uu
#u = ((cos(n* theta) * qk + pk *sin(n *theta))* Uu).function(theta)
ak = Function('ak')(tau)

zr = u .subs(theta, ak)
#zr = u(ak)
du = diff(u,tau)    # D[u, τ];

dzr = du.subs(theta, ak)   # /. {θ -> αk[τ]};
#dzr = du(ak,qk,pk)
ddzr = diff(dzr,tau)   #D[dzr, τ]

v = - (h/2 + hT)* Psi_theta_theta * (cos(n*theta)*pk + sin(n*theta)*qk)
dv = diff(v, tau)   ##dv = D[%, τ];

#aft= dv.coefficient(diff(qk(tau),tau))

#f.coefficient(sin(y))
```

```python
type(d)
```

    sympy.core.symbol.Symbol

```python
dv.coeff(Derivative(qk,tau))
```

$\displaystyle 0$

```python
#qk = symbols('qk', cls=Function)
qk = Function('qk')(tau)
pk = Function('pk')(tau)

#f = (x^2 + sin(a*w)).function(a,x,w); f

u = (cos(n* theta) * qk + pk *sin(n *theta))* Uu
#u = ((cos(n* theta) * qk + pk *sin(n *theta))* Uu).function(theta)
ak = Function('ak')(tau)

zr = u .subs(theta, ak)
#zr = u(ak)
du = diff(u,tau)    # D[u, τ];

dzr = du.subs(theta, ak)   # /. {θ -> αk[τ]};
#dzr = du(ak,qk,pk)
ddzr = diff(dzr,tau)   #D[dzr, τ]

v = - (h/2 + hT)* Psi_theta_theta * (cos(n*theta)*pk + sin(n*theta)*qk)
dv = diff(v, tau)   ##dv = D[%, τ];
print(dv)

dvqk = diff(dv, Derivative(Function('qk')(tau), tau)).subs(theta, ak)
#dvqk = diff(dv, Derivative(Function('qk')(Symbol('tau')), Symbol('tau'))).subs(theta, ak)  #D[dv, qk '[τ]] /. {θ -> αk[τ]}
print(dvqk)
dvpk = diff(dv, Derivative(Function('pk')(tau), tau)).subs(theta, ak)   #D[dv, pk '[τ]] /. {θ -> αk[τ]}
print(dvpk)
duqk = diff(du, Derivative(Function('qk')(tau), tau)).subs(theta, ak)   #D[du, qk '[τ]] /. {θ -> αk[τ]}
print(duqk)
dupk = diff(du, Derivative(Function('pk')(tau), tau)).subs(theta, ak)   ###D[du, pk '[τ]] /. {θ -> αk[τ]}
print(dupk)
```

    Psi_theta_theta*(-h/2 - hT)*(sin(n*theta)*Derivative(qk(tau), tau) + cos(n*theta)*Derivative(pk(tau), tau))
    Psi_theta_theta*(-h/2 - hT)*sin(n*ak(tau))
    Psi_theta_theta*(-h/2 - hT)*cos(n*ak(tau))
    Uu*cos(n*ak(tau))
    Uu*sin(n*ak(tau))

```python
dphir = (dv/Rk).subs(theta, ak)

ddv = diff(dv, tau) ###D[dv, τ];

ddphir = diff(dphir, tau)
```

```python
zr = zr.subs({sin(n*Function('ak')(tau)): Function('pk')(tau)/sqrt(Function('pk')(tau)**2 + Function('qk')(tau)**2),cos(n*Function('ak')(tau)): Function('qk')(tau)/sqrt(Function('pk')(tau)**2 + Function('qk')(tau)**2)})
dzr=dzr.subs({sin(n*Function('ak')(tau)): Function('pk')(tau)/sqrt(Function('pk')(tau)**2 + Function('qk')(tau)**2),cos(n*Function('ak')(tau)): Function('qk')(tau)/sqrt(Function('pk')(tau)**2 + Function('qk')(tau)**2)})
ddzr=ddzr.subs({sin(n*Function('ak')(tau)): Function('pk')(tau)/sqrt(Function('pk')(tau)**2 + Function('qk')(tau)**2),cos(n*Function('ak')(tau)): Function('qk')(tau)/sqrt(Function('pk')(tau)**2 + Function('qk')(tau)**2)})
dvqk=dvqk.subs({sin(n*Function('ak')(tau)): Function('pk')(tau)/sqrt(Function('pk')(tau)**2 + Function('qk')(tau)**2),cos(n*Function('ak')(tau)): Function('qk')(tau)/sqrt(Function('pk')(tau)**2 + Function('qk')(tau)**2)})
dvpk=dvpk.subs({sin(n*Function('ak')(tau)): Function('pk')(tau)/sqrt(Function('pk')(tau)**2 + Function('qk')(tau)**2),cos(n*Function('ak')(tau)): Function('qk')(tau)/sqrt(Function('pk')(tau)**2 + Function('qk')(tau)**2)})
duqk=duqk.subs({sin(n*Function('ak')(tau)): Function('pk')(tau)/sqrt(Function('pk')(tau)**2 + Function('qk')(tau)**2),cos(n*Function('ak')(tau)): Function('qk')(tau)/sqrt(Function('pk')(tau)**2 + Function('qk')(tau)**2)})
dupk=dupk.subs({sin(n*Function('ak')(tau)): Function('pk')(tau)/sqrt(Function('pk')(tau)**2 + Function('qk')(tau)**2),cos(n*Function('ak')(tau)): Function('qk')(tau)/sqrt(Function('pk')(tau)**2 + Function('qk')(tau)**2)})
dphir=dphir.subs({sin(n*Function('ak')(tau)): Function('pk')(tau)/sqrt(Function('pk')(tau)**2 + Function('qk')(tau)**2),cos(n*Function('ak')(tau)): Function('qk')(tau)/sqrt(Function('pk')(tau)**2 + Function('qk')(tau)**2)})
ddphir=ddphir.subs({sin(n*Function('ak')(tau)): Function('pk')(tau)/sqrt(Function('pk')(tau)**2 + Function('qk')(tau)**2),cos(n*Function('ak')(tau)): Function('qk')(tau)/sqrt(Function('pk')(tau)**2 + Function('qk')(tau)**2)})
print(ddphir)
```

    Psi_theta_theta*(-h/2 - hT)*(-n*pk(tau)*Derivative(ak(tau), tau)*Derivative(pk(tau), tau)/sqrt(pk(tau)**2 + qk(tau)**2) + n*qk(tau)*Derivative(ak(tau), tau)*Derivative(qk(tau), tau)/sqrt(pk(tau)**2 + qk(tau)**2) + pk(tau)*Derivative(qk(tau), (tau, 2))/sqrt(pk(tau)**2 + qk(tau)**2) + qk(tau)*Derivative(pk(tau), (tau, 2))/sqrt(pk(tau)**2 + qk(tau)**2))/Rk

```python
print(zr)
zr=zr.factor()
dzr=dzr.factor()
ddzr=ddzr.factor()
dvqk=dvqk.factor()
dvpk=dvpk.factor()
duqk=duqk.factor()
dupk=dupk.factor()
dphir=dphir.factor()
print(ddphir)
ddphir=ddphir.factor()
print(ddphir)
```

    Uu*(pk(tau)**2/sqrt(pk(tau)**2 + qk(tau)**2) + qk(tau)**2/sqrt(pk(tau)**2 + qk(tau)**2))
    Psi_theta_theta*(-h/2 - hT)*(-n*pk(tau)*Derivative(ak(tau), tau)*Derivative(pk(tau), tau)/sqrt(pk(tau)**2 + qk(tau)**2) + n*qk(tau)*Derivative(ak(tau), tau)*Derivative(qk(tau), tau)/sqrt(pk(tau)**2 + qk(tau)**2) + pk(tau)*Derivative(qk(tau), (tau, 2))/sqrt(pk(tau)**2 + qk(tau)**2) + qk(tau)*Derivative(pk(tau), (tau, 2))/sqrt(pk(tau)**2 + qk(tau)**2))/Rk
    Psi_theta_theta*(h + 2*hT)*(n*pk(tau)*Derivative(ak(tau), tau)*Derivative(pk(tau), tau) - n*qk(tau)*Derivative(ak(tau), tau)*Derivative(qk(tau), tau) - pk(tau)*Derivative(qk(tau), (tau, 2)) - qk(tau)*Derivative(pk(tau), (tau, 2)))/(2*Rk*sqrt(pk(tau)**2 + qk(tau)**2))

```python
ddzr=ddzr.subs(Derivative(Function('ak')(tau),tau), (Function('qk')(tau)*Derivative(Function('pk')(tau),tau)-Function('pk')(tau)*Derivative(Function('qk')(tau),tau))/(n*(Function('pk')(tau)**2+Function('qk')(tau)**2  )) )

ddphir=ddphir.subs(Derivative(Function('ak')(tau),tau), (Function('qk')(tau)*Derivative(Function('pk')(tau),tau)-Function('pk')(tau)*Derivative(Function('qk')(tau),tau))/(n*(Function('pk')(tau)**2+Function('qk')(tau)**2  )) )
```

```python
print(ddphir)
```

    Psi_theta_theta*(h + 2*hT)*((-pk(tau)*Derivative(qk(tau), tau) + qk(tau)*Derivative(pk(tau), tau))*pk(tau)*Derivative(pk(tau), tau)/(pk(tau)**2 + qk(tau)**2) - (-pk(tau)*Derivative(qk(tau), tau) + qk(tau)*Derivative(pk(tau), tau))*qk(tau)*Derivative(qk(tau), tau)/(pk(tau)**2 + qk(tau)**2) - pk(tau)*Derivative(qk(tau), (tau, 2)) - qk(tau)*Derivative(pk(tau), (tau, 2)))/(2*Rk*sqrt(pk(tau)**2 + qk(tau)**2))

```python
ddphir.factor()
```

$\displaystyle - \frac{\Psi_{\theta \theta} \left(h + 2 hT\right) \left(\operatorname{pk}^{3}{\left(\tau \right)} \frac{d^{2}}{d \tau^{2}} \operatorname{qk}{\left(\tau \right)} + \operatorname{pk}^{2}{\left(\tau \right)} \operatorname{qk}{\left(\tau \right)} \frac{d^{2}}{d \tau^{2}} \operatorname{pk}{\left(\tau \right)} + \operatorname{pk}^{2}{\left(\tau \right)} \frac{d}{d \tau} \operatorname{pk}{\left(\tau \right)} \frac{d}{d \tau} \operatorname{qk}{\left(\tau \right)} + \operatorname{pk}{\left(\tau \right)} \operatorname{qk}^{2}{\left(\tau \right)} \frac{d^{2}}{d \tau^{2}} \operatorname{qk}{\left(\tau \right)} - \operatorname{pk}{\left(\tau \right)} \operatorname{qk}{\left(\tau \right)} \left(\frac{d}{d \tau} \operatorname{pk}{\left(\tau \right)}\right)^{2} - \operatorname{pk}{\left(\tau \right)} \operatorname{qk}{\left(\tau \right)} \left(\frac{d}{d \tau} \operatorname{qk}{\left(\tau \right)}\right)^{2} + \operatorname{qk}^{3}{\left(\tau \right)} \frac{d^{2}}{d \tau^{2}} \operatorname{pk}{\left(\tau \right)} + \operatorname{qk}^{2}{\left(\tau \right)} \frac{d}{d \tau} \operatorname{pk}{\left(\tau \right)} \frac{d}{d \tau} \operatorname{qk}{\left(\tau \right)}\right)}{2 Rk \left(\operatorname{pk}^{2}{\left(\tau \right)} + \operatorname{qk}^{2}{\left(\tau \right)}\right)^{\frac{3}{2}}}$

```python
dphir
```

$\displaystyle - \frac{\Psi_{\theta \theta} \left(h + 2 hT\right) \left(\operatorname{pk}{\left(\tau \right)} \frac{d}{d \tau} \operatorname{qk}{\left(\tau \right)} + \operatorname{qk}{\left(\tau \right)} \frac{d}{d \tau} \operatorname{pk}{\left(\tau \right)}\right)}{2 Rk \sqrt{\operatorname{pk}^{2}{\left(\tau \right)} + \operatorname{qk}^{2}{\left(\tau \right)}}}$

```python
Fv = cr*ps
#FN = (1/n)*(mR*omega**2*ddzr + omega*dr*dzr + cr*zr + Fv)
FN = (1/n)*(mR*omega**2*ddzr + cr*zr + Fv)       #dr = 0
#FC = (1/n)*(Ir*omega**2*ddphir + drot*omega*dphir  + Texte)/Rk
FC = (1/n)*(Ir*omega**2*ddphir + Texte)/Rk
eq1 = -diff(pk,tau,2)-(1/(msT*omega))*d*diff(pk,tau)-pk-(1/(msT*omega**2))*cUo*Vo*sin(Omega*tau/omega)+(n/(msT*omega**2))*(-FN*dupk-FC*dvpk)
eq2 = -diff(qk,tau,2)-(1/(msT*omega))*d*diff(qk,tau)-qk-(1/(msT*omega**2))*cUo*Vo*cos(Omega*tau/omega)+(n/(msT*omega**2))*(-FN*duqk-FC*dvqk)
```

```python
print(eq1)
#print(eq1.factor())
```

    -Vo*cUo*sin(tau)/(msT*omega**2) - d*Derivative(pk(tau), tau)/(msT*omega) - pk(tau) - Derivative(pk(tau), (tau, 2)) + n*(Psi_theta_theta*(h + 2*hT)*(Ir*Psi_theta_theta*omega**2*(h + 2*hT)*((-pk(tau)*Derivative(qk(tau), tau) + qk(tau)*Derivative(pk(tau), tau))*pk(tau)*Derivative(pk(tau), tau)/(pk(tau)**2 + qk(tau)**2) - (-pk(tau)*Derivative(qk(tau), tau) + qk(tau)*Derivative(pk(tau), tau))*qk(tau)*Derivative(qk(tau), tau)/(pk(tau)**2 + qk(tau)**2) - pk(tau)*Derivative(qk(tau), (tau, 2)) - qk(tau)*Derivative(pk(tau), (tau, 2)))/(2*Rk*sqrt(pk(tau)**2 + qk(tau)**2)) + Texte)*qk(tau)/(2*Rk*n*sqrt(pk(tau)**2 + qk(tau)**2)) - Uu*(Uu*cr*sqrt(pk(tau)**2 + qk(tau)**2) + Uu*mR*omega**2*(-(-pk(tau)*Derivative(qk(tau), tau) + qk(tau)*Derivative(pk(tau), tau))*pk(tau)*Derivative(qk(tau), tau)/(pk(tau)**2 + qk(tau)**2) + (-pk(tau)*Derivative(qk(tau), tau) + qk(tau)*Derivative(pk(tau), tau))*qk(tau)*Derivative(pk(tau), tau)/(pk(tau)**2 + qk(tau)**2) + pk(tau)*Derivative(pk(tau), (tau, 2)) + qk(tau)*Derivative(qk(tau), (tau, 2)))/sqrt(pk(tau)**2 + qk(tau)**2) + cr*ps)*pk(tau)/(n*sqrt(pk(tau)**2 + qk(tau)**2)))/(msT*omega**2)

```python
eq2
```

$\displaystyle - \frac{Vo cUo \cos{\left(\tau \right)}}{msT \omega^{2}} - \frac{d \frac{d}{d \tau} \operatorname{qk}{\left(\tau \right)}}{msT \omega} - \operatorname{qk}{\left(\tau \right)} - \frac{d^{2}}{d \tau^{2}} \operatorname{qk}{\left(\tau \right)} + \frac{n \left(\frac{\Psi_{\theta \theta} \left(h + 2 hT\right) \left(\frac{Ir \Psi_{\theta \theta} \omega^{2} \left(h + 2 hT\right) \left(\frac{\left(- \operatorname{pk}{\left(\tau \right)} \frac{d}{d \tau} \operatorname{qk}{\left(\tau \right)} + \operatorname{qk}{\left(\tau \right)} \frac{d}{d \tau} \operatorname{pk}{\left(\tau \right)}\right) \operatorname{pk}{\left(\tau \right)} \frac{d}{d \tau} \operatorname{pk}{\left(\tau \right)}}{\operatorname{pk}^{2}{\left(\tau \right)} + \operatorname{qk}^{2}{\left(\tau \right)}} - \frac{\left(- \operatorname{pk}{\left(\tau \right)} \frac{d}{d \tau} \operatorname{qk}{\left(\tau \right)} + \operatorname{qk}{\left(\tau \right)} \frac{d}{d \tau} \operatorname{pk}{\left(\tau \right)}\right) \operatorname{qk}{\left(\tau \right)} \frac{d}{d \tau} \operatorname{qk}{\left(\tau \right)}}{\operatorname{pk}^{2}{\left(\tau \right)} + \operatorname{qk}^{2}{\left(\tau \right)}} - \operatorname{pk}{\left(\tau \right)} \frac{d^{2}}{d \tau^{2}} \operatorname{qk}{\left(\tau \right)} - \operatorname{qk}{\left(\tau \right)} \frac{d^{2}}{d \tau^{2}} \operatorname{pk}{\left(\tau \right)}\right)}{2 Rk \sqrt{\operatorname{pk}^{2}{\left(\tau \right)} + \operatorname{qk}^{2}{\left(\tau \right)}}} + Texte\right) \operatorname{pk}{\left(\tau \right)}}{2 Rk n \sqrt{\operatorname{pk}^{2}{\left(\tau \right)} + \operatorname{qk}^{2}{\left(\tau \right)}}} - \frac{Uu \left(Uu cr \sqrt{\operatorname{pk}^{2}{\left(\tau \right)} + \operatorname{qk}^{2}{\left(\tau \right)}} + \frac{Uu mR \omega^{2} \left(- \frac{\left(- \operatorname{pk}{\left(\tau \right)} \frac{d}{d \tau} \operatorname{qk}{\left(\tau \right)} + \operatorname{qk}{\left(\tau \right)} \frac{d}{d \tau} \operatorname{pk}{\left(\tau \right)}\right) \operatorname{pk}{\left(\tau \right)} \frac{d}{d \tau} \operatorname{qk}{\left(\tau \right)}}{\operatorname{pk}^{2}{\left(\tau \right)} + \operatorname{qk}^{2}{\left(\tau \right)}} + \frac{\left(- \operatorname{pk}{\left(\tau \right)} \frac{d}{d \tau} \operatorname{qk}{\left(\tau \right)} + \operatorname{qk}{\left(\tau \right)} \frac{d}{d \tau} \operatorname{pk}{\left(\tau \right)}\right) \operatorname{qk}{\left(\tau \right)} \frac{d}{d \tau} \operatorname{pk}{\left(\tau \right)}}{\operatorname{pk}^{2}{\left(\tau \right)} + \operatorname{qk}^{2}{\left(\tau \right)}} + \operatorname{pk}{\left(\tau \right)} \frac{d^{2}}{d \tau^{2}} \operatorname{pk}{\left(\tau \right)} + \operatorname{qk}{\left(\tau \right)} \frac{d^{2}}{d \tau^{2}} \operatorname{qk}{\left(\tau \right)}\right)}{\sqrt{\operatorname{pk}^{2}{\left(\tau \right)} + \operatorname{qk}^{2}{\left(\tau \right)}}} + cr ps\right) \operatorname{qk}{\left(\tau \right)}}{n \sqrt{\operatorname{pk}^{2}{\left(\tau \right)} + \operatorname{qk}^{2}{\left(\tau \right)}}}\right)}{msT \omega^{2}}$

```python
DIFF2Q , DIFF2P= symbols('DIFF2Q, DIFF2P')
eq1sss = eq1.subs({Derivative(qk,tau,tau) : DIFF2Q, Derivative(pk,tau,tau):DIFF2P})
eq2sss = eq2.subs({Derivative(qk,tau,tau) : DIFF2Q, Derivative(pk,tau,tau):DIFF2P})
```

```python
solution= solve([eq1sss , eq2sss],[DIFF2Q , DIFF2P])
```

```python
help(solve)
```

    Help on function solve in module sympy.solvers.solvers:

    solve(f, *symbols, **flags)
        Algebraically solves equations and systems of equations.

        Explanation
        ===========

        Currently supported:
            - polynomial
            - transcendental
            - piecewise combinations of the above
            - systems of linear and polynomial equations
            - systems containing relational expressions

        Examples
        ========

        The output varies according to the input and can be seen by example:

            >>> from sympy import solve, Poly, Eq, Function, exp
            >>> from sympy.abc import x, y, z, a, b
            >>> f = Function('f')

        Boolean or univariate Relational:

            >>> solve(x < 3)
            (-oo < x) & (x < 3)

        To always get a list of solution mappings, use flag dict=True:

            >>> solve(x - 3, dict=True)
            [{x: 3}]
            >>> sol = solve([x - 3, y - 1], dict=True)
            >>> sol
            [{x: 3, y: 1}]
            >>> sol[0][x]
            3
            >>> sol[0][y]
            1

        To get a list of *symbols* and set of solution(s) use flag set=True:

            >>> solve([x**2 - 3, y - 1], set=True)
            ([x, y], {(-sqrt(3), 1), (sqrt(3), 1)})

        Single expression and single symbol that is in the expression:

            >>> solve(x - y, x)
            [y]
            >>> solve(x - 3, x)
            [3]
            >>> solve(Eq(x, 3), x)
            [3]
            >>> solve(Poly(x - 3), x)
            [3]
            >>> solve(x**2 - y**2, x, set=True)
            ([x], {(-y,), (y,)})
            >>> solve(x**4 - 1, x, set=True)
            ([x], {(-1,), (1,), (-I,), (I,)})

        Single expression with no symbol that is in the expression:

            >>> solve(3, x)
            []
            >>> solve(x - 3, y)
            []

        Single expression with no symbol given. In this case, all free *symbols*
        will be selected as potential *symbols* to solve for. If the equation is
        univariate then a list of solutions is returned; otherwise - as is the case
        when *symbols* are given as an iterable of length greater than 1 - a list of
        mappings will be returned:

            >>> solve(x - 3)
            [3]
            >>> solve(x**2 - y**2)
            [{x: -y}, {x: y}]
            >>> solve(z**2*x**2 - z**2*y**2)
            [{x: -y}, {x: y}, {z: 0}]
            >>> solve(z**2*x - z**2*y**2)
            [{x: y**2}, {z: 0}]

        When an object other than a Symbol is given as a symbol, it is
        isolated algebraically and an implicit solution may be obtained.
        This is mostly provided as a convenience to save you from replacing
        the object with a Symbol and solving for that Symbol. It will only
        work if the specified object can be replaced with a Symbol using the
        subs method:

        >>> solve(f(x) - x, f(x))
        [x]
        >>> solve(f(x).diff(x) - f(x) - x, f(x).diff(x))
        [x + f(x)]
        >>> solve(f(x).diff(x) - f(x) - x, f(x))
        [-x + Derivative(f(x), x)]
        >>> solve(x + exp(x)**2, exp(x), set=True)
        ([exp(x)], {(-sqrt(-x),), (sqrt(-x),)})

        >>> from sympy import Indexed, IndexedBase, Tuple, sqrt
        >>> A = IndexedBase('A')
        >>> eqs = Tuple(A[1] + A[2] - 3, A[1] - A[2] + 1)
        >>> solve(eqs, eqs.atoms(Indexed))
        {A[1]: 1, A[2]: 2}

            * To solve for a symbol implicitly, use implicit=True:

                >>> solve(x + exp(x), x)
                [-LambertW(1)]
                >>> solve(x + exp(x), x, implicit=True)
                [-exp(x)]

            * It is possible to solve for anything that can be targeted with
              subs:

                >>> solve(x + 2 + sqrt(3), x + 2)
                [-sqrt(3)]
                >>> solve((x + 2 + sqrt(3), x + 4 + y), y, x + 2)
                {y: -2 + sqrt(3), x + 2: -sqrt(3)}

            * Nothing heroic is done in this implicit solving so you may end up
              with a symbol still in the solution:

                >>> eqs = (x*y + 3*y + sqrt(3), x + 4 + y)
                >>> solve(eqs, y, x + 2)
                {y: -sqrt(3)/(x + 3), x + 2: -2*x/(x + 3) - 6/(x + 3) + sqrt(3)/(x + 3)}
                >>> solve(eqs, y*x, x)
                {x: -y - 4, x*y: -3*y - sqrt(3)}

            * If you attempt to solve for a number remember that the number
              you have obtained does not necessarily mean that the value is
              equivalent to the expression obtained:

                >>> solve(sqrt(2) - 1, 1)
                [sqrt(2)]
                >>> solve(x - y + 1, 1)  # /!\ -1 is targeted, too
                [x/(y - 1)]
                >>> [_.subs(z, -1) for _ in solve((x - y + 1).subs(-1, z), 1)]
                [-x + y]

            * To solve for a function within a derivative, use ``dsolve``.

        Single expression and more than one symbol:

            * When there is a linear solution:

                >>> solve(x - y**2, x, y)
                [(y**2, y)]
                >>> solve(x**2 - y, x, y)
                [(x, x**2)]
                >>> solve(x**2 - y, x, y, dict=True)
                [{y: x**2}]

            * When undetermined coefficients are identified:

                * That are linear:

                    >>> solve((a + b)*x - b + 2, a, b)
                    {a: -2, b: 2}

                * That are nonlinear:

                    >>> solve((a + b)*x - b**2 + 2, a, b, set=True)
                    ([a, b], {(-sqrt(2), sqrt(2)), (sqrt(2), -sqrt(2))})

            * If there is no linear solution, then the first successful
              attempt for a nonlinear solution will be returned:

                >>> solve(x**2 - y**2, x, y, dict=True)
                [{x: -y}, {x: y}]
                >>> solve(x**2 - y**2/exp(x), x, y, dict=True)
                [{x: 2*LambertW(-y/2)}, {x: 2*LambertW(y/2)}]
                >>> solve(x**2 - y**2/exp(x), y, x)
                [(-x*sqrt(exp(x)), x), (x*sqrt(exp(x)), x)]

        Iterable of one or more of the above:

            * Involving relationals or bools:

                >>> solve([x < 3, x - 2])
                Eq(x, 2)
                >>> solve([x > 3, x - 2])
                False

            * When the system is linear:

                * With a solution:

                    >>> solve([x - 3], x)
                    {x: 3}
                    >>> solve((x + 5*y - 2, -3*x + 6*y - 15), x, y)
                    {x: -3, y: 1}
                    >>> solve((x + 5*y - 2, -3*x + 6*y - 15), x, y, z)
                    {x: -3, y: 1}
                    >>> solve((x + 5*y - 2, -3*x + 6*y - z), z, x, y)
                    {x: 2 - 5*y, z: 21*y - 6}

                * Without a solution:

                    >>> solve([x + 3, x - 3])
                    []

            * When the system is not linear:

                >>> solve([x**2 + y -2, y**2 - 4], x, y, set=True)
                ([x, y], {(-2, -2), (0, 2), (2, -2)})

            * If no *symbols* are given, all free *symbols* will be selected and a
              list of mappings returned:

                >>> solve([x - 2, x**2 + y])
                [{x: 2, y: -4}]
                >>> solve([x - 2, x**2 + f(x)], {f(x), x})
                [{x: 2, f(x): -4}]

            * If any equation does not depend on the symbol(s) given, it will be
              eliminated from the equation set and an answer may be given
              implicitly in terms of variables that were not of interest:

                >>> solve([x - y, y - 3], x)
                {x: y}

        **Additional Examples**

        ``solve()`` with check=True (default) will run through the symbol tags to
        elimate unwanted solutions. If no assumptions are included, all possible
        solutions will be returned:

            >>> from sympy import Symbol, solve
            >>> x = Symbol("x")
            >>> solve(x**2 - 1)
            [-1, 1]

        By using the positive tag, only one solution will be returned:

            >>> pos = Symbol("pos", positive=True)
            >>> solve(pos**2 - 1)
            [1]

        Assumptions are not checked when ``solve()`` input involves
        relationals or bools.

        When the solutions are checked, those that make any denominator zero
        are automatically excluded. If you do not want to exclude such solutions,
        then use the check=False option:

            >>> from sympy import sin, limit
            >>> solve(sin(x)/x)  # 0 is excluded
            [pi]

        If check=False, then a solution to the numerator being zero is found: x = 0.
        In this case, this is a spurious solution since $\sin(x)/x$ has the well
        known limit (without dicontinuity) of 1 at x = 0:

            >>> solve(sin(x)/x, check=False)
            [0, pi]

        In the following case, however, the limit exists and is equal to the
        value of x = 0 that is excluded when check=True:

            >>> eq = x**2*(1/x - z**2/x)
            >>> solve(eq, x)
            []
            >>> solve(eq, x, check=False)
            [0]
            >>> limit(eq, x, 0, '-')
            0
            >>> limit(eq, x, 0, '+')
            0

        **Disabling High-Order Explicit Solutions**

        When solving polynomial expressions, you might not want explicit solutions
        (which can be quite long). If the expression is univariate, ``CRootOf``
        instances will be returned instead:

            >>> solve(x**3 - x + 1)
            [-1/((-1/2 - sqrt(3)*I/2)*(3*sqrt(69)/2 + 27/2)**(1/3)) - (-1/2 -
            sqrt(3)*I/2)*(3*sqrt(69)/2 + 27/2)**(1/3)/3, -(-1/2 +
            sqrt(3)*I/2)*(3*sqrt(69)/2 + 27/2)**(1/3)/3 - 1/((-1/2 +
            sqrt(3)*I/2)*(3*sqrt(69)/2 + 27/2)**(1/3)), -(3*sqrt(69)/2 +
            27/2)**(1/3)/3 - 1/(3*sqrt(69)/2 + 27/2)**(1/3)]
            >>> solve(x**3 - x + 1, cubics=False)
            [CRootOf(x**3 - x + 1, 0),
             CRootOf(x**3 - x + 1, 1),
             CRootOf(x**3 - x + 1, 2)]

        If the expression is multivariate, no solution might be returned:

            >>> solve(x**3 - x + a, x, cubics=False)
            []

        Sometimes solutions will be obtained even when a flag is False because the
        expression could be factored. In the following example, the equation can
        be factored as the product of a linear and a quadratic factor so explicit
        solutions (which did not require solving a cubic expression) are obtained:

            >>> eq = x**3 + 3*x**2 + x - 1
            >>> solve(eq, cubics=False)
            [-1, -1 + sqrt(2), -sqrt(2) - 1]

        **Solving Equations Involving Radicals**

        Because of SymPy's use of the principle root, some solutions
        to radical equations will be missed unless check=False:

            >>> from sympy import root
            >>> eq = root(x**3 - 3*x**2, 3) + 1 - x
            >>> solve(eq)
            []
            >>> solve(eq, check=False)
            [1/3]

        In the above example, there is only a single solution to the
        equation. Other expressions will yield spurious roots which
        must be checked manually; roots which give a negative argument
        to odd-powered radicals will also need special checking:

            >>> from sympy import real_root, S
            >>> eq = root(x, 3) - root(x, 5) + S(1)/7
            >>> solve(eq)  # this gives 2 solutions but misses a 3rd
            [CRootOf(7*x**5 - 7*x**3 + 1, 1)**15,
            CRootOf(7*x**5 - 7*x**3 + 1, 2)**15]
            >>> sol = solve(eq, check=False)
            >>> [abs(eq.subs(x,i).n(2)) for i in sol]
            [0.48, 0.e-110, 0.e-110, 0.052, 0.052]

        The first solution is negative so ``real_root`` must be used to see that it
        satisfies the expression:

            >>> abs(real_root(eq.subs(x, sol[0])).n(2))
            0.e-110

        If the roots of the equation are not real then more care will be
        necessary to find the roots, especially for higher order equations.
        Consider the following expression:

            >>> expr = root(x, 3) - root(x, 5)

        We will construct a known value for this expression at x = 3 by selecting
        the 1-th root for each radical:

            >>> expr1 = root(x, 3, 1) - root(x, 5, 1)
            >>> v = expr1.subs(x, -3)

        The ``solve`` function is unable to find any exact roots to this equation:

            >>> eq = Eq(expr, v); eq1 = Eq(expr1, v)
            >>> solve(eq, check=False), solve(eq1, check=False)
            ([], [])

        The function ``unrad``, however, can be used to get a form of the equation
        for which numerical roots can be found:

            >>> from sympy.solvers.solvers import unrad
            >>> from sympy import nroots
            >>> e, (p, cov) = unrad(eq)
            >>> pvals = nroots(e)
            >>> inversion = solve(cov, x)[0]
            >>> xvals = [inversion.subs(p, i) for i in pvals]

        Although ``eq`` or ``eq1`` could have been used to find ``xvals``, the
        solution can only be verified with ``expr1``:

            >>> z = expr - v
            >>> [xi.n(chop=1e-9) for xi in xvals if abs(z.subs(x, xi).n()) < 1e-9]
            []
            >>> z1 = expr1 - v
            >>> [xi.n(chop=1e-9) for xi in xvals if abs(z1.subs(x, xi).n()) < 1e-9]
            [-3.0]

        Parameters
        ==========

        f :
            - a single Expr or Poly that must be zero
            - an Equality
            - a Relational expression
            - a Boolean
            - iterable of one or more of the above

        symbols : (object(s) to solve for) specified as
            - none given (other non-numeric objects will be used)
            - single symbol
            - denested list of symbols
              (e.g., ``solve(f, x, y)``)
            - ordered iterable of symbols
              (e.g., ``solve(f, [x, y])``)

        flags :
            dict=True (default is False)
                Return list (perhaps empty) of solution mappings.
            set=True (default is False)
                Return list of symbols and set of tuple(s) of solution(s).
            exclude=[] (default)
                Do not try to solve for any of the free symbols in exclude;
                if expressions are given, the free symbols in them will
                be extracted automatically.
            check=True (default)
                If False, do not do any testing of solutions. This can be
                useful if you want to include solutions that make any
                denominator zero.
            numerical=True (default)
                Do a fast numerical check if *f* has only one symbol.
            minimal=True (default is False)
                A very fast, minimal testing.
            warn=True (default is False)
                Show a warning if ``checksol()`` could not conclude.
            simplify=True (default)
                Simplify all but polynomials of order 3 or greater before
                returning them and (if check is not False) use the
                general simplify function on the solutions and the
                expression obtained when they are substituted into the
                function which should be zero.
            force=True (default is False)
                Make positive all symbols without assumptions regarding sign.
            rational=True (default)
                Recast Floats as Rational; if this option is not used, the
                system containing Floats may fail to solve because of issues
                with polys. If rational=None, Floats will be recast as
                rationals but the answer will be recast as Floats. If the
                flag is False then nothing will be done to the Floats.
            manual=True (default is False)
                Do not use the polys/matrix method to solve a system of
                equations, solve them one at a time as you might "manually."
            implicit=True (default is False)
                Allows ``solve`` to return a solution for a pattern in terms of
                other functions that contain that pattern; this is only
                needed if the pattern is inside of some invertible function
                like cos, exp, ect.
            particular=True (default is False)
                Instructs ``solve`` to try to find a particular solution to a linear
                system with as many zeros as possible; this is very expensive.
            quick=True (default is False)
                When using particular=True, use a fast heuristic to find a
                solution with many zeros (instead of using the very slow method
                guaranteed to find the largest number of zeros possible).
            cubics=True (default)
                Return explicit solutions when cubic expressions are encountered.
            quartics=True (default)
                Return explicit solutions when quartic expressions are encountered.
            quintics=True (default)
                Return explicit solutions (if possible) when quintic expressions
                are encountered.

        See Also
        ========

        rsolve: For solving recurrence relationships
        dsolve: For solving differential equations

```python
solution
```

```python
len(solution)
```

```python
type(solution)
```

```python
solution[DIFF2Q]
```

```python
solution[DIFF2P]
```

```python
soluEqP = solution[DIFF2P].subs({Derivative(qk,tau):0, Derivative(pk,tau):0})
soluEqQ = solution[DIFF2Q].subs({Derivative(qk,tau):0, Derivative(pk,tau):0})
```

```python
soluEqP
```

```python

```

```python

```

```python
solution[DIFF2P]
```

```python

```

```python

```

```python

```

```python
eq1.expand()
```

```python
DerivPK, DerivQK, PK, QK = symbols('DerivPK, DerivQK, PK, QK')

soluDIFF2PP = solution[DIFF2P].subs({Derivative(pk,tau): DerivPK, Derivative(qk,tau): DerivQK,
                       Function('pk')(tau): PK, Function('qk')(tau):QK})
soluDIFF2QQ = solution[DIFF2Q].subs({Derivative(pk,tau): DerivPK, Derivative(qk,tau): DerivQK,
                       Function('pk')(tau): PK, Function('qk')(tau):QK})
```

```python
ms=0.0000261725
mT = 5.0750952130962986 *10**(-6)
cs=1.94991*10**8
Ds = 0.05###; (*0.005 damping stator*)
#d = 2 *sqrt(msT* cs *Ds) = 38.2402923781611
rhor = 2700 ###(*Al*)
####(*leaf spring*)
EE = 206000###; (*Nmm^2*)
EE = EE*10**6
B = 0.003 ##;(*width*)
t = 0.0005  ###; (*thickness*)
l = 0.02   ###; (*length*)
Ib = (B*t**3)/12
#cr ####(*0;4000;*) (**)
rout = 0.003124764129949177
rin = 0.002224764129949177
Rr = rout
Hr = 0.001 ###(*0.003*)

r1 = 0.001
mr = float(pi) * rhor *Rr**2 *Hr - float(pi) * rhor *r1**2 *Hr ### (*6.4 10 -4 ;*)
Ha = 0.0005
ma = float(pi) *rhor * Ha*(rout**2 - rin**2)

solucdiff2pp =(soluDIFF2PP.subs({Ir: mr*(Rr**2 + r1**2)/2 + ma*(rout**2+ rin**2)/2,
                                 Psi_theta_theta: 226.536, Uu: -0.377673,
                  h: 0.0012, Rk: 0.0027, msT: ms + mT, hT: 0.0015,
                  Vo: 100, cUo: 0.0174596, d: 38.2402923781611, ps: 0.5*10**(-3), mR: mr + ma,
                  cr: (3 *EE *Ib)/l**3, omega: 2.72951*10**6, Texte: 0.1*10**(-3), n: 4, k: 2}) ).expand()

solucdiff2qq = (soluDIFF2QQ.subs({Ir: mr*(Rr**2 + r1**2)/2 + ma*(rout**2+ rin**2)/2,
                                  Psi_theta_theta: 226.536, Uu: -0.377673,
                  h: 0.0012, Rk: 0.0027, msT: ms + mT, hT: 0.0015,
                  Vo: 100, cUo: 0.0174596, d: 38.2402923781611, ps: 0.5*10**(-3), mR: mr + ma,
                  cr: (3 *EE *Ib)/l**3, omega: 2.72951*10**6, Texte: 0.1*10**(-3), n: 4, k: 2}) ).expand()

```

```python
solucdiff2qq
```

```python

```

```python
help(sympy.lambdify)
```

```python

```

```python
help(scipy.integrate.solve_ivp)
```

```python

```

```python
from sympy import symbols, lambdify
from sympy.parsing.sympy_parser import parse_expr
import numpy as np

xs = symbols('x1 x2')
ks = symbols('k1 k2')
strs = ['-k1 * x1**2 + k2 * x2', 'k1 * x1**2 - k2 * x2']
syms = [parse_expr(item) for item in strs]

# Convert each expression in syms to a function with signature f(x1, x2, k1, k2):
funcs = [lambdify(xs + ks, f) for f in syms]
print(type(funcs[0]))

# This is not exactly the same as the `my_odes` in the question.
# `t` is included so this can be used with `scipy.integrate.odeint`.
# The value returned by `sym.subs` is wrapped in a call to `float`
# to ensure that the function returns python floats and not sympy Floats.
def my_odes(x, t, k):
    all_dict = dict(zip(xs, x))
    all_dict.update(dict(zip(ks, k)))
    return np.array([float(sym.subs(all_dict)) for sym in syms])

def lambdified_odes(x, t, k):
    x1, x2 = x
    k1, k2 = k
    xdot = [f(x1, x2, k1, k2) for f in funcs]
    return xdot

if __name__ == "__main__":
    from scipy.integrate import odeint

    k1 = 0.5
    k2 = 1.0
    init = [1.0, 0.0]
    t = np.linspace(0, 1, 6)
    sola = odeint(lambdified_odes, init, t, args=((k1, k2),))
    solb = odeint(my_odes, init, t, args=((k1, k2),))
    print(np.allclose(sola, solb))

```

```python
funcs=[sympy.lambdify((tau,PK,QK,DerivPK,DerivQK),DerivPK),sympy.lambdify((tau,PK,QK,DerivPK,DerivQK),DerivQK),sympy.lambdify((tau,PK,QK,DerivPK,DerivQK),solucdiff2pp,"numpy"),sympy.lambdify((tau,PK,QK,DerivPK,DerivQK),solucdiff2qq,"numpy")]
# print(funcs[0](0,0,0))
def fun(tau,z):
    PK,QK,DerivPK,DerivQK=z
    xdot=[f(tau,PK,QK,DerivPK,DerivQK) for f in funcs]
    return xdot
y0 = [0,0.0000001,0.0000001, 0]
print(type(sympy.lambdify((PK,QK,DerivPK,DerivQK),DerivPK)))
print(type(sympy.lambdify((PK,QK,DerivPK,DerivQK),solucdiff2pp)))
```

```python

```

```python
funcs=[sympy.lambdify((tau,PK,QK,DerivPK,DerivQK),DerivPK),sympy.lambdify((tau,PK,QK,DerivPK,DerivQK),DerivQK),sympy.lambdify((tau,PK,QK,DerivPK,DerivQK),solucdiff2pp),sympy.lambdify((tau,PK,QK,DerivPK,DerivQK),solucdiff2qq)]

def fun(tau,z):
    PK,QK,DerivPK,DerivQK=z
    xdot=[f(tau,PK,QK,DerivPK,DerivQK) for f in funcs]
    return xdot
y0 = [0.000000001,0.000000001,0, 0]  #initial conditions for pk, qk, Derivative(pk(tau),tau), Derivative(qk(tau),tau)
#tau = numpy.linspace(0,10,101) #a solution 101 evenly spaced samples in the interval 0 <= t <= 10
sol=scipy.integrate.solve_ivp(fun,[0,301],y0,dense_output=True)
```

```python
sol
```

```python
taut = numpy.linspace(0,10,301) #a solution 101 evenly spaced samples in the interval 0 <= t <= 10
#print(sol.y)
#print(sol.t)
#
soly=sol.y
plt.plot(sol.t,soly.T)
plt.xlabel("tau")
plt.legend(["Pk","Qk","derivPk","derivQk"],shadow=True)
plt.title("Run-up")
plt.show()
```

```python
plt.plot(sol.t,soly[0:2].T)
plt.xlabel("tau")
plt.legend(["Pk","Qk"],shadow=True)
plt.title("Run-up")
plt.show()
```

```python
# T = tau/tauC, Pkk = PK/pkkC, Qkk = QK/qkkC
# Derivative(qk(tau),tau) = Derivative(qk,T)*Derivative(T,tau) = Derivative(qk,T)*(1/tauC)
# DerivPK = derivPK / tauC
# derivPK = Derivative(pk(T),T)

# dydt = [PK, QK, solucdiff2pp, solucdiff2qq]

tau = symbols('tau')
T, tauC, derivPK, derivQK, Pkk, Qkk = symbols('T, tauC, derivPK, derivQK, Pkk, Qkk')
dydt = [PK.subs({DerivPK: derivPK/tauC, DerivQK: derivQK, tau: tauC*T}),
        QK.subs({DerivPK: derivPK/tauC, DerivQK: derivQK, tau: tauC*T}),
        solucdiff2pp.subs({DerivPK: derivPK/tauC, DerivQK: derivQK, tau: tauC*T, Pkk: PK/pkkC, Qkk: QK/qkkC}),
        solucdiff2qq.subs({DerivPK: derivPK/tauC, DerivQK: derivQK, tau: tauC*T, Pkk: PK/pkkC, Qkk: QK/qkkC})]

```

```python
dydt
```

constantes
n, k : nondimensional
tau : [s]

ms=0.0000261725 # []
mT = 5.0750952130962986 *10**(-6) # []
cs=1.94991*10**8
Ds = 0.06###; (*0.005 Dämpfungsmaß des Stators*)
#d = 2 *sqrt(msT* cs *Ds) = 38.2402923781611
rhor = 2700  # [N/m²] ###(*Aluminum*)
####(*viga mola*
EE = 206000###; (*Nmm^2*)
EE = EE*10**6
B = 0.0025 ##;(*largura*)
t = 0.0005  ###; (*espessura*)
l = 0.02   ###; (*comprimento*)
Ib = (B*t**3)/12
#cr ####(*0;4000;*) (*elasticidade da viga mola*)
rout = 0.003124764129949177
rin = 0.002224764129949177
Rr = rout
Hr = 0.001 ###(*0.003*)

r1 = 0.001
mr = float(pi) * rhor *Rr**2 *Hr - float(pi) * rhor *r1**2 *Hr ### (*6.4 10 -4 ;*)
Ha = 0.0005
ma = float(pi) *rhor * Ha*(rout**2 - rin**2)

solucdiff2pp =(soluDIFF2PP.subs({Ir: mr*(Rr**2 + r1**2)/2 + ma*(rout**2+ rin**2)/2,
                                 Psi_theta_theta: 226.536, Uu: -0.377673,
                  h: 0.0012, Rk: 0.0027, msT: ms + mT, hT: 0.0015,
                  Vo: 100, cUo: 0.0174596, d: 38.2402923781611, ps: 0.5*10**(-3), mR: mr + ma,
                  cr: (3 *EE *Ib)/l**3, omega: 2.72951*10**6, Texte: 0.1*10**(-3), n: 4, k: 2}) ).expand()

Ir = [kg m²]
Psi_theta_theta =
Uu =
h = [m]   #stator thickness
Rk = [m] #contact point/radius (2,4)
msT = [kg]
hT = [m]
Vo = [V]
cUo = [
d =
ps = [m]
mR = [kg]
cr = [N/m²]*[m⁴]/[m³]=[N/m]
omega = [1/s]
Texte = [Nm]

PI teorem