• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python sympy.init_printing函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sympy.init_printing函数的典型用法代码示例。如果您正苦于以下问题:Python init_printing函数的具体用法?Python init_printing怎么用?Python init_printing使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了init_printing函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: pprint

    def pprint(self, **settings):
        """
        Print the PHS structure :math:`\\mathbf{b} = \\mathbf{M} \\cdot \\mathbf{a}`
        using sympy's pretty printings.

        Parameters
        ----------

        settings : dic
            Parameters for sympy.pprint function.

        See Also
        --------

        sympy.pprint

        """

        sympy.init_printing()

        b = types.matrix_types[0](self.dtx() +
                                  self.w +
                                  self.y +
                                  self.cy)

        a = types.matrix_types[0](self.dxH() +
                                  self.z +
                                  self.u +
                                  self.cu)

        sympy.pprint([b, self.M, a], **settings)
开发者ID:A-Falaize,项目名称:pyphs,代码行数:31,代码来源:core.py


示例2: hst

def hst(n=16):
    # %pylab inline # command in ipython that imports sci modulues
    import sympy as sym
    sym.init_printing()
    for k in range(n+1):
        n = float(n)
        print('HST63%02d = %s' %  ( k, sym.Rational(k,n*2) ) )  
开发者ID:andela-osule,项目名称:mechpy,代码行数:7,代码来源:units.py


示例3: in_mm

def in_mm(n=16):
    # %pylab inline # command in ipython that imports sci modulues
    import sympy as sym
    sym.init_printing()
    for k in range(n+1):
        n = float(n)
        print(' %5s in - %.6f in - %.6f mm ' %  (sym.Rational(k,n) , k/n, 25.4*k/n ) )  
开发者ID:andela-osule,项目名称:mechpy,代码行数:7,代码来源:units.py


示例4: setup_pprint

def setup_pprint():
    from sympy import pprint_use_unicode, init_printing

    # force pprint to be in ascii mode in doctests
    pprint_use_unicode(False)

    # hook our nice, hash-stable strprinter
    init_printing(pretty_print=False)
开发者ID:qsnake,项目名称:sympy,代码行数:8,代码来源:runtests.py


示例5: triangle_length

def triangle_length(l):
    sympy.init_printing()
    for n in range(1, 17):
        print("Triangle: ", n)
        print (l)
        sympy.pprint (l * sympy.sqrt(n), use_unicode=True) 
        sympy.pprint (l * sympy.sqrt(n+1), use_unicode=True) 
    print ("-------------------------")
开发者ID:schirrecker,项目名称:Math,代码行数:8,代码来源:pythagorean_spiral.py


示例6: print_series

def print_series(n):
    # initialize printing system with
    # reverse order
    init_printing(order='rev-lex')
    x = Symbol('x')
    series = x
    for i in range(2, n+1):
        series = series + (x**i)/i
    pprint(series)
开发者ID:KentFujii,项目名称:doing_math,代码行数:9,代码来源:series.py


示例7: main

def main():
    if sympy.__version__ != "1.0":
        sys.exit("The doctests must be run against SymPy 1.0. Please install SymPy 1.0 and run them again.")
    full_text = ""

    for file in files:
        with open(file, 'r') as f:
            s = f.read()
            st = s.find(begin)
            while st != -1:
                if not (st >= len(skip)) or s[st - len(skip) : st] != skip:
                    full_text += s[st + len(begin) : s.find(end, st)]
                st = s.find(begin, st+ len(begin))

    full_text = full_text.replace(r'\end{verbatim}', '')

    with open(output_file, "w") as f:
        f.write("'''\n %s \n'''" % full_text)

    # force pprint to be in ascii mode in doctests
    pprint_use_unicode(False)

    # hook our nice, hash-stable strprinter
    init_printing(pretty_print=False)

    import test_full_paper

    # find the doctest
    module = pdoctest._normalize_module(test_full_paper)
    tests = SymPyDocTestFinder().find(module)
    test = tests[0]

    runner = SymPyDocTestRunner(optionflags=pdoctest.ELLIPSIS |
            pdoctest.NORMALIZE_WHITESPACE |
            pdoctest.IGNORE_EXCEPTION_DETAIL)
    runner._checker = SymPyOutputChecker()

    old = sys.stdout
    new = StringIO()
    sys.stdout = new

    future_flags = __future__.division.compiler_flag | __future__.print_function.compiler_flag

    try:
        f, t = runner.run(test, compileflags=future_flags,
                          out=new.write, clear_globs=False)
    except KeyboardInterrupt:
        raise
    finally:
        sys.stdout = old

    if f > 0:
        print(new.getvalue())
        return 1
    else:
        return 0
