 The Museum of HP Calculators

HP Forum Archive 20

 Symbolic Complex Linear System Solver (HP-28S, HP-48G/GX and HP-50g)Message #1 Posted by Gerson W. Barbosa on 13 Mar 2011, 3:10 p.m. This program was written many years ago by Francisco Matheus, one of my classmates back then, originally for the HP-28S. It was particularly useful during Circuit Analysis examinations. The program would accept symbolic equations, no further rearrangement being necessary, which was very impressive. The author has authorized its free use with the hope it continues to be useful for EE students. No warranty shall be provided though. Test it on your textbook examples before you decide it's suitable for your needs. The HP-48G/GX and HP-50g built-in linear system solver is an option. 1) V1 - V2 = 10*Ix 2) V1/j20 + (V1 - V3)/20 + V2/10 + (V2 - V3)/-j10 = 0 3) V3/j10 + (V3-V2)/-j10 + 2/-45 + (V3 - V1)/20 = 0 4) Ix = -V3/j10 where j = sqrt(-1) and 2/-45 is 2 angle -45 degrees. As an example, the equations in the linear system above would be entered as ```'V1-V2=10*IX' 'V1/(0,20)+(V1-V3)/20+V2/10+(V2-V3)/(0,-10)=0' 'V3/(0,10)+(V3-V2)/(0,-10)+(1.41421356237,-1.41421356237)+(V3-V1)/20=0' 'IX=-V3/(0,10)' ``` On the HP-28S 2/-45 would have to be previously converted from polar to retangular coordinates. Notice the number of equations could have been reduced to three by substituting eq. 4 in eq. 1, but we'll use the example as it has been presented. Copy the programs to an empty HP-28S directory. Enter the four equations of the example system, enter the list of unknowns {V1 V2 V3 IX} then run SYS program to solve the linear system. The '<-' program cleans up the directory, that is, it purges all objects at the left of it in the menu. The lines below can be copied and pasted to Emu42 with an HP-28S ROM and then saved to 'SYS', '<-' and 'EQS', respectively, after applying the STR-> command. ( '<-' should be entered as 142 CHR STR-> ) ’ DUP SIZE Ť l n ’ n ŤLIST 'EQS' STO 0 n FOR i 1 n FOR j i j == 1 0 IFTE l j GET STO NEXT 1 n FOR j 'EQS(j)' ŤNUM NEXT n ŤARRY i IF NOT THEN NEG 'VET' STO ELSE VET + ARRYŤ DROP END NEXT { n n } ŤARRY l PURGE TRN CONJ 'MAT' STO VET MAT / n 1 FOR i DUP i GET l i GET STO -1 STEP VET ARRYŤ DROP { n 1 } ŤARRY 'VET' STO DROP “ “ ’ VARS 1 OVER 'Ž' POS 1 - SUB PURGE “ { 'V1-V2=10*IX' 'V1/ (0,20)+(V1-V3)/20+V2 /10+(V2-V3)/(0,-10)= 0' 'V3/(0,10)+(V3-V2 )/(0,-10)+ (1.41421356237,-1.41421356237) +(V3-V1)/20=0' 'IX=- V3/(0,10)' } Contents of the directory after the example linear system is solved HP-28S Version:```-------------------------- V1 (-1.88561808316, -24.5130350811) V2 (-1.88561808316, -5.65685424948) V3 (-18.8561808316,0) IX (0,-1.88561808316) MAT [[ (1,0) (-1,0) (0,0) (-10,0) ] [ (.05,-.05) (.1,.1) (-.05,-.1) (0,0) ] [ (-.05,0) (0,-.1) (.05,0) (0,0) ] [ (0,0) (0,0) (0,-.1) (1,0) ]] VET [[ (0,0) ] [ (0,0) ] [ (-1.41421356237,1.41421356237) ] [ (0,0) ]] EQS { 'V1-V2=10*IX' 'V1/ (0,20)+(V1-V3)/20+V2 /10+(V2-V3)/(0,-10)= 0' 'V3/(0,10)+(V3-V2 )/(0,-10)+ (1.41421356237,-1.41421356237) +(V3-V1)/20=0' 'IX=- V3/(0,10)' } <- « VARS 1 OVER '<-' POS 1 - SUB PURGE » SYS « DUP SIZE \-> l n « n \->LIST 'EQS' STO 0 n FOR i 1 n FOR j i j == 1 0 IFTE l j GET STO NEXT 1 n FOR j 'EQS(j)' \->NUM NEXT n \->ARRY i IF NOT THEN NEG 'VET' STO ELSE VET + ARRY\-> DROP END NEXT { n n } \->ARRY l PURGE TRN CONJ 'MAT' STO VET MAT / n 1 FOR i DUP i GET l i GET STO -1 STEP VET ARRY\-> DROP { n 1 } \->ARRY 'VET' STO DROP » » -------------------------- ``` HP-48G/GX Version: On the HP-48G/GX and the HP-50g, the third equation can be entered as `'V3/(0,10)+(V3-V2)/(0,-10)+(2,/-45)+(V3-V1)/20=0'` On the HP-48G/GX the angle symbol '/ ' is accessible through right-shift SPC (ALPHA right-shift 6 on the HP-50g). ``` -------------------------- %%HP: T(3)A(D)F(.); DIR V1 (-1.88561808316,-24.5130350811) V2 (-1.88561808316,-5.65685424948) V3 (-18.8561808316,0) IX (0,-1.88561808316) MAT [[ (1,0) (-1,0) (0,0) (-10,0) (0,0) ] [ (.05,-.05) (.1,.1) (-.05,-.1) (0,0) (0,0) ] [ (-.05,0) (0,-.1) (.05,0) (0,0) (-1.41421356237,1.41421356237) ] [ (0,0) (0,0) (0,-.1) (1,0) (0,0) ]] EQS { 'V1-V2=10*IX' 'V1/(0,20)+(V1-V3)/20+V2/10+(V2-V3)/(0,-10)=0' 'V3/(0,10)+(V3-V2)/(0,-10)+(1.41421356237,-1.41421356237)+(V3-V1)/20=0' 'IX=-V3/(0,10)' } \183\<- \<< VARS 1 OVER '\183\<-' POS 1 - SUB PURGE \>> SYS \<< DUP SIZE \-> l n \<< n \->LIST 'EQS' STO 0 n FOR i 1 n FOR j i j == 1 0 IFTE l j GET STO NEXT 1 n FOR j 'EQS(j)' \->NUM NEXT n \->ARRY i IF NOT THEN NEG 'VET' STO ELSE VET + ARRY\-> DROP END NEXT { n n } \->ARRY l PURGE TRN CONJ 'MAT' STO VET MAT / n 1 FOR i DUP i GET l i GET STO -1 STEP DROP MAT VET n 1 + COL+ 'MAT' STO 'VET' PURGE \>> \>> END -------------------------- ``` HP-50g Version: CAS mode should be set to Complex. ```-------------------------- %%HP: T(3)A(D)F(.); DIR V1 (-1.88561808316,-24.5130350811) V2 (-1.88561808317,-5.65685424948) V3 (-18.8561808316,0.) IX (0.,-1.88561808316) MAT [[ (1.,0.) (-1.,0.) (0.,0.) (-10.,0.) 0. ] [ (.05,-.05) (.1,.1) (-.05,-.1) (0.,0.) (0.,0.) ] [ (-.05,0.) (0.,-.1) (.05,0.) (0.,0.) (-1.41421356237,1.41421356237) ] [ (0.,0.) (0.,0.) (0.,-.1) (1.,0.) (0.,0.) ]] EQS { 'V1-V2=10*IX' 'V1/(0+20*i)+(V1-V3)/20+V2/10+(V2-V3)/(0+-10*i)=0' 'V3/(0+10*i)+(V3-V2)/(0+-10*i)+(2*COS(-45)+2*SIN(-45)*i)+(V3-V1)/20=0' 'IX=-V3/(0+10*i)' } \183\<- \<< VARS 1 OVER '\183\<-' POS 1 - SUB PURGE \>> SYS \<< DUP SIZE \-> l n \<< n \->LIST 'EQS' STO 0 n FOR i 1 n FOR j i j == 1 0 IFTE l j GET STO NEXT 1 n FOR j 'EQS(j)' \->NUM NEXT n \->ARRY i IF NOT THEN \->NUM NEG 'VET' STO ELSE VET + \->NUM ARRY\-> DROP END NEXT { n n } \->ARRY l PURGE TRAN 'MAT' STO VET MAT / n 1 FOR i DUP i GET l i GET STO -1 STEP DROP MAT VET n 1 + COL+ 'MAT' STO 'VET' PURGE \>> \>> END -------------------------- ``` Edited: 13 Mar 2011, 4:00 p.m. Go back to the main exhibit hall