Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Complex number arithmetic in Tcl?

Is there an equivalent to the expr command which works for complex numbers (represented lists of two doubles)?

This library provides functions for complex number arithmetic, and this seems to be a useful utility to define the required cexpr function, but it doesn't work well.

E.g. it doesn't handle properly the brackets.

ParseExpressions::ParseExpr { (1) + ((2) + (3)) } { } 

returns

+ [+ 1 ((2)] (3)) 

while it should return

+ [+ 1 2] 3 

Also ParseExpressions::ParseExpr { {1 2} + {3 4} } {}

returns

+ 1 2 3 4 

while it should return

+ {1 2} {3 4} 

So basically I am asking for a robust version of this utility.

like image 319
Vahagn Avatar asked Feb 01 '12 14:02

Vahagn


People also ask

What is the arithmetic of complex numbers?

Technically, the only arithmetic operations that are defined on complex numbers are addition and multiplication. This means that both subtraction and division will, in some way, need to be defined in terms of these two operations.

How do you perform the arithmetic of complex numbers?

Answer: Following are the arithmetic rules for complex numbers, Addition: For addition of complex numbers, one can write (a + ib) + (c + id) = (a + c) + i(b + d). Subtraction: For subtraction of complex numbers, one can write (a + ib) – (c + id) = (a – c) + i(b – d).

Does TCL do math?

The Tcl command for doing math type operations is expr .


1 Answers

Why don't you try this: http://wiki.tcl.tk/11415 or something like this too: http://wiki.tcl.tk/13885

I hope these are easy to use alternatives for the mentioned utility.

like image 127
askmish Avatar answered Sep 28 '22 03:09

askmish