开发者ID:mattcurry,项目名称:sympy-paper,代码行数:56,代码来源:test-paper.py


示例8: print_series

def print_series(n, x_value):
	init_printing(order = 'rev-lex')
	x = Symbol('x')
	series = x
	for i in range(2, n+1):
		series = series + (x**i)/i
	pprint(series)

	series_value = series.subs({x:x_value})
	print('Value of the series at {0}: {1}'.format(x_value, series_value))
开发者ID:NTomtishen,项目名称:MathWithPython,代码行数:10,代码来源:SeriesPrinting.py


示例9: printSeries

def printSeries(n, val):
    init_printing(order='rev-lex')
    x = Symbol('x')
    expr = x
    for i in range(2, n + 1):
        expr += (x**i / i)
    pprint(expr)

    res = expr.subs({x: val})
    print(res)
开发者ID:JSONMartin,项目名称:codingChallenges,代码行数:10,代码来源:sympy_math.py


示例10: new_MM

	def new_MM(self):
		init_printing()
		
		m, n, k, self.tag = self.__choose_problem_type__()
		
		self.A = self.random_integer_matrix( m, k )
		self.x = self.random_integer_matrix( k, n )
		self.answer = self.A * self.x
		
		return Math( "$$" + latex( MatMul( self.A, self.x ), mat_str = "matrix" ) + "=" + "?" + "$$" )
开发者ID:KurtOstergaard,项目名称:Linear-Algebra,代码行数:10,代码来源:generate_problems.py


示例11: new_problem

	def new_problem(self):
		init_printing()

		m = self.random_integer( 3, 4 )
		n = self.random_integer( 2, 3 )

		self.A = self.random_integer_matrix( m, n )
		self.x = self.random_integer_matrix( n, 1 )
		self.answer = self.A * self.x

		return Math( "$$" + latex( MatMul( self.A, self.x ), mat_str = "matrix" ) + "=" + "?" + "$$" )
开发者ID:KurtOstergaard,项目名称:Linear-Algebra,代码行数:11,代码来源:generate_problems.py


示例12: print_series

def print_series(n, x_value):
    # initialize printing system with
    # reverse order
    init_printing(order='rev-lex')
    x = Symbol('x')
    series = x
    for i in range(2, n+1):
        series = series + (x**i)/i
    pprint(series)
    # evaluate the series at x_value
    series_value = series.subs({x:x_value})
    print('Value of the series at {0}: {1}'.format(x_value, series_value))
开发者ID:KentFujii,项目名称:doing_math,代码行数:12,代码来源:calculate_series.py


示例13: init_sympy_printing

 def init_sympy_printing(self, line):
     from sympy import init_printing
     init_printing()
     ip = get_ipython()
     latex = ip.display_formatter.formatters["text/latex"]
     for key in latex.type_printers.keys():
         if key.__module__ == "__builtin__":
             del latex.type_printers[key]
     png = ip.display_formatter.formatters["image/png"]
     for key in png.type_printers.keys():
         if key.__module__ == "__builtin__":
             del png.type_printers[key]
开发者ID:Andor-Z,项目名称:scpy2,代码行数:12,代码来源:nbmagics.py


示例14: exer_mult_step

def exer_mult_step(expression):
    import re
    import sympy as sym
    from sympy import init_printing; init_printing() 
    from IPython.display import display, Math, Latex
    a, b, c, x, y, z = sym.symbols("a b c x y z")
    expression=str(expression)
    evexpr=sym.expand(eval(expression))
    print 'Expand the following expression step by step:'
    display(Math(str(expression).replace('**','^').replace('*','')))
    print 'Multiply ALL the monomials:'
    factor=re.split('\)\s*\*\s*\(',str(expression))
    refactor=[ re.split('\(|\)',factor[i])[1-i] for i in range(len(factor))]
    terms=[ re.split(':',re.sub('\s*(\+|\-)\s*',r':\1',refactor[i])) for i in range(len(refactor)) ]
    expandednr=''
    for i in range(len(terms[0])):
    #nci=''
        if terms[0][i]:
            nci=terms[0][i]
            terms[0][i]=r'{\color{red}{%s}}' %terms[0][i]
            for j in range(len(terms[1])):
            #ncj=''
                if terms[1][j]:
                    ncj=terms[1][j]
                    terms[1][j]=r'\color{red}{%s}' %terms[1][j]
        
                    l=jointerms(terms)
                    display(Math(l.replace('**','^').replace('*','')))
                    terms[1][j]=ncj
                    newterm=raw_input()
                    if re.search('^-',newterm):
                        newterm=newterm
                    else:
                        newterm='+'+newterm
                    expandednr=expandednr+newterm
                    expandednr=re.sub('^\+','',expandednr)
                
            terms[0][i]=nci  
        
    print 'Reduce the expression:' 
    display(Math(expandednr.replace('**','^').replace('*','')))
    result=raw_input()
    if evexpr== eval(result): 
        print "Good job!, final result:"
        return eval(result)
        
    else:
        print('WRONG!!!\nRight result:')
        return sym.expand(expression)
