当前位置: 首页>>代码示例>>Python>>正文


Python sympy.init_printing函数代码示例

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


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


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