home *** CD-ROM | disk | FTP | other *** search
- 3000 ' tutor 8 Ver 2.0 01AUG83
- 3010 GOSUB 37100
- 3020 T5$ = SPACE$(5) : T10$ = SPACE$(10) : T15$ = SPACE$(15) :VT$ = CHR$(11)
- 3030 GOSUB 37100
- 3040 PRINT T10$;" OK. We'll try a problem: Required: compute successive values"
- 3050 PRINT T10$;"of U*(U+1)^2 for uniformly increasing 'U' values, but limiting"
- 3060 PRINT T10$;"U*(U+1)^2 to 10 or less. The computer will decide how many 'U'"
- 3070 PRINT T10$;"values it will use. It will keep increasing 'U' by 'delta U'"
- 3080 PRINT T10$;"until U*(U+1)^2 reaches 10, then stop. The program shown "
- 3090 PRINT T10$;"below will accomplish this.";CRLF$
- 3100 PRINT "100 LET U = 0"
- 3110 PRINT "110 PRINT U, U * (U + 1)^2"
- 3120 PRINT "120 LET U = U + 1"
- 3130 PRINT "130 IF U * (U + 1)^2< = 10 THEN 110"
- 3150 PRINT "140 END"
- 3160 PRINT
- 3170 PRINT T10$;" Study the program and see if you can tell me what line"
- 3180 PRINT T10$;"number is the beginning of the loop. Which would you say? ";
- 3190 GOSUB 40900 : L$ = CVTSTR$
- 3200 PRINT
- 3210 IF L$ = "110" THEN 3240
- 3220 PRINT T10$;"Try another number."; VT$;VT$;CR$;
- 3230 GOTO 3180
- 3240 PRINT VT$;VT$;VT$;CR$;EES$;
- 3245 PRINT T10$;"Fine. And which is the last line in the loop? ";
- 3250 GOSUB 40900 : T$ = CVTSTR$ : PRINT
- 3260 IF T$ = "130" THEN 3280
- 3270 PRINT T10$;"Study the program and try again!"; VT$;VT$;CR$;
- 3275 GOTO 3245
- 3280 PRINT T10$;" That's the one. Notice we used a 'delta U' of unity (line 120);"
- 3290 PRINT T10$;"We could have used other incremental values, which would have"
- 3300 PRINT T10$;"changed the number of times through the loop. Here are three "
- 3310 PRINT T10$;"outputs based on different values of 'delta U' shown in line 120"
- 3320 GOSUB 37000 : GOSUB 37100
- 3330 PRINT T10$;"For '120 LET U = U + 1' we get: For '120 LET U = U + .2' we get:"
- 3340 PRINT
- 3350 PRINT T10$;" U U * (U + 1)^2 U U * (U + 1)^2"
- 3360 PRINT T10$;" 0 0 0 0"
- 3365 PRINT T10$;" 1 4 .2 .288"
- 3370 PRINT T10$;" .4 .784"
- 3380 PRINT T10$;"For '120 LET U = U + .5' we get: .6 1.536"
- 3390 PRINT T10$;" .8 2.592"
- 3400 PRINT T10$;" 0 0 1. 4."
- 3410 PRINT T10$;" .5 1.125 1.2 5.808"
- 3420 PRINT T10$;" 1 4 1.4 8.064"
- 3430 PRINT T10$;" 1.5 9.375";CRLF$
- 3440 PRINT T10$;" In each case, 'U' is the left-hand column and 'U*(U+1)^2' is the"
- 3450 PRINT T10$;"right-hand column. Notice - the largest number in the right-hand"
- 3460 PRINT T10$;"column is never over 10 (130 IF U * (U + 1)^2< = 10 THEN 110.)"
- 3465 PRINT T10$;"The computer has seen that one more 'U' would be too much,"
- 3470 PRINT T10$;"and has taken action to halt the loop."
- 3480 GOSUB 37000 : GOSUB 37100
- 3490 PRINT T10$;" Another way to 'loop' uses an instruction requiring a predeter-"
- 3500 PRINT T10$;"mined number of loops - i.e., the computer is instructed exactly how"
- 3510 PRINT T10$;"many iterations it is to make. Here is an example:";CRLF$
- 3520 PRINT "160 FOR J = 2 TO 2.5 STEP .1"
- 3530 PRINT
- 3540 PRINT T10$;" How would you answer this: True or False: 'J' values control"
- 3550 PRINT T10$;"the number of iterations. -- Your answer? ";
- 3560 GOSUB 40900 : J$ = LEFT$(CVTSTR$,1)
- 3570 PRINT
- 3580 IF J$ = "1" OR J$ = "T" THEN 3610
- 3590 PRINT VT$;VT$;VT$;CR$;EES$;T10$;" You should have said 'True'. You see, 'J' is the counter, and"
- 3600 GOTO 3620
- 3610 PRINT VT$;VT$;VT$;CR$;EES$;T10$;" You're right. The 'J' value will be used to count the loop."
- 3620 PRINT T10$;"its starting value will be '2'. Its maximum value will be? ";
- 3630 GOSUB 40900 : J1$ = CVTSTR$
- 3640 PRINT
- 3650 IF J1$ = "2.5" THEN 3680
- 3660 PRINT T10$;" No - but its maximum value is shown in the statement.";VT$;VT$;CR$;ELR$;
- 3670 GOTO 3620
- 3680 PRINT VT$;VT$;VT$;CR$;EES$;T10$;" Good. But it may end up somewhat less, because of the size of"
- 3690 PRINT T10$;"the increment (change in 'J'). What increment is shown? ";
- 3700 GOSUB 40900 : I$ = CVTSTR$
- 3710 PRINT
- 3720 IF I$ = ".1" THEN 3750
- 3730 PRINT T10$;" That's not it, but the statement tells.";VT$;VT$;CR$;
- 3740 GOTO 3690
- 3750 PRINT VT$;VT$;VT$;CR$;EES$;T10$;" You obviously understand the statement, and probably realize"
- 3760 PRINT T10$;"that '160' is the statement (or line) number, 'FOR' means"
- 3770 PRINT T10$;"'starting value' to the machine, 'TO' says 'maximum value',"
- 3780 PRINT T10$"and 'STEP' means 'increment by'. "
- 3790 GOSUB 37000 : PRINT VT$;VT$;VT$;VT$;VT$;CR$;EES$;T10$;
- 3800 PRINT " Now we have one more obstacle. The computer knows where the"
- 3810 PRINT T10$;"loop starts (at line 160) and everything else about it except"
- 3820 PRINT T10$;"where it stops - i.e., what the last instruction in the loop "
- 3830 PRINT T10$;"is. Do you think (1) 'LAST LINE' or (2) 'NEXT J' or (3) 'NEW J'"
- 3840 PRINT T10$;"is the correct last instruction? ";
- 3850 GOSUB 40900 : N$ = CVTSTR$
- 3860 PRINT VT$;VT$;VT$;VT$;VT$;CR$;EES$;
- 3870 IF N$ = "2" OR (LENSTR% > 2 AND LEFT$(N$,3) = "NEX") THEN 3890
- 3875 PRINT
- 3880 PRINT T10$;EES$;" Well, maybe that was too tricky. It should be 'NEXT J', and we"
- 3885 GOTO 3900
- 3890 PRINT T10$;EES$;" That's the one, all right. The word 'NEXT' is the clue. so we"
- 3900 PRINT T10$;"put a line number on it which sequences it as the last line of"
- 3910 PRINT T10$;"the loop. The computer then 'backtracks' to the beginning of"
- 3920 PRINT T10$;"the loop (line 160 here) and 'loops' until 'J' says to stop."
- 3930 GOSUB 37000 : GOSUB 37100
- 3940 PRINT T10$;" For the previous example, suppose we wanted 4 values, regardless"
- 3950 PRINT T10$;"of the function's size. Let's count with 'C'. We'll write:"
- 3960 PRINT
- 3970 PRINT "100 LET U = 0"
- 3980 PRINT "110 FOR C = 1 TO 4"
- 3985 PRINT "120 PRINT U, U * (U + 1)^2"
- 3990 PRINT "130 LET U = U + .2"
- 4000 PRINT "140 NEXT C"
- 4010 PRINT "150 END"
- 4020 PRINT
- 4030 PRINT T10$;" When 'step' is omitted (line 110) the increase (in 'C') is 1."
- 4040 PRINT T10$;"So now we have looked at two ways to iterate - the 'IF' loop"
- 4050 PRINT T10$;"and the 'FOR' loop. We'll be seeing more of them in the future."
- 4060 PRINT CRLF$;T10$;"Your next lesson is 'TUTR.09'"
- 4070 PRINT CRLF$;FNCENTER$("press any key for menu");
- 4080 FOR CT = 1 TO 22 : PRINT CHR$(8); : NEXT CT : GOSUB 40800
- 4090 GOTO 39999
-
- 37000 'press any key pause
- 37010 PRINT T10$;CRLF$;CRLF$;FNCENTER$("press any key to continue");
- 37020 FOR CT= 1 TO 25 : PRINT CHR$(8); : NEXT CT
- 37030 GOSUB 40800
- 37099 RETURN
-
- 37100 ' heading
- 37110 PRINT CLS$;FNPOSCUR$(4,1);FNCENTER$("Tutor -- Lesson 8");CRLF$
- 37199 RETURN
-
- 38000 ' converted for Non-linear Systems, Kaypro Educational Division
- 38010 ' by t.crew , Simple Software, San Diego CA
- 38020 ' has to be run with mentutr to get all variables
- 38030 ' tutor lesson 8 version 2.0 released to nls 1 aug 83
-
- 39999 RUN "MENU" 'end of overlay
-
- tutr to get all variables
- 38