开发者ID:simonres,项目名称:algebra,代码行数:49,代码来源:polymult.py


示例15: ItosLemma

def ItosLemma(f, drift, diffusion, finv=None, replaceX=True, pretty_print=False):
  """
    This function applies Ito's lemma given a twice-differentiable,
    invertible function (f) and drift and diffusion coefficients for a
    stochastic process (X_t) satisfying SDE

      dX = drift(X,t) dt + diffusion(X,t) dW

    This routine then prints out a new the SDE for Y=f(X)

      dY = drift_new(X,t) dt + diffusion_new(X,t) dW_t

    If replaceX=True, this will replace instances of X with f^{-1}(Y)

    NOTE: Inputs f, drift, diffusion _all_ expected to be sympy fcns.
    Derivatives are taken with respect to sympy symbols/variables X and
    t in those functions.
  """

  # Define symbols for display later
  t, Y, dt, dW, dY, dX, Y_t = sp.symbols('t Y dt dW dY dX Y_t')

  # Define differentiation functions
  DX, Dt = map(lambda var: (lambda fcn: sp.diff(fcn, var)), [X, t])

  # Compute drift_new and diffusion_new according to Ito's Lemma
  drift_new     = Dt(f) + DX(f)*b + 0.5*DX(DX(f))*(s**2)
  diffusion_new = DX(f)*s

  # If finv not given, invert Y=f(X) to get Y = f^{-1}(X)
  if finv == None:
    finv = invertInteractive(f, X, Y)

  # Substitute out X with f^{-1}(Y)
  if replaceX:
    drift_new, diffusion_new = map(lambda fcn: fcn.subs(X,finv).simplify(),
                                   [drift_new, diffusion_new])

  # Print the results to screen
  if pretty_print:
    sp.init_printing()
  print "\nOriginal SDE\n------------\n"
  sp.pprint(sp.Eq(dX, (drift)*dt + (diffusion)*dW))
  print "\n\nNew SDE for Y = f(X)\n--------------------\n"
  sp.pprint(sp.Eq(dY,(drift_new)*dt + (diffusion_new)*dW))
  print "\nwhere"
  sp.pprint(sp.Eq(Y,f))
  print("\n\n")
开发者ID:MattCocci,项目名称:ReusableCode,代码行数:48,代码来源:ItosLemma.py


示例16: exer_mult

def exer_mult(expression):
    import sympy as sym
    from sympy import init_printing; init_printing() 
    from IPython.display import display, Math, Latex
    a, b, c, x, y, z = sym.symbols("a b c x y z")
    expression=str(expression)
    evexpr=sym.expand(eval(expression))
    print 'Expand the expression:'
    display(Math(str(expression).replace('**','^').replace('*','')))
    result=raw_input()
    if evexpr== eval(result): 
        print "Good job! Final result:"
        return eval(result)
    else:
        print('WRONG!!!\nRight result:')
        return sym.expand(eval(expression))
开发者ID:simonres,项目名称:algebra,代码行数:16,代码来源:polymult.py


示例17: init_from_matmodlab_magic

def init_from_matmodlab_magic(p):
    if p == BOKEH:
        from bokeh.plotting import output_notebook
        output_notebook()
        environ.plotter = BOKEH
        i = 2
    elif p == MATPLOTLIB:
        environ.plotter = MATPLOTLIB
        i = 1

    environ.notebook = i
    environ.verbosity = 0
    try:
        from sympy import init_printing
        init_printing()
    except ImportError:
        pass
开发者ID:tjfulle,项目名称:matmodlab,代码行数:17,代码来源:__init__.py


示例18: Format

