# "Literal replace" in SymPy

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)) because it also replaces exp(-I*t)… Read More "Literal replace" in SymPy

# How to tell sympy to simplify or change between minimums and absolute values?

For example, how can we make this simplify to zero (or show me where I’ve made a dumb mistake and then it just works) import sympy sympy.var(‘s t’, real=True) (s – 2 * sympy.Min(s, t) – sympy.Abs(s – t)).simplify() # should be zero? I see evidence that sympy knows about these kind of relations but… Read More How to tell sympy to simplify or change between minimums and absolute values?

# Making sympy function with 2 variables

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 – y**2)) / (x**2 + y**2), (x,y)… Read More Making sympy function with 2 variables

# Sympy not simplifying polygamma

I have a python script that finds the derivative of a function, within which is the gamma function. When substituting values in, instead of finding the digamma of the values and returning it as a float, sympy only returns polygamma (0, 1.05) or whatever the output is. Below is my code: import mpmath import time… Read More Sympy not simplifying polygamma

# How to get a decimal instead of a fraction in sympy?

I am making a chemistry project for school, I want to use sympy for solving some density and concentration problems. solveset function returns the value as a fraction, for example: mL = Symbol("mL") density = Symbol("p") mass = 115*g volume = 100*ml print(solveset(Eq(density, mass/volume), density)) The output is {23*g/(20*mL)} (fraction) but I want it in… Read More How to get a decimal instead of a fraction in sympy?

# How could I solve the error of putting a string in the sympy set solver with an input?

So I’m trying to create this program where it takes an input (for example x+2=5) and sympy solves that equation. However since I believe that "=" sign will cause an error I tried to cut it out from the input but with this I’m finding my self inputting a string type in the simpy solver.… Read More How could I solve the error of putting a string in the sympy set solver with an input?

# Why is my function plotting incorrectly when using sympy.plotting.plot?

I am using sympy.plotting.plot to plot my function but, it shows me a different graph then when I plot the same function in my graphic calculator. My code is: def S(t): return (10*sympy.E**(t/12)*((sympy.sin((sympy.pi*t)/24))**2)) sympy.plotting.plot(S(t), xlim=[0,24]) Also, when I just do this, sympy.plotting.plot(10*sympy.E**(t/12)*((sympy.sin((sympy.pi*t)/24))**2), xlim=[0,24]) it shows a different graph. In my calculator the function has a… Read More Why is my function plotting incorrectly when using sympy.plotting.plot?

# Sympy not finding a solution to equation, would numpy work?

I’m trying to build a system for simulating sliding done arbitrary slopes, but it requires that I find the intersection of half a circle and an arbitrary function. However, when I use sympy, it does find a solution despite one clearly existing. Is there a numerical approach I could take to this in NumPy? See… Read More Sympy not finding a solution to equation, would numpy work?

# Sympy multiply `MatrixSymbol` with `Matrix` with known and fixed sizes

I am trying to multiply a MatrixSymbol and Matrix and access the value inside it’s multiplication a = MatrixSymbol(‘a’, 1, 4) l = Matrix([1,2,3,4]) print((a*l)[0]) This error IndexError: Single indexing is only supported when the number of columns is known. I would like to access the inner multiplication a[0][0]*1 + a[0][1]*2…. >Solution : Maybe what… Read More Sympy multiply `MatrixSymbol` with `Matrix` with known and fixed sizes

# Collect coefficients of non-square matrix in sympy

Given three vectors, a(1,4), b(1, 4), c(4,1). I want to do the following a = MatrixSymbol(‘a’, 1, 4) b = MatrixSymbol(‘a’, 1, 4) c = MatrixSymbol(‘c’, 4, 1) expr = a*c + b*c c_coeff = …. # How to get the value of (a+b) here I tried using coeff and collect but it fails because… Read More Collect coefficients of non-square matrix in sympy