I am working on a math project.I need a programming language that allows me to evaluate users input. Like Multiplying 2 complex numbers: I can't use a regular expression since there are many possibilities( I want to include all the steps of calculation.)
Asked
Active
Viewed 310 times
-8
-
5What's your question? – Reinstate Monica -- notmaynard Mar 22 '13 at 18:28
-
The set of complex numbers (with i being an imaginary number. ) – neo Mar 22 '13 at 18:30
-
Update your question with example and what you have tried ... – Baba Mar 22 '13 at 18:31
-
Whoever retagged this: not `calculus`. Maybe `math`. – Reinstate Monica -- notmaynard Mar 22 '13 at 18:31
-
"A regular expression"? What didn't work about it? What language are you using? Did you try a different regular expression? Have you written any other code aside from a regular expression? Having "read the question carefully" it says you "can't use a regular expression," not that you've actually tried it. – Reinstate Monica -- notmaynard Mar 22 '13 at 18:33
-
What is the question you are trying to ask? – gordonk Mar 22 '13 at 18:37
-
think about it like this: (2X +2Y) *(3X+4Y)=.... now here is the complicated step since the user can start multiplying any 2 values together which is always true – neo Mar 22 '13 at 18:37
-
Are you having problems parsing or problems calculating? – gordonk Mar 22 '13 at 18:38
-
Read the previous comment – neo Mar 22 '13 at 18:47
1 Answers
1
You could use Scheme, it's a nice Lisp-like language that has built-in support for complex numbers. Also, since in Scheme data is code, it is really easy to turn user input into executable code.
Chicken Scheme is a popular variant.
Other popular languages with built-in complex number support are:
- R: use
i
as suffix for imaginary numbers.(1+2i)^2
returns-3+4j
. - Python: use
j
as a suffix for imaginary numbers.(1+2j)**2
returns(-3+4j)
. - Ruby: use the
Complex
class. - C: include
complex.h
and useI
as the imaginary unit. See also How to work with complex numbers in C?