Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing expression with complex numbes [closed]

Tags:

c++

char

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;

like image 260
Stelian B. Avatar asked Oct 20 '13 08:10

Stelian B.


People also ask

Why does Python use j instead of i for complex numbers?

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.

How do you round off complex numbers in Python?

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.

How do you take a real part of a complex number in Python?

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().

What is parsing an expression?

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.


1 Answers

You need a library that can parse mathematical expressions. Either write your own or take one of the existing ones (like ExprTk).

like image 124
Oswald Avatar answered Sep 23 '22 16:09

Oswald