sympy

How can I use sympy sum over elements of a list in python?

How can I use sympy sum over elements of a list in python? Question: I am just trying to use a sympy sum over a list of elements, for example: x = [1,2,3,4,5] expression = sympy.sum(x[i], (i,0,2)) * sympy.sum(x[j], (j,1,3)) and I just want it to numerically evaluate this. I always get index out of …

Total answers: 1

How to stop matplotlib from incorrectly adding lines at vertical asymptotes?

How to stop matplotlib from incorrectly adding lines at vertical asymptotes? Question: For functions that contain vertical asymptotes, y^2 = x^3/(2(3) – x) for example, matplotlib will add in vertical lines at the asymptotes which majorly throws off the expected graph. I am using plot_implicit() from sympy. I have tried setting the adaptive attribute to …

Total answers: 1

Logarithms in sympy

Logarithms in sympy Question: Please tell me how you can change log(e) to 1. And in general is there a way in sympy to get a float-type answer? For example, instead of log(2), get 0.69314718056 from math import * from sympy import * x1=symbols(‘x1’) x2=symbols(‘x2’) Func = e**(2*x1)*(x1+x2**2+2*x2) print(Func.diff(x2)) Here I already get log(e). In …

Total answers: 1

Plotting an equation with constraints using sympy

Plotting an equation with constraints using sympy Question: I’m currently working on a project that requires plotting and equation with constraints like: sin(x) for x > 1. but can get more complicated than this like: 3z * cos(x) for x >= 0 and x + z = 1 I managed to take the input as …

Total answers: 1

"Literal replace" in SymPy

"Literal replace" in SymPy Question: Is there a way to perform a "literal replacing" in SymPy, which matches exactly the pattern? For example, for the expression exp(I*theta)+exp(-I*theta), I would like to replace only exp(It) to zero without replacing exp(-It) A minimal example would be from sympy import * f=exp(I*t)+exp(-I*t) Clearly, subs will not work f.subs((exp(I*t),0)) …

Total answers: 2

Solving an eigenvalue probem for a hermitian matrix with Sympy

Solving an eigenvalue probem for a hermitian matrix with Sympy Question: I’m trying to find the eigenvalues of a Hermitian matrix using Sympy. We know from the linear algebra that the eigenvalues should be real, but the output of Sympy always contains infinitesimal imaginary part. I know this might not look a serious problem at …

Total answers: 1

Making sympy function with 2 variables

Making sympy function with 2 variables Question: I´m trying to do a piecewise function with sympy, but I can´t. It doesn´t the piecewise function. I want a simple funtion when (x,y) != (0,0) and a when (x,y) = (0,0) Can someone help me ? Thank you so much I tried this code: f_exp = sp.Piecewise((((x*y)*(x**2 …

Total answers: 1