Пример #1
0
    def latex(self):
        r"""
        Print a LaTeX representation of a linear multistep formula.

        **Example**::

            >>> from nodepy import lm
            >>> print(lm.Adams_Bashforth(2).latex())
            \begin{align} y_{n + 2} - y_{n + 1} = \frac{3}{2}h f(y_{n + 1}) - \frac{1}{2}h f(y_{n})\end{align}

        """
        from sympy import symbols, latex
        n = symbols('n')
        from nodepy.snp import printable
        k = len(self)
        alpha_terms = []
        beta_terms = []
        for i in range(k+1):
            subscript = latex(n+k-i)
            if self.alpha[k-i] != 0:
                alpha_terms.append(printable(self.alpha[k-i],return_one=False)
                                   + ' y_{'+subscript+'}')
            if self.beta[k-i] != 0:
                beta_terms.append(printable(self.beta[k-i],return_one=False)
                                  +  'h f(y_{'+subscript+'})')
        lhs = ' + '.join(alpha_terms)
        rhs = ' + '.join(beta_terms)
        s = r'\begin{align}'+ ' = '.join([lhs,rhs]) + r'\end{align}'
        s = s.replace('+ -','-')
        return s
Пример #2
0
    def latex(self):
        r"""
        Print a LaTeX representation of a linear multistep formula.

        **Example**::

            >>> from nodepy import lm
            >>> print(lm.Adams_Bashforth(2).latex())
            \begin{align} y_{n + 2} - y_{n + 1} = \frac{3}{2}h f(y_{n + 1}) - \frac{1}{2}h f(y_{n})\end{align}

        """
        from sympy import symbols, latex
        n = symbols('n')
        from nodepy.snp import printable
        k = len(self)
        alpha_terms = []
        beta_terms = []
        for i in range(k + 1):
            subscript = latex(n + k - i)
            if self.alpha[k - i] != 0:
                alpha_terms.append(
                    printable(self.alpha[k - i], return_one=False) + ' y_{' +
                    subscript + '}')
            if self.beta[k - i] != 0:
                beta_terms.append(
                    printable(self.beta[k - i], return_one=False) + 'h f(y_{' +
                    subscript + '})')
        lhs = ' + '.join(alpha_terms)
        rhs = ' + '.join(beta_terms)
        s = r'\begin{align}' + ' = '.join([lhs, rhs]) + r'\end{align}'
        s = s.replace('+ -', '-')
        return s