10 REM CIRCUIT ANALYSIS PROGRAM 120 DIM F(40),H(40),J(40),C(40):NN = 1 140 HOME 150 PRINT TAB( 24)"COMPONENT LIST": PRINT TAB( 24)"--------------" 160 DIM R(15,15),S(15,15) 165 PI = 3.1415927 170 PRINT " TYPE NODES VALUE IMPEDANCE" 180 PRINT " ---- ------ ------ ---------" 190 FOR I = 1 TO 9: READ C$(I): NEXT : FOR I = 1 TO 9: READ S$(I): NEXT 200 READ FF,E,D: IF P = 0 THEN F = FF 210 GOSUB 640 220 READ A: IF P = 0 THEN PRINT : PRINT S$(T);" ANALYSIS "; 230 IF P = 0 THEN PRINT N + 1;"NODES" 240 IF T = 9 AND P = 0 THEN PRINT : PRINT " MEASUREMENT N ODE: ";A:O = A 250 IF P = 0 AND T < 9 THEN READ O: PRINT "INPUT NODE: ";A;" OUTPUT NODE: ";O 260 IF P > 0 AND T < 9 THEN READ O 270 IF P = 0 THEN PRINT " FREQ AMPLITUDE DB PHASE": PRINT " ------- ------------ ------ -------" 290 R = A:V = O: IF T = 9 THEN V = A:O = A 300 READ T$: GOSUB 750:S = G:X = V: IF ( - 1) ^ (A + O) > 0 THEN 320 310 X = X + 180 320 RESTORE : FOR I = 1 TO 18: READ C$: NEXT : READ C,C,C:P = 1: GOSUB 640 330 IF T = 7 THEN 360 340 U = N: IF N = 2 THEN GOSUB 800: GOTO 370 350 GOSUB 790: GOTO 370 360 R = A:V = A: GOSUB 750 370 IF S$(T) < > "VOLTAGE" THEN S = 100 * S 375 S = S / G:X = X - V: IF X > 180 THEN X = X - 360 380 IF X < - 180 THEN X = X + 360 390 C = INT (S / .001 + .5) * .001:H = INT (2000 * LOG (S) / LOG (10) + .5) * .01:B = INT (F / .1 + .5) * .1 400 J = INT (X / .01 + .5) * .01:J$ = "BCHJ":Q = 1:K$ = "14264054": GOSUB 1040 420 F(NN) = B:H(NN) = H:J(NN) = J:C(NN) = C:NN = NN + 1 450 IF T$ = "M" THEN F = F * D: GOTO 480 470 F = F + D 480 IF F > E THEN 1200 490 RESTORE : GOTO 190 500 READ I,J,C: IF P = 0 THEN J$ = "IJC":K$ = "131737": GOSUB 1030 510 ON T GOTO 520,580,600 520 C = 100 / C: GOSUB 740 530 IF I > N THEN N = I 540 IF J > N THEN N = J 550 IF K > N THEN N = K 560 IF L > N THEN N = L 570 GOTO 650 580 C = - 100 / (2 * PI * F * C) 590 S(I,I) = S(I,I) + C:S(J,J) = S(J,J) + C:S(I,J) = S(I,J) - C:S(J,I) = S(J,I) - C: GOTO 530 600 C = 200 * PI * F * C: GOTO 590 610 READ J,K,I,C: IF P = 0 THEN J$ = "JKIC": GOSUB 1020 620 L = J:C = 100 * C 630 R(I,K) = R(I,K) + C:R(J,L) = R(J,L) + C:R(J,K) = R(J,K) - C:R(I,L) = R(I,L) - C: GOTO 530 640 FOR I = 1 TO N + 1: FOR J = 1 TO N + 1:R(I,J) = 0:S(I,J) = 0: NEXT : NEXT 650 READ C$: FOR T = 1 TO 9: IF C$ = C$(T) THEN 670 660 NEXT : PRINT : PRINT "********DATA ERROR**********": STOP 670 ON T GOTO 500,500,500,610,690,710,680,680 680 N = N - 1: RETURN 690 READ J,K,I,H,C: IF P = 0 THEN J$ = "JKIHC": GOSUB 1020 700 C = 100 / C / H:L = I:I = K: GOSUB 740:I = L:L = J: GOTO 730 710 READ L,K,I,J,H,C: IF P = 0 THEN J$ = "LKIJHC":K$ = "131721253752": GOSUB 1030 720 C = 100 / C: GOSUB 740 730 C = H * C: GOTO 630 740 R(I,I) = R(I,I) + C:R(J,J) = R(J,J) + C:R(I,J) = R(I,J) - C:R(J,I) = R(J,I) - C: RETURN 750 IF N = 1 THEN G = 1:V = 0: RETURN 760 K = 0:U = N - 1: FOR I = 1 TO U: IF I = R THEN K = 1 770 L = 0: FOR J = 1 TO U: IF J = V THEN L = 1 780 R(I,J) = R(I + K,J + L):S(I,J) = S(I + K,J + L): NEXT : NEXT 790 IF N < 3 THEN R = R(1,1):V = S(1,1): GOTO 1000 800 FOR I = 1 TO U - 1:J = 1:B = ABS (R(I,I)) + ABS (S(I,I)) 810 FOR K = I + 1 TO U:C = ABS (R(K,I)) + ABS (S(K,I)): IF B > = C THEN 830 820 J = K:B = C 830 NEXT : IF J = 1 THEN 860 840 FOR L = 1 TO U:B = - R(I,L):R(I,L) = R(J,L):R(J,L) = B:Y = - S(I,L):S(I,L) = S(J,L) 850 S(J,L) = Y: NEXT 860 FOR K = I + 1 TO U:Y = R(I,I) * R(I,I) + S(I,I) * S(I,I):R = R(I,I) * R(K,I) + S(I,I) * S(K,I) 870 V = R(I,I) * S(K,I) - R(K,I) * S(I,I): FOR L = I + 1 TO U:R(K,L) = R(K,L) - (R(I,L) * R - S(I,L) * V) / Y 890 S(K,L) = S(K,L) - (R(I,L) * V + S(I,L) * R) / Y: NEXT : NEXT : NEXT 900 R = 1:V = 0 910 FOR K = 1 TO U:B = R:R = R(K,K) * R - V * S(K,K):V = V * R(K,K) + B * S(K,K): NEXT 1000 G = SQR (R * R + V * V):V = 180 * ATN (V / (R + 1E - 33)) / PI: IF R < 0 THEN V = V + 180 1010 RETURN 1020 K$ = "1317213754" 1030 Q = 4: PRINT S$(T); 1040 IF T > 7 THEN K$ = "14284054" 1050 FOR LL = 1 TO LEN (J$):M$ = MID$ (J$,LL,1): IF M$ = "I" THEN M = I 1060 IF M$ = "J" THEN M = J 1070 IF M$ = "K" THEN M = K 1080 IF M$ = "C" THEN M = C 1090 IF M$ = "H" THEN M = H 1100 IF M$ = "B" THEN M = B 1110 IF M$ = "L" THEN M = L 1120 O$ = STR$ (M):R = VAL ( MID$ (K$,2 * LL - 1,2)):Z = LEN ( STR$ ( INT ( ABS ( VAL (O$))))) 1130 IF ABS (M) < 1 AND ABS (M) > = .01 THEN Z = 1 1140 IF R - Q < > Z THEN FOR XX = 1 TO R - Q - Z: PRINT " ";: NEXT 1150 PRINT O$;:Q = R + LEN (O$) - Z: NEXT : PRINT : RETURN 1160 DATA R,L,C,F,T,A,V,I,Z, "RESISTOR ","INDUCTOR ","CAPACITOR ","FET ","TRANSISTOR", "AMPLIFIER ","VOLTAGE" 1170 DATA "TRANSFER IMPEDANCE", IMPEDANCE 1200 JS = 2 ^ 125:HS = JS:JM = - JS:HM = JM:NN = NN - 1: FOR I = 1 TO NN 1210 IF H(I) > HM THEN HM = H(I):CM = C(I) 1220 IF H(I) < HS THEN HS = H(I):CS = C(I) 1230 IF J(I) > JM THEN JM = J(I) 1240 IF J(I) < JS THEN JS = J(I) 1242 NEXT 1245 PRINT : PRINT "PRESS 'ANY KEY TO PLOT THE DATA " 1247 KEY = 0:KEY = PEEK ( - 16384): IF KEY < 127 THEN 1247 1250 HOME : PRINT S$(T)" ANALYSIS": PRINT 1260 IF S$(T) = "VOLTAGE" THEN 1290 1270 PRINT "MAXIMUM IMPEDANCE = ",CM," OHMS": PRINT "MINIMUM IMPEDANCE = ",CS," OHMS": PRINT 1280 FOR I = 1 TO NN:H(I) = H(I) - HM: NEXT :HS = HS - HM:HM = 0 1290 GOSUB 1460: GOSUB 1480: GOSUB 1510: PRINT 1300 L = 0:A = 1 1310 G = 4:L = L + 1: IF A > NN THEN 1370 1315 O$ = STR$ (F(A)):J = 16:Q = 1: GOSUB 1660: IF Q < > 21 THEN FOR X = 1 TO 21 - Q: PRINT " ";: NEXT 1320 IF JM < > JS THEN UU = INT ((J(A) - JS) / (JM - JS) * 25 + .5) + 1 1330 M = 0: IF HM < > HS THEN U = INT ((H(A) - HS) / (HM - HS) * 25 + .5) + 1 1340 FOR V = 1 TO 26: GOSUB 1520: NEXT :A = A + 1: PRINT 1350 IF L < 5 THEN 1310 1360 L = 0: GOTO 1310 1370 GOSUB 1510: PRINT : GOSUB 1480: GOSUB 1460 1380 PRINT : INPUT "DO YOU WANT TO CHANGE SCALES ?";J$ 1390 IF LEFT$ (J$,1) = "N" THEN END 1400 PRINT : PRINT "DO YOU WANT TO CHANGE THE ": PRINT S$(T)," (DB) SCALE ";: INPUT J$ 1410 IF LEFT$ (J$,1) = "N" THEN 1430 1420 PRINT : PRINT "ENTER ",A$(T)," (DB) MIN AND ",S$(T)," (DB) MAX:": INPUT HS,HM 1430 PRINT "DO YOU WANT TO CHANGE THE": INPUT "PHASE SCALE ";J$ 1440 IF LEFT$ (J$,1) = "N" THEN 1290 1450 PRINT : PRINT "ENTER PHASE MIN AND MAX:": INPUT JS,JM: GOTO 1290 1460 Q = 9: PRINT " PHASE(X)";: FOR I = 1 TO 6:FF = JS - (I - 1) * (JS - JM) / 5:O$ = STR$ ( VAL ( LEFT$ ( STR$ (FF),4))) 1470 J = 13 + 5 * I: GOSUB 1660: NEXT : PRINT : RETURN 1480 Q = 9: PRINT " DB(*)";: FOR I = 1 TO 6:FF = HS - (I - 1) * (HS - HM) / 5:O$ = STR$ ( VAL ( LEFT$ ( STR$ (FF),4))) 1490 J = 13 + 5 * I: GOSUB 1660: NEXT : PRINT 1500 RETURN 1510 PRINT " HZ +";: FOR I = 1 TO 5: PRINT "----+";: NEXT : RETURN 1520 IF M < 0 THEN RETURN 1530 IF L < 5 THEN 1580 1540 G = G + 1: IF G < 5 THEN 1610 1550 G = 0: IF V = U THEN 1640 1560 IF V = UU THEN 1650 1570 PRINT "+";: RETURN 1580 IF V < > U THEN 1610 1590 M = 1: IF V = UU THEN 1650 1600 GOTO 1640 1610 IF V = U THEN 1640 1620 IF V = UU THEN 1650 1630 PRINT " ";: RETURN 1640 PRINT "*";: RETURN 1650 PRINT "X";: RETURN 1660 Z = LEN ( STR$ ( INT ( VAL (O$)))) 1670 IF J - Q < > Z THEN FOR X = 1 TO J - Q - Z: PRINT " ";: NEXT 1680 PRINT O$;:Q = J + LEN (O$) - Z: RETURN 10000 DATA 2E6,130E6,1.41421356 11000 DATA R,1,2,1000 12000 DATA C,2,3,5E-12 13000 DATA R,3,5,2000 14000 DATA R,4,5,1000 15000 DATA F,4,2,3,2E-3 16000 DATA V,1,3,M