sympy

Mathematical Equations - Rendering and Evaluation with Python and QT (and sympy?)

你离开我真会死。 提交于 2019-12-14 02:06:43
问题 I am developing a GUI application (in the civil engineering context) with python3 and QT and want to display an equation in three different ways: symbolic: sigma=N/A with values: sigma=200kN/20cm² as a result: sigma=10kN/cm² The layout of the equation and the order of symbols has to be the same for both (1) and (2), but i only want to enter the equation once in my sourcecode. I searched a lot, this is the best i could get: class myfancy_equation(): def __init__(self): self.a = Symbol('a')

NotImplementedError in Sympy's solve

折月煮酒 提交于 2019-12-14 01:36:51
问题 I'm reading an article about Bloom filters, https://en.wikipedia.org/wiki/Bloom_filter, in which an expression is derived for the optimal number of hash functions. I'd like to reproduce the computation for the simplified case that m = n , that is, I'd like to determine the minimum of the function (1-exp(-x))**x which, from the article, should occur at x = ln(2) . I tried doing this with sympy as follows: In [1]: from sympy import * In [2]: x, y, z = symbols('x y z') In [3]: init_printing(use

map each element to expression

眉间皱痕 提交于 2019-12-14 01:28:10
问题 I have this code: import sympy import numpy as np from sympy.utilities.lambdify import lambdify from collections import OrderedDict arr = [np.array([ 1, 2]), np.array([ 5, 6])] a,b = sympy.symbols('a b') var = [a,b] expr = ['a+cos(b)', 'a+cos(b)*2'] f = lambdify( var, expr, 'numpy') vals = OrderedDict(zip(var, arr)).values() f(*vals) and I am receiving: [array([ 1.28366219, 2.96017029]), array([ 1.56732437, 3.92034057])] I want to receive: [array([ 1.28366219, 3.92034057])] hence : 1+np.cos(5

Using sympy's latex() function without calculating the input

不问归期 提交于 2019-12-14 00:26:43
问题 I want to get latex output from a sympy expression without calculating the expression. For instance if I do latex((2+3)/7) the output would be 5/7 (with latex), but what I am after is for it to just output (2+3)/7 with latex. Like this: \frac{2+3}{7} 回答1: You can manually adjust the long_frac_ratio long_frac_ratio: The allowed ratio of the width of the numerator to the width of the denominator before we start breaking off long fractions. The default value is 2. >>> latex(e,long_frac_ratio=3)

Using SymPy's New Assumptions

杀马特。学长 韩版系。学妹 提交于 2019-12-13 19:33:21
问题 I'm having some issues with SymPy's current assumptions. Look at this thread. One of the hints said to use the assume module (reference here). I tried doing the following computation $\lim_{x \to \infty} \frac{\ln{x}}{x^k}$. I want to evaluate this limit for $k >0$. So I tried this: with assuming(k>0): limit((log(x))/(x**k),x,oo) I also tried this: eval(limit((log(x))/(x**k),x,oo),k>0) But regardless, I get this error: NotImplementedError: Result depends on the sign of -sign(k) In the case of

Complex numbers: convert SymPy to numeric (I to 1j)

吃可爱长大的小学妹 提交于 2019-12-13 17:22:03
问题 using symbolic calculation in Python I have import sympy from cmath import * from mpmath import arg, cplot z = sympy.symbols('z') fhandle='z**2' g = lambda w: sympy.sympify(fhandle).evalf(subs={z: w}) g(1+2j) # Returns: -3.0 + 4.0*I # hence the next command fails, because I is expected to be 1j cplot(g, [-3,3], [-3,3]) Crawling the web I only found this which will fix the matter for the print command, but will not work with cplot. Any suggestions? 回答1: One option is to wrap the result by

SymPy — define domain of variable

家住魔仙堡 提交于 2019-12-13 15:35:09
问题 I'm writing a program to compute an exact differential for my physics laboratory. I know that I can set real domain or positive ( from sympy import * ): x, y, z = symbol('x y z', positive = True) My problem is to specify domain for example n>1 . Is it possible? In my output I'm getting an expresion like |n^2-1| and with setting this domain n>1 I would accept output like n^2-1 (without absolute value "||") 回答1: For assumptions on symbols, you can use positive or negative : p = Symbol('p',

Diagonalize symbolic matrix

丶灬走出姿态 提交于 2019-12-13 13:25:45
问题 I need to diagonalize a symbolic matrix with python. In Mathematica it can be done easily, but when using the module numpy.linalg I get problems. For concreteness, consider the matrix [[2, x], [x, 3]] where x is a symbolic variable. I guess I get problems because the numpy package is provided for numerical computations, not symbolic, but I cannot find how to do it with sympy. 回答1: You can compute it from the eigenvalues, but there is actually a method that will do it for you, diagonalize In

Julia changing name in loop, using symbolic variables

故事扮演 提交于 2019-12-13 13:13:48
问题 I'd like to change the name of a symbolic variable in each iteration of a loop, and then solve an equation using these symbolic variables e.g: using SymPy for i in 1:5 p{i} = symbols("p"{i}, real=true,positive=true) solve(p{i}^2-i^2) end So I'm looking to create a series of scalar symbolic variables (since I don't think it is possible to create a vector valued symbolic variable) each with a different name - p1,p2,p3,p4 and p5 - and then use these in a equation solver. However the curly braces

Rewrite equation as polynomial

淺唱寂寞╮ 提交于 2019-12-13 06:35:36
问题 from sympy import * K, T, s = symbols('K T s') G = K/(1+s*T) Eq1 =Eq(G+1,0) I want to rewrite equation Eq1 with sympy as polynomial: 1+K+T*s==0 How would I do this? I spent some hours of searching and trying simplifications methods but could not find a elegant, short solution. The actual problem in SymPy: from IPython.display import display import sympy as sp sp.init_printing(use_unicode=True,use_latex=True,euler=True) Kf,Td0s,Ke,Te,Tv,Kv,s= sp.symbols("K_f,T_d0^',K_e,T_e,T_v,K_v,s") Ga= Kf/