sympy

Want to do multi-variation minimize with sympy

Deadly 提交于 2019-12-01 03:04:15
问题 I want to use minimization with scipy.optimize using Symbolized charactors from scipy.optimize import minimize from sympy.utilities.lambdify import lambdify import sympy as sp x1, x2, x3, x4 = sp.symbols('x1 x2 x3 x4') FormulaMain = sp.symbols('-2*x1**2*x3+6*x1**2*x4+13*x1**2-3*x1*x2**2+x1*x2+3*x1*x3**2-3*x4+103') HandleMain = lambdify((x1,x2,x3,x4),FormulaMain,'numpy') bnds = ((-1, 1), (-1, 1), (-1, 1), (-1, 1)) PrintParams = minimize(HandleMain,[1,1,1,1],method='SLSQP',bounds=bnds) print

Factoring polys in sympy

我的未来我决定 提交于 2019-12-01 02:27:29
问题 I'm doing a very simple probability calculations of getting subset of X, Y, Z from set of A-Z (with corresponding probabilities x, y, z). And because of very heavy formulas, in order to handle them, I'm trying to simplify (or collect or factor - I dont know the exact definition) these polynomial expressions using sympy . So.. having this (a very simple probability calculation expression of getting subset of X,Y,Z from set of A-Z with corresponding probabilities x, y, z) import sympy as sp x,

SymPy/SciPy: solving a system of ordinary differential equations with different variables

限于喜欢 提交于 2019-12-01 02:24:34
问题 I am new to SymPy and Python in general, and I am currently working with Python 2.7 and SymPy 0.7.5 with the objective to: a) read a system of differential equations from a text file b) solve the system I already read this question and this other question, and they are almost what I am looking for, but I have an additional issue: I do not know in advance the form of the system of equations, so I cannot create the corresponding function using def inside the script, as in this example. The

How to substitute symbol for matrix using symPy and numPy

孤街醉人 提交于 2019-12-01 02:19:35
问题 I'm trying to substitute two symbols in my equation for the matrix form of each of them. I created a commutator function which formed my expression: t, vS, = sy.symbols('t, vS', commutative = False) hS = t + vS eta = myComm(t,hS) dHs = myComm(eta,hS) print dHs.expand() yielding the correct expression I want: 2*t*vS*t + t*vS**2 - t**2*vS - 2*vS*t*vS - vS*t**2 + vS**2*t So now I wish to substitute the symbols t and vS with matrices, however when using subs I get an error, "unhashable type:

Multivariate Taylor approximation in sympy

倖福魔咒の 提交于 2019-12-01 02:00:44
问题 I aim to write a multidimensional Taylor approximation using sympy , which uses as many builtin code as possible, computes the truncated Taylor approximation of a given function of two variables returns the result without the Big-O-remainder term, as e.g. in sin(x)=x - x**3/6 + O(x**4) . Here is what I tryed so far: Approach 1 Naively, one could just combine the series command twice for each variable, which unfortunately does not work, as this example shows for the function sin(x*cos(y)) : sp

How to create a Rician random variable?

扶醉桌前 提交于 2019-12-01 01:00:21
I'm trying to model a signal detection problem using Sympy, and need two random variables. One with a Rayleigh distribution to model noise, and one with a Rician distribution to model signal+noise. Sympy provides a Rayleigh distribution , but not a Rician-- or at least not one by that name. What's the best way of creating one? Does it exist under a different name? Is there a way to manipulate existing distributions into a Rician? Following advice from @asmeurer, I've implemented my own Rice distribution, like so: from sympy.stats.crv_types import rv from sympy.stats.crv import

Possible to add descriptions to symbols in sympy?

坚强是说给别人听的谎言 提交于 2019-12-01 00:48:02
问题 I seek a functionality in sympy that can provide descriptions to symbols when needed. This would be something along the lines of >>> x = symbols('x') >>> x.description.set('Distance (m)') >>> t = symbols('t') >>> t.description.set('Time (s)') >>> x.description() 'Distance (m)' >>> t.description() 'Time (s)' This would be useful because it would enable me to keep track of all my variables and know what physical quantities I am dealing with. Is something like this even remotely possible in

define numerical evaluation of a derivative of a sympy function

一笑奈何 提交于 2019-12-01 00:46:23
How can I define the numerical evaluation of a derivative of a function in sympy? I have some functions I can describe with splines for the function and it's derivative using scipy.interpolate. I want to manipulate some expressions with this function and then evaluate the expressions with the splines. I can use lambdify to make a sympy function evaluate numerically as a spline. But how can I define the derivative of a sympy function to evaluate numerically as a spline? E.g. import sympy as sp import numpy as np from scipy.interpolate import InterpolatedUnivariateSpline from sympy.ultilitis

define numerical evaluation of a derivative of a sympy function

旧时模样 提交于 2019-11-30 19:38:32
问题 How can I define the numerical evaluation of a derivative of a function in sympy? I have some functions I can describe with splines for the function and it's derivative using scipy.interpolate. I want to manipulate some expressions with this function and then evaluate the expressions with the splines. I can use lambdify to make a sympy function evaluate numerically as a spline. But how can I define the derivative of a sympy function to evaluate numerically as a spline? E.g. import sympy as sp

Get a value from solution set returned as finiteset by Sympy

泪湿孤枕 提交于 2019-11-30 17:24:14
I`m creating a script in Python Sympy library and trying to access the result returned by solveset() and linsolve() functions. My problem is that the object returned by these functions is of type finiteset and I want to select some results automaticaly to re-enter it in other equations. Any body could help me? An example: I create a list of equations with two unknown variables: >>> a1, a2 = symbols('a1, a2') >>> eq2_1 = Eq(-3*a1/10 - 3*a2/20 + 1/12) >>> eq2_2 = Eq(-3*a1/20 - 13*a2/105 + 1/20) >>> lista = [eq2_1,eq2_2] >>> str(lista) [-3*a1/10 - 3*a2/20 + 1/12, -3*a1/20 - 13*a2/105 + 1/20] Then