def Format(Fmode=True, Dmode=True, dop=1, inverse='full'):
    """
    Set modes for latex printer -

        Fmode:  Suppress function arguments (True)          Use sympy latex for functions (False)
        Dmode:  Use compact form of derivatives (True)      Use sympy latex for derivatives (False)

    and redirects printer output so that latex compiler can capture it.
    """
    global Format_cnt

    GaLatexPrinter.Dmode = Dmode
    GaLatexPrinter.Fmode = Fmode
    GaLatexPrinter.inv_trig_style = inverse

    if Format_cnt == 0:
        Format_cnt += 1

        """
        if metric.in_ipynb():
            GaLatexPrinter.ipy = True
        else:
            GaLatexPrinter.ipy = False

        GaLatexPrinter.dop = dop
        GaLatexPrinter.latex_flg = True

        if not GaLatexPrinter.ipy:
            GaLatexPrinter.redirect()
        """
        GaLatexPrinter.dop = dop
        GaLatexPrinter.latex_flg = True
        GaLatexPrinter.redirect()

        Basic.__str__ = lambda self: GaLatexPrinter().doprint(self)
        Matrix.__str__ = lambda self: GaLatexPrinter().doprint(self)
        Basic.__repr_ = lambda self: GaLatexPrinter().doprint(self)
        Matrix.__repr__ = lambda self: GaLatexPrinter().doprint(self)

        if isinteractive():
            init_printing(use_latex= 'mathjax')

    return
开发者ID:sashmit,项目名称:galgebra,代码行数:43,代码来源:printer.py


示例19: exer_mult_step_old

def exer_mult_step_old(expression):
    import re
    import sympy as sym
    from sympy import init_printing; init_printing() 
    from IPython.display import display, Math, Latex
    a, b, c, x, y, z = sym.symbols("a b c x y z")
    expression=str(expression)
    evexpr=sym.expand(eval(expression))
    print 'Expand the following expression step by step:'
    display(Math(str(expression).replace('**','^').replace('*','')))
    print 'Multiply ALL the monomials:'
    factor=re.split('\)\s*\*\s*\(',str(expression))
    refactor=[ re.split('\(|\)',factor[i])[1-i] for i in range(len(factor))]
    terms=[ re.split(':',re.sub('\s*(\+|\-)\s*',r':\1',refactor[i])) for i in range(len(refactor)) ]
    expandednr=''
    for i in terms[0]:
        for j in terms[1]:
            if i and j: #mo empty strings
                print '(%s)*(%s)' %(i,j)
                newterm=raw_input()
                if re.search('^-',newterm):
                    newterm=newterm
                else:
                    newterm='+'+newterm
                expandednr=expandednr+newterm
                expandednr=re.sub('^\+','',expandednr)
    print 'Reduce the expression:' 
    display(Math(expandednr.replace('**','^').replace('*','')))
    result=raw_input()
    if evexpr== eval(result): 
        print "Good job!, final result:"
        return eval(result)
        
    else:
        print('WRONG!!!\nRight result:')
        return sym.expand(expression)
           
开发者ID:simonres,项目名称:algebra,代码行数:36,代码来源:polymult.py


示例20: __init__

 def __init__(self, coordinates, metric):
     sp.init_printing()
     if len(coordinates)==metric.rows and len(coordinates)==metric.cols:
         self.gdd = metric #stands for down-down components of the metric g
         self.x = coordinates
         self.dim = len(self.x)
         self.index = range(self.dim)
         self.guu = metric.inv()
         
         self.connection = [[[0 for i in self.index] for i in self.index] for i in self.index]
         for i in self.index:
             for j in self.index:
                 for k in self.index:
                     for m in self.index:
                         self.connection[i][j][k] += self.guu[i,m]*(self.gdd[m,j].diff(self.x[k]) + self.gdd[m,k].diff(self.x[j]) - self.gdd[k,j].diff(self.x[m]))/2
         self.Riemanntensor = [[[[0for i in self.index]for i in self.index]for i in self.index]for i in self.index]
         for i in self.index:
             for j in self.index:
                 for k in self.index:
                     for m in self.index:
                         self.Riemanntensor[i][j][k][m] +=  self.connection[i][j][k].diff(self.x[m]) - self.connection[i][j][m].diff(self.x[k])
                         for n in self.index:
                             self.Riemanntensor[i][j][k][m] += self.connection[n][j][k]*self.connection[i][m][n] - self.connection[n][j][m]*self.connection[i][k][n]
         
         self.Riccitensor = [[0 for i in self.index]for i in self.index]
         for i in self.index:
             for j in self.index:
                 for k in self.index:
                     self.Riccitensor[i][j] += self.Riemanntensor[k][i][k][j]
                     
         self.Riemannscalar = 0 
         for i in self.index:
             for j in self.index:
                 self.Riemannscalar += self.guu[i,j]*self.Riccitensor[i][j]           
     else:
         print "Creation failed. Please use an n-tuple of coordinate names with a square, n times n matrix"
开发者ID:LeoVanNierop,项目名称:RiemannCurvatureSympy,代码行数:36,代码来源:geometry.py



注:本文中的sympy.init_printing函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sympy.integrate函数代码示例发布时间:2022-05-27
下一篇:
Python sympy.imageset函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap