I want to transform a C-string to complex expression and simplify it.
For example for the string:
(3+2i)² + 6-i-3+2i
output should be: 8+13i
;
Python adopted the convention used by electrical engineers. In that field, i is used to represent current and use j as the square root of -1.
In Python, there is a built-in round() function that rounds off a number to the given number of digits. The function round() accepts two numeric arguments, n, and n digits, and then returns the number n after rounding it to n digits.
An complex number is represented by “ x + yi “. Python converts the real numbers x and y into complex using the function complex(x,y). The real part can be accessed using the function real() and imaginary part can be represented by imag().
Parsing is the process of analysing a string of symbols, expressed in natural or computer languages that will accord formal grammar. Expression Parsing in Data Structure means the evaluation of arithmetic and logical expressions.
You need a library that can parse mathematical expressions. Either write your own or take one of the existing ones (like ExprTk).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With