sympy

Need sympy function for log2(x) capable of being used in sympy.solve

笑着哭i 提交于 2020-03-03 06:15:11
问题 I need to accept user input in the form of a string, parse it into a sympy expression, and then solve for a variable. Most of the user's allowed functions match sympy functions except for log2(x) which is equivalent to sympy's log(x, 2). I've tried the method of defining a python function that returns the sympy function as mentioned here. I've also tried using defining a sympy function using lambda. Both methods work for getting the value of the expression after substituting variables for

Putting together plots of Matplotlib and Sympy

爱⌒轻易说出口 提交于 2020-02-25 05:16:13
问题 I would like to know how to put the following plots together in a same figure: import matplotlib.pyplot as plt from sympy.plotting.plot import plot_parametric from sympy import * from sympy.abc import x,y,z p1 = plt.arrow(0,0,0.5,0.5,head_width = 0.05, head_length=0.05,length_includes_head=True) p2 = plot_parametric(cos(x),sin(x),(x,0,2*pi)) It might be helpful to know that it is possible to access to the axes and figure of plots of Sympy by fig = p2._backend.fig ax = p2._backend.ax Any help

Putting together plots of Matplotlib and Sympy

旧街凉风 提交于 2020-02-25 05:16:08
问题 I would like to know how to put the following plots together in a same figure: import matplotlib.pyplot as plt from sympy.plotting.plot import plot_parametric from sympy import * from sympy.abc import x,y,z p1 = plt.arrow(0,0,0.5,0.5,head_width = 0.05, head_length=0.05,length_includes_head=True) p2 = plot_parametric(cos(x),sin(x),(x,0,2*pi)) It might be helpful to know that it is possible to access to the axes and figure of plots of Sympy by fig = p2._backend.fig ax = p2._backend.ax Any help

KeyError while perfoming solve of two equation

自闭症网瘾萝莉.ら 提交于 2020-02-08 10:01:07
问题 1st i need to get two equation of two longest line length i put lenghths with eq in list like these [( length 1 , eq 1 ) ,.....] sort list with reverse get two equation of two longest line when run the below code from sympy import * import math class shape(): def __init__(self,T): self.T=T self.Ax = self.T[0][0] self.Ay = self.T[0][1] self.Bx = self.T[1][0] self.By = self.T[1][1] self.Cx = self.T[2][0] self.Cy = self.T[2][1] #Triangle: self.C_dashx = 0.5 * (self.Ax + self.Bx) self.C_dashy = 0

Create an unknown number of programmatically defined variables

半腔热情 提交于 2020-02-05 05:44:05
问题 I have a recursive function that can produce a difficult-to-know number of expressions, each needing a new variable multiplied to it. These variables will later be removed out by calculations involving integration or residue. How can I develop these unknown number of variables? Maybe indexed? All examples I've seen on the internet are working with an a priori known object of a definite size, e.g. "item" in How can you dynamically create variables via a while loop? or Accessing the index in

How to pretty print in ipython notebook via sympy?

北慕城南 提交于 2020-01-25 10:12:09
问题 I tried pprint , print , the former only prints Unicode version, and the latter doesn't do pretty prints. from sympy import symbols, Function import sympy.functions as sym from sympy import init_printing init_printing(use_latex=True) from sympy import pprint from sympy import Symbol x = Symbol('x') # If a cell contains only the following, it will render perfectly. (pi + x)**2 # However I would like to control what to print in a function, # so that multiple expressions can be printed from a

How to define variable values using user input

只愿长相守 提交于 2020-01-25 08:39:16
问题 I have come across an issue I don't quite know how to solve. I'm trying to use solver to solve a simple equation. However, I want it so that you can solve for any variable you want, and give any value for the other constants that you want. from sympy import * a, b, c, d=symbols('a b c d') constants=[] input1=list(input('input variables for a,b,c,and d')) for value in input1: try: int_values=int(value) constants.append(int_values) except: solve_for=value equation=solveset(a + (b-1) * c-d,

How to pass sympy expressions to be used with scipy?

ⅰ亾dé卋堺 提交于 2020-01-25 06:53:09
问题 I want to solve a systen of non-linear equations created by loops using root from scipy.optimize . I want to create the equations with one method and then solve them with another. I created the equations with sympy and want to solve them with scipy. My real code has too many loops and every time root from scipy iterates those loops. This is a very simplified version of what I tried. I made the equations with sympy symbols and then I used lambdify to take the equations out of sympy but the

Error using 'exp' in sympy -TypeError and Attribute Error is displayed

假如想象 提交于 2020-01-24 19:47:26
问题 I want solve differential equation using sympy on Python3. My equation is relatively simple with two variables. However, the equation has log, power, and exp operators. Whether I use np.exp or sym.exp, it gives me one of the two errors below: TypeError: 'module' object is not callable AttributeError: 'Mul' object has no attribute 'log' AttributeError: 'Mul' object has no attribute 'exp' I am importing numpy and sympy separately. I am not sure if these two libraries are conflicting. import