sympy

No Sympy two-sided limits?

a 夏天 提交于 2019-12-24 05:45:06
问题 I can't get Sympy to handle two-sided limits. Running in a Jupyter notebook, Anaconda installation: from sympy import * x = symbols('x') limit(1/x,x,0) gives an answer of oo . Furthermore, Limit(1/x,x,0) prints as a right-sided limit. In fact, all of my two-sided limits 'pretty-print' as right-sided limits. They seem to be evaluated that way, too. Can't find a way to force two-sided. Of course, one could write a short program to remedy this. What am I doing wrong? 回答1: limit has a fourth

Summing factorials in Python

谁说我不能喝 提交于 2019-12-24 05:32:51
问题 I would like to compute sums with factorials using symbolic algebra in python. The simplest version of the problem I can generate is the following one: from sympy.abc import j from math import factorial from sympy import summation summation(factorial(j), (j, 1, 4)) And I get the following error: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "sympy/core/expr.py", line 194, in __int__ r = self.round(2) File "sympy/core/expr.py", line 3042, in round raise TypeError(

Sympy Simplify eliminate imaginary numbers

帅比萌擦擦* 提交于 2019-12-24 05:31:36
问题 I'm trying to get the cosine similarity between convolved vectors. Because I'm using fast fourier transform, I am using complex numbers. In the calculation of the cosine similarity, the final value returned should be a real number. However, my output is including imaginary parts: 1.0*(-1.53283653303955 + 6.08703605256546e-17*I)/(sqrt(5.69974497311137 + 5.55111512312578e-17*I)*sqrt(14.2393958011541 - 3.46944695195361e-18*I)) The imaginary portions should be zero (which they effectively are),

How to set up sympy to perform standard differential geometry tasks?

两盒软妹~` 提交于 2019-12-24 05:12:16
问题 I'm an engineering student. Pretty much all math I have to do is something in R2 or R3 and concerns differential geometry. Naturally I really like sympy because it makes my calculations reusable and presentable. What I found: The thing in sympy that comes closeset to what I know functions as, which is as mapping of scalar or vector values to scalar or vector values, with a name and connected to an expressions seems to be something of the form functionname=sympy.Lambda(Variables in tuple,

Construct a symbolic interpolating spline through given points using SymPy

筅森魡賤 提交于 2019-12-24 02:47:32
问题 Pretend I start with some simple dataset which is defined on R2 follows: DataPointsDomain = [0,1,2,3,4,5] DataPointsRange = [3,6,5,7,9,1] With scipy I can make a lazy polynomial spline using the following: ScipySplineObject = scipy.interpolate.InterpolatedUnivariateSpline( DataPointsDomain, DataPointsRange, k = 1, ) What is the equivalent object in sympy?? SympySplineObject = ...??? (I want to define this object and do analytic sympy manipulation like taking integrals, derivatives, etc... on

How do I get sympy to simplify an expression containing sqrt(2)/2?

空扰寡人 提交于 2019-12-24 00:35:02
问题 This code: from sympy import * x = Symbol('x', positive=True) vp = Symbol('vp', positive=True) num = integrate( (vp*sin(x))**2, (x, 0, 2*pi)) den = integrate( 1 , (x, 0, 2*pi)) print " num =",num print " den =",den vrms = sqrt(num/den) print "vrms =",vrms print "simplified vrms = ",simplify(vrms) Returns this: num = pi*vp**2 den = 2*pi vrms = sqrt(2)*vp/2 simplified vrms = sqrt(2)*vp/2 How can I get it to take the last step? I'd like it return this: vrms = vp/sqrt(2) 回答1: SymPy automatically

Sympy and plotting

梦想与她 提交于 2019-12-23 23:30:16
问题 I have a few questions about what how to work with graphics, using Sympy. My code: from sympy import * x, y = symbols("x y") plot_implicit(Eq(x**2 + y**2, 4), (x, -3, 3), (y, -3, 3)) 1) The graph is obtained stretched along the x axis. How to make so that the curve looked like a circle? 2) How to add other elements to the chart. For example, the point O(0, 0) and the line y = x. 回答1: According to the docstring of plot.py, you can get the backend wrapper of the Matplotlib axes and figure that

Long expression crashes SymPy

廉价感情. 提交于 2019-12-23 20:28:07
问题 I'm using 64-bit Python 3.3.1, pylab and 32GB system RAM. This function: def sqrt2Expansion(limit): x = Symbol('x') term = 1+1/x for _ in range(limit): term = term.subs({x: (2+1/x)}) return term.subs({x: 2}) Produces expressions of this kind: 1 + 1/(2 + 1/(2 + 1/(2 + 1/(2 + 1/(2 + 1/(...)))))) . When called as: sqrt2Expansion(100) returns valid result, but sqrt2Expansion(200) produces RuntimeError with many pages of traceback and hangs up pylab/IPython interpreter with plenty of system memory

Difference between eye and Identity in SymPy

一世执手 提交于 2019-12-23 20:07:35
问题 In SymPy, what is the difference between eye(5) and Identity(5) ? If I have a matrix X , I see that X + eye(5) and X + Identity(5) give different results (the latter is not a matrix). 回答1: SymPy distinguishes between explicit matrices , which have certain size, like 3 by 3, and explicit (possibly symbolic) entries; matrix expressions , which may have symbolic size, like n by n. eye creates a matrix, Identity creates a matrix expression. For example: n = Symbol("n") A = Identity(n) # works A =

Expression simplification in SymPy

余生颓废 提交于 2019-12-23 19:10:05
问题 I want to achieve this kind of simplification: e+ac+ad+bc+bd = e+(a+b)(c+d) . None of SymPy simplification functions worked this way. Is there any other method in SymPy or somewhere else in python to get this kind of simplification? 回答1: You can use collect(expr, e, func=factor) . In [5]: expr = e + a*c + a*d + b*c + b*d In [6]: collect(expr, e, func=factor) Out[6]: e + (a + b)⋅(c + d) 来源: https://stackoverflow.com/questions/40620585/expression-simplification-in-sympy