▼
Posts: 2,247
Threads: 200
Joined: Jun 2005
Hi All,
I am using an HP-71B with a MATH Pac module. This module supports the COMPLEX type. How can I declare a SUB subroutine to have a parameter with the COMPLEX type?
Thanks!
Namir
▼
Posts: 69
Threads: 6
Joined: Aug 2010
Here is one way:
Main Program
10 COMPLEX A ! declare type
20 A=-5
30 CALL TESTSUB(A) ! call and pass the variable
Sub Program
10 SUB TESTSUB(A) ! sub program with variable passed
20 DISP SQRT(A) ! take the sqrt of the negative number
you should get (0,2.2360679775)
Edited: 26 Nov 2010, 9:29 p.m.
▼
Posts: 2,247
Threads: 200
Joined: Jun 2005
Hi!
I am using the EMU71 (since I am away from home) and get the following value!
(0,5)
Matlab gives me your answer of 0 + 2.2361i.
Any explanation why I am getting (0,5) with EMU71?
Namir
Edited: 27 Nov 2010, 6:11 a.m.
▼
Posts: 69
Threads: 6
Joined: Aug 2010
That's odd, I just tried it on EMU71 and got the correct result.
▼
Posts: 1,619
Threads: 147
Joined: May 2006
▼
Posts: 2,247
Threads: 200
Joined: Jun 2005
When I type VER$ on my EMU71 I get:
HP71:2CDCC MATH:1A JPC:Ex HPIL:1B HELP:C FACTR:A STRU:A RCPY:E
The EMU71.INI file is:
; emu71.ini Emu71 initialisation file
;
[MODULES]
; 10 softwired modules max., plus 1 hardwired module
; main RAM in port 0 only
; port(1-5) type(ROM,RAM,HRD) size(Ko) file
0 RAM 32 ram00.bin
1 ROM 16 hpilrom.bin
2 ROM 16 mathrom.bin
3 ROM 32 jpcromx.bin
5 RAM 32 iram50.bin
;
[DEVICES]
DISPLAY
HDRIVE1
HDRIVE2
DOSLINK
LPRTER1
Maybe the above info helps?
Posts: 1,477
Threads: 71
Joined: Jan 2005
On a real 71b with Math ROM I can confirm that the answer is (0,2.236...).
▼
Posts: 2,247
Threads: 200
Joined: Jun 2005
Sounds like an emulator bug, given the INI configuration I am using. The good news is that the polynomial-root program I wrote (which heavily uses complex math and complex variables and arrays) works just fine!!
Edited: 27 Nov 2010, 4:24 p.m.
Posts: 1,792
Threads: 62
Joined: Jan 2005
Quote:
On a real 71b with Math ROM I can confirm that the answer is (0,2.236...).
I'll second Katie. I got the answer (0,2.2360679775) by modifying Jerry's program as follows and hitting "RUN" to execute:
10 COMPLEX A
20 A=(-5,0)
30 CALL TESTSUB(A)
40 SUB TESTSUB(A)
50 DISP SQRT(A)
ADDENDUM: The following program also works. It proves passage of the complex-valued variable, undeclared in the subroutine.
10 COMPLEX A
20 A=(-5,0)
30 CALL TESTSUB(A)
35 END
40 SUB TESTSUB(B)
50 DISP SQRT(B)
-- KS
Edited: 28 Nov 2010, 3:38 p.m. after one or more responses were posted
▼
Posts: 2,247
Threads: 200
Joined: Jun 2005
I typed you code, line for line, and got (0,5).
▼
Posts: 291
Threads: 63
Joined: Jan 1970
This Message was deleted. This empty message preserves the threading when a post with followup(s) is deleted. If all followups have been removed, the original poster may delete this post again to make this placeholder disappear.
▼
Posts: 2,247
Threads: 200
Joined: Jun 2005
i will certainly test the program with a real HP-71B and Math rom by the end of the week, when i am back home.
▼
Posts: 1,083
Threads: 126
Joined: Sep 2006
Both real versions of my HP71B with math roms give the correct answer:(0,2.236...)
Haven't tried the emulator yet.
Cheers,
HP71:2cdcc clk:ms hpil:1b math:1a
HP71:1bbbb clk:a hpil:1b math:1a
Edited: 28 Nov 2010, 5:31 p.m.
Posts: 2,247
Threads: 200
Joined: Jun 2005
My main goal was to write SUB routines that have parameters that are complex arrays and variables. The good news is that the approach you suggest WORKS!! It seems that with the MATH module, the HP-71B does not require a special syntax for COMPLEX parameters. When the arguments passed to the SUB routines are complex, the routine treats them as COMPLEX within its scope.
I was trying to implement the Aberth–Ehrlich method that simultaneously solves for all the roots (real and complex) of polynomials. The good news is that the implementation works!
Namir
Edited: 27 Nov 2010, 6:05 p.m.
▼
Posts: 69
Threads: 6
Joined: Aug 2010
I'm glad it works! Still it's odd I can't seem to duplicate your result of (0,5) on either of my computers with EMU71.
▼
Posts: 2,247
Threads: 200
Joined: Jun 2005
I am equally baffled about the result. The program I wrote does not use the SQRT, so I guess I am fine.
Posts: 2,247
Threads: 200
Joined: Jun 2005
I downloaded the latest version of EMU71 and ran the code. Same result. Also when I type SQR((-144,0)) I get (0,144). Also when I execute SQR((144,0)) I get (144,0). Moreover, when I execute SQR((144,144) I get (20808,3,46020761246E-3). The correct answeris 13.1842 + 5.4611i.
Seems like a bug to me?????
Namir
Edited: 27 Nov 2010, 7:44 p.m.
▼
Posts: 69
Threads: 6
Joined: Aug 2010
Yes something is wrong. When I execute the examples you just tried on EMU71, I get the correct results. Not the results you are getting.
Posts: 412
Threads: 40
Joined: Mar 2006
Hi Namir,
Are you running Emu71 on a native Windows computer, or in a Windows (or DOS) emulation?
J-F
▼
Posts: 2,247
Threads: 200
Joined: Jun 2005
Hi!
I usually launch a DOS box in Windows 7 and then run your emulator. I tried running the emulator directly and I get the same error. I am running a 32-bit Windows 7 on my (traveling) laptop.
I also noticed that raising complex number to integer power does not work!
Thank you for responding to my query!
Namir
Edited: 28 Nov 2010, 6:29 a.m.
▼
Posts: 1,841
Threads: 54
Joined: Jul 2005
Have you tried without the JPC, just to be sure ? IIRC the JPC listens to some interrupts, so maybe it's a matter of a Mode setting?
HTH
Ray
Posts: 412
Threads: 40
Joined: Mar 2006
Namir,
Very strange. I doubt this is a problem from Emu71 but can you send me your complete Emu71 folder with all your files so I can check ? jeffcalc (at] wanadoo <dot> fr thanks.
J-F
▼
Posts: 2,247
Threads: 200
Joined: Jun 2005
▼
Posts: 412
Threads: 40
Joined: Mar 2006
Found it :-))
In emu71.in, replace "2 ROM 16 mathrom.bin" by "2 ROM 32 mathrom.bin". Math module is a 32bB ROM.
What is strange is that Emu71 didn't crash with just half of the ROM loaded...
J-F
▼
Posts: 2,247
Threads: 200
Joined: Jun 2005
Jean-Francois,
It worked!!! thank you!! Now I get the correct results with EMU71. The power operator for complex numbers also works properly. I guess it was part of the ROM that was not loaded.
Many thanks for taking the time to look into it.
Namir
Edited: 28 Nov 2010, 6:27 p.m.
Posts: 69
Threads: 6
Joined: Aug 2010
Perhaps no calls were made within the ROM half that was missing. Although I wonder why the SQRT result Namir originally got didn't cause a crash. It is interesting.
▼
Posts: 2,247
Threads: 200
Joined: Jun 2005
The ^ operator also did not work! I had to recode the program and apply work-arounds.
When I used the SQRT with complex values I got (wrong) answers. The emulator never crashed.
namir
Edited: 29 Nov 2010, 4:54 a.m.
Posts: 1,619
Threads: 147
Joined: May 2006
Quote:
(or DOS) emulation?
I tested with DOS emulation without issue. I tested the latest EMU71 with DOSBox on OS/X and on my iPad.
10 COMPLEX A
20 A=-5
30 CALL TESTSUB(A)
40 END
100 SUB TESTSUB(A)
110 DISP SQRT(A)
120 END SUB
Results:
(0,2.2360679775)
VER$:
HP71:2CDCC RPN:C FACTR:A MATH:1A JPC:Ex HPIL:1B HELP:C FACTR:A STRU:A RCPY:E FTH41:1A EDT:A
Edited: 28 Nov 2010, 1:54 p.m.
|