Post Reply 
INPUT() and complex numbers?
01-14-2015, 01:47 PM
Post: #1
INPUT() and complex numbers?
How can complex numbers be used with INPUT()?

Simple example:

INPUT(zl); // Using zl=50+25i as input value
zo:=50;

RE(zl)=>50, IM(zl)=>25.
(zl-zo)/(zl+zo) => 0.06 +0.24*i

I haven't been able to get complex numbers to work with an INPUT().
Find all posts by this user
Quote this message in a reply
01-14-2015, 04:44 PM (This post was last modified: 01-14-2015 05:13 PM by DrD.)
Post: #2
RE: INPUT() and complex numbers?
I think I may have discovered a way to input a complex number:

1. Predefine a variable as a complex number: zl:=0+0i;
2. Execute the INPUT() function on it: INPUT(zl); // <== 50+25i, returns 1.00
3. Now EVAL the variable: EVAL(zl); ==> 50.00+25.00*i

EVAL((zo-50)/(zo+50)) ==> 0.06+0.24*i


Predefining zl:=0+0i worked when entered in the HOME command line, but results in a syntax error when zl:=0+0i; is entered in a ppl program.


-Dale-
Find all posts by this user
Quote this message in a reply
01-14-2015, 08:21 PM
Post: #3
RE: INPUT() and complex numbers?
(01-14-2015 04:44 PM)DrD Wrote:  [...]
Predefining zl:=0+0i worked when entered in the HOME command line, but results in a syntax error when zl:=0+0i; is entered in a ppl program.
Enter it as zl:=0+0*i or zl:=(0,0).
Find all posts by this user
Quote this message in a reply
01-14-2015, 09:49 PM
Post: #4
RE: INPUT() and complex numbers?
Snorre, your suggested forms, as well as (0,0i) and (0,0*i), are syntax issues as well. Z0-Z9 are reserved for complex variables, but Z0:=50+25i; (and all the complex entry variants tried so far), also error out. Maybe it just isn't possible to assign complex numbers to variables in a program. That it works fine when entered in the HOME command line, would suggest it would also work programmatically in the same way.

Currently, I've isolated a code fragment of my program to just deal with complex number entry, but so far, no luck. My main program deals with impedance and related parameters, where complex numbers are the norm. Maybe the Re(zl) and IM(zl) components can only be handled in stand alone fashion, within programs.

Currently, my settings are HOME: Complex a+b*i, allow complex output from real input checked, CAS: Complex checked (Include complex results in variables), and Symbolic Setup: Complex (system). I have tried to accomplish zl:=50+25i; using each of the entry methods discussed, including your suggestions, and no go.

I have tried many other settings, as well. In fact, I don't think there is any combination left that I haven't tried, so complex number assignment to a variable in a program is, at this point, myth "busted." (EMU ver 6975).

-Dale-
Find all posts by this user
Quote this message in a reply
01-14-2015, 10:27 PM (This post was last modified: 01-14-2015 10:39 PM by Snorre.)
Post: #5
RE: INPUT() and complex numbers?
Hello DrD,

in PPL implicit multiplication is not valid syntax, so anything like 0i or 0i won't compile. Something like (a,b*i) is not forbidden, but actually means a+b*i*i = a-b (a real).

I've tried on my device:
Code:
BEGIN
  LOCAL a:=1+2*i,  // lower case letter i ([Alpha]+[Shift]+[TAN])
        b:=3+4*i,  // imaginary unit i ([Shift]+[2])
        c:=(5,6),
        d:=7+8*√-1;
  INPUT({a,b,c,d});
  {EVAL(a),EVAL(b),EVAL(c),EVAL(d)};
END;
and didn't observe any problems, regardless of current complex format setting.
The CAS setting "Complex" is not related to PPL.

Please doublecheck there aren't any typos in your program. If you still cannot assign complex numbers then there's something very strange happening on your device. (Maybe a reset is required?)
What is your software version (mine is 6975), your "Digit Grouping" setting (mine is "123456.789")?

Greetings
Find all posts by this user
Quote this message in a reply
01-14-2015, 10:33 PM (This post was last modified: 01-14-2015 10:41 PM by Helge Gabert.)
Post: #6
RE: INPUT() and complex numbers?
Predefining the complex variable in a LOCAL statement works for me.

...
LOCAL xl:=2+2*i;
...
INPUT(xl);
<User enters a complex number>
...

OK

Edit: But complex numbers inside an array, if predefined, don't seem to work with input . I get "error: insufficient memory."
Find all posts by this user
Quote this message in a reply
01-14-2015, 11:05 PM
Post: #7
RE: INPUT() and complex numbers?
Thank you! Predefining the complex variable completely within the local declaration did the trick, and worked for me, as well:

Code:

EXPORT test()
BEGIN
local zl:=50+25*i,            
       zo:=50+0*i;

input(zl,zo);
g:=eval((zl-zo)/(zl+zo));
return g; 

END;

This produces the 0.06+0.24*i result I was after, and I can now continue with the rest of my program. You have been very helpful, and I sure hope I can return the favor soon!

-Dale-
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)