Please tell me how to break down the expression by using sympy with positive and negative.

Asked 2 years ago, Updated 2 years ago, 57 views

1+2*x-3*cos(x)
1st
Second +2*x
Third - 3*cos(x)
Could not find standard function.
Is it a regular expression method?Thank you for your cooperation.

python sympy

2022-09-30 21:29

1 Answers

SymPy normalizes the order of the sections, so I don't know if it suits my purpose, but how about this?

 from sympathy import cos
from sympy.abc import x,y

y = 1 + 2 * x - 3 * cos(x)
print(y)
print(y.args)

Results

2*x-3*cos(x)+1
(1,-3*cos(x), 2*x)

Alternatively, you can use y.as_terms() to obtain a section.


2022-09-30 21:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.