"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?

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 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