Пример #1
0
    def _makefm(self, params):
        zdot = self.x[self.dim:]
        OhmP = tn.subs(self._Ohm, zip(self.z, self._P))
        OhmI = tn.subs(self._dPsi, zip(self.q, OhmP))

        zz = self._P
        zzdot = np.dot(self._dP, zdot)

        out = -tn.einsum('i,ijk,k', zzdot, self.dMzz, zzdot) \
            + tn.einsum('i,ikj,k', zzdot, self.dMzz, zzdot) / 2
        out = np.dot(self.Mzzi, out + self.dVzz)
        out = out - tn.einsum('ijk,j,k', tn.diff(self._dP, self.z), zdot, zdot)
        out = out + matmult(OhmI, self.Mqi, self.u)
        # in general, there should be a subs here
        out = matmult(self._dPi, out)
        out = np.concatenate((zdot, out))

        out = tn.SymExpr(tn.subs(out, self.ztox))
        out.callable(*params)

        return out
Пример #2
0
    def _makefm(self, params):
        zdot = self.x[self.dim:]
        OhmP = tn.subs(self._Ohm, zip(self.z, self._P))
        OhmI = tn.subs(self._dPsi, zip(self.q, OhmP))

        zz = self._P
        zzdot = np.dot(self._dP, zdot)

        out = -tn.einsum('i,ijk,k', zzdot, self.dMzz, zzdot) \
            + tn.einsum('i,ikj,k', zzdot, self.dMzz, zzdot) / 2
        out = np.dot(self.Mzzi, out + self.dVzz)
        out = out - tn.einsum('ijk,j,k',
                              tn.diff(self._dP, self.z), zdot, zdot)
        out = out + matmult(OhmI, self.Mqi, self.u)
                            # in general, there should be a subs here
        out = matmult(self._dPi, out)
        out = np.concatenate((zdot, out))

        out = tn.SymExpr(tn.subs(out, self.ztox))
        out.callable(*params)

        return out
Пример #3
0
    def _makefp(self, params):
        zdot = self.x[self.dim:]
        out = np.concatenate((
            zdot,
            np.dot(
                self.Mzi, -tn.einsum('i,ijk,k', zdot, self.dMz, zdot) +
                tn.einsum('i,ikl,k', zdot, self.dMz, zdot) / 2 + self.dVz) +
            matmult(
                tn.subs(self._dPsi, self.qtoz),
                self.Mqi,  # here we might need subs
                self.u)))

        out = tn.SymExpr(tn.subs(out, self.ztox))
        out.callable(*params)
        return out
Пример #4
0
    def _makefp(self, params):
        zdot = self.x[self.dim:]
        out = np.concatenate((zdot,
                              np.dot(self.Mzi,
                                     - tn.einsum(
                                         'i,ijk,k', zdot, self.dMz, zdot)
                                     + tn.einsum(
                                         'i,ikl,k', zdot, self.dMz, zdot) / 2
                                     + self.dVz)
                              + matmult(
                                  tn.subs(self._dPsi, self.qtoz),
                                  self.Mqi,  # here we might need subs
                                  self.u)
                              ))

        out = tn.SymExpr(tn.subs(out, self.ztox))
        out.callable(*params)
        return out
Пример #5
0
from nlsymb import np, sym, matmult, tensor
import nlsymb.tensor as tn

from sympy import Symbol as S

if __name__ == "__main__":
    x1 = S('x1')
    x2 = S('x2')
    x = np.array([x1, x2])
    f = np.array([x[0], x[1]**2, 3 * x[0] + x[1]])
    print f
    print tn.subs(f, {x1: 2.0, x2: 3.0})
    print tn.eval(f, x, [2.0, 3.0])

    A = tn.diff(f, x)
    print A
    print A[0, 1]
    Anum = tn.eval(A, x, [2, 3])
    print Anum[0, 1]

    g = np.dot(A, x)
    print g

    g = tn.einsum('ij,j', A, x)
    print g
Пример #6
0
from nlsymb import np, sym, matmult, tensor
import nlsymb.tensor as tn

from sympy import Symbol as S

if __name__ == "__main__":
    x1 = S('x1')
    x2 = S('x2')
    x = np.array([x1, x2])
    f = np.array([x[0], x[1]**2, 3*x[0]+x[1]]) 
    print f
    print tn.subs(f, {x1:2.0, x2:3.0})
    print tn.eval(f, x, [2.0, 3.0])

    A = tn.diff(f, x)
    print A
    print A[0, 1]
    Anum = tn.eval(A, x, [2,3])
    print Anum[0,1]

    g = np.dot(A, x)
    print g

    g = tn.einsum('ij,j', A, x)
    print g