home *** CD-ROM | disk | FTP | other *** search
- 3000 ' tutor 12
- 3010 GOSUB 37100
- 3020 T5$ = SPACE$(5) : T10$ = SPACE$(10) : T15$ = SPACE$(15) :VT$ = CHR$(11)
- 3030 PRINT T10$;" Before we go on to defining functions, would you like to"
- 3040 PRINT T10$;"review the meanings of the standard ones? ";
- 3050 GOSUB 40900 : Y$ = CVTSTR$
- 3060 PRINT
- 3070 IF LEFT$(Y$,1) = "N" THEN 4060
- 3080 IF LEFT$(Y$,1) = "Y" THEN 3110
- 3090 PRINT T10$;"Please type 'yes' or 'no', which is it...";VT$;VT$;CR$;
- 3100 GOTO 3040
- 3110 GOSUB 37100
- 3120 PRINT T10$;"Good. Use this answer selection table:"
- 3130 PRINT
- 3140 PRINT T10$;" (1) sin(x) (2) cos(x) (3) tan(x) (4) atn(x)"
- 3150 PRINT
- 3160 PRINT T10$;" (5) exp(x) (6) abs(x) (7) log(x) (8) sqr(x)"
- 3170 PRINT
- 3180 PRINT T10$;" (9) fix(x) (10) sgn(x)";CRLF$
- 3190 R = 0
- 3200 PRINT T10$;" Note: the above functions are in lower case. Mbasic will accept"
- 3210 PRINT T10$;"programs written in lower case and automatically convert them to"
- 3220 PRINT T10$;"upper case."
- 3230 GOSUB 37000 : PRINT FNPOSCUR$(14,1);EES$;
- 3240 PRINT T10$;"Which function finds the absolute value? ";
- 3250 GOSUB 40900 : A$ = CVTSTR$
- 3260 R = R + 1
- 3270 PRINT
- 3280 IF A$ = "6" OR (LEN(A$) > 1 AND LEFT$(A$,2) = "AB") THEN 3320
- 3290 PRINT T10$;"Nope, the function name is an abbreviation for what it does."
- 3300 PRINT T10$;"Try again - which one....";VT$;VT$;VT$;CR$;
- 3310 GOTO 3240
- 3320 PRINT VT$;VT$;CR$;EES$;
- 3330 PRINT T10$;"Good! The next question is harder: what function determines the"
- 3340 PRINT T10$;"natural logarithm of 'x'? ";
- 3350 GOSUB 40900 : A$ = CVTSTR$
- 3360 R = R + 1
- 3370 PRINT
- 3380 IF A$ = "7" OR (LEN(A$) > 1 AND LEFT$(A$,2) = "LO") THEN 3410
- 3390 PRINT T10$;"No - check the abbreviation for 'logarithm'. Now which....";
- VT$;VT$;CR$;
- 3400 GOTO 3340
- 3410 PRINT VT$;VT$;VT$;CR$;EES$;
- 3420 PRINT T10$;"Very Good! The next one is easy: what's the sine function? ";
- 3430 GOSUB 40900 : A$ = CVTSTR$
- 3440 R = R + 1
- 3450 PRINT
- 3460 IF A$ = "1" OR (LEN(A$) > 1 AND LEFT$(A$,2) = "SI") THEN 3490
- 3470 PRINT T10$;"Try again, please. Which one....";VT$;VT$;CR$;
- 3480 GOTO 3420
- 3490 PRINT VT$;VT$;CR$;EES$;
- 3500 PRINT T10$;"Right. Which function gives an angle whose tangent is 'x'? ";
- 3510 GOSUB 40900 : A$ = CVTSTR$
- 3520 R = R + 1
- 3530 PRINT
- 3540 IF A$ = "4" OR (LEN(A$) > 1 AND LEFT$(A$,2) = "AT") THEN 3570
- 3550 PRINT T10$;"It's tricky. Try again.";VT$;VT$;CR$;
- 3560 GOTO 3500
- 3570 PRINT VT$;VT$;CR$;EES$;
- 3580 PRINT T10$;"Excellent. Now for the hardest: what function computes 'e^x'? ";
- 3590 GOSUB 40900 : A$ = CVTSTR$
- 3600 R = R + 1
- 3610 PRINT
- 3620 IF A$ = "5" OR (LEN(A$) > 1 AND LEFT$(A$,2) = "EX") THEN 3650
- 3630 PRINT T10$;"Well it's hard. Hint: what is the exponential (power) of 'e'";VT$;VT$;CR$;
- 3640 GOTO 3580
- 3650 PRINT T10$;"Terrific. The rest are trivial, so we might as well move on."
- 3660 PRINT
- 3670 IF R = 5 THEN 3690
- 3680 GOTO 3700
- 3690 PRINT T10$;"By the way, you get a 'big gold star' for a perfect score."
- 3700 GOSUB 37000 : PRINT FNPOSCUR$(12,1);EES$;
- 3710 PRINT T10$;" Here are some restrictions which apply to certain functions:"
- 3720 PRINT T10$;"the argument of the sine, cosine, and tangent functions must"
- 3730 PRINT T10$;"be in radian measure. The arctangent gives an angle in radians."
- 3740 PRINT
- 3750 PRINT T10$;" The logarithm of a negative number is not defined. So if the"
- 3760 PRINT T10$;"argument is negative, an error message will appear and the"
- 3770 PRINT T10$;"command will be executed with a positive argument. If 'sqr' has"
- 3780 PRINT T10$;"a negative argument, then another error message appears and a"
- 3790 PRINT T10$;"positive argument is used. The argument of a function may be any"
- 3800 PRINT T10$;"expression, as long as it has a numerical value."
- 3810 GOSUB 37000 : GOSUB 37100
- 3820 PRINT T10$;" Let's make a table of 'x' and 'sin(x)' for 0<=x<=360 degrees"
- 3830 PRINT T10$;"in steps of 60 degrees. Here's a program which will do it:"
- 3840 PRINT
- 3850 PRINT "5 pi = 22/7"
- 3860 PRINT "10 let x = pi/180 ' (degrees to radians)"
- 3870 PRINT "20 for i = 0 to 360 step 60 ' (start of loop)"
- 3880 PRINT "30 print i, sin(x*i) ' (output statement)"
- 3890 PRINT "40 next i ' (end of loop)"
- 3900 PRINT "50 end ' (last statement)"
- 3910 PRINT
- 3920 PRINT T10$;"Would you like to have this program run? ";
- 3930 GOSUB 40900 : B$ = CVTSTR$
- 3940 PRINT
- 3950 IF LEN(B$) = 0 OR LEFT$(B$,1) <> "Y" THEN 4080
- 3960 GOSUB 37100
- 3970 X = (22/7) / 180
- 3980 FOR I = 0 TO 360 STEP 60
- 3990 PRINT I, SIN(X * I)
- 4000 NEXT I
- 4010 PRINT "Ok"
- 4020 PRINT
- 4030 PRINT T10$;" Column headings would probably have improved the output. Also,"
- 4040 PRINT T10$;"two functions were not shown above. 'INT' extracts the whole"
- 4050 GOTO 4100
- 4060 PRINT:PRINT T10$;" OK, but two should interest you. 'INT' extracts the whole"
- 4070 GOTO 4100
- 4080 PRINT T10$;"Anyway, it does the job. Don't forget: in addition to the "
- 4090 PRINT T10$;"eight functions above, there's 'int', which extracts the whole"
- 4100 PRINT T10$;"number part of any number. If n=27.68, then when the statement"
- 4110 PRINT T10$;"'print int(n)' is used, the computer will print '27'. The other"
- 4120 PRINT T10$;"standard function is 'rnd(x)', which generates a number (not"
- 4130 PRINT T10$;"specified) between 0 and 1. It has an unused ('dummy') argument."
- 4140 PRINT T10$;"'rnd' is equivalent to 'rnd(0)'"
- 4150 PRINT
- 4160 IF LEFT$(Y$,1) = "N" THEN 4180
- 4170 PRINT T10$;"I'll remind you of a program on standard functions later."
- 4180 PRINT T10$;"Let's show how we can write our own functions. This is done"
- 4190 PRINT T10$;"by means of the term 'def' (for 'define')."
- 4200 PRINT : PRINT FNCENTER$("press any key for an example");
- 4210 FOR CT = 1 TO 28 : PRINT CHR$(8); : NEXT CT : GOSUB 40800 : GOSUB 37100
- 4220 PRINT "10 def fnp(c) = c + .57 * c"
- 4230 PRINT
- 4240 PRINT T10$;"The 'fn' means 'function' to the computer, and 'p' is the name"
- 4250 PRINT T10$;"of the function. A function name is any legal variable name";CRLF$
- 4260 PRINT T10$;"What is the argument in the above definition? ";
- 4270 GOSUB 40900 : A$ = CVTSTR$
- 4280 PRINT
- 4290 IF A$ = "C" THEN 4320
- 4300 PRINT T10$;" Wrong - 'c' is operated on; the right side shows how."
- 4310 GOTO 4330
- 4320 PRINT T10$;" Of course. Any function needs an argument. on the right side,"
- 4330 PRINT T10$;"'c + .57 * c' will have a value dependent upon the size of 'c'. If"
- 4340 PRINT T10$;"'p' is a sales price based on a 57 percent markup over cost,"
- 4350 PRINT T10$;"then the expression could be read: 'the price function of cost"
- 4360 PRINT T10$;"is defined as c + .57 * c'."
- 4370 GOSUB 37000 : GOSUB 37100
- 4380 PRINT T10$;"The following sample program incorporates the example function:"
- 4390 PRINT
- 4400 PRINT "100 def fnp(c) = c+.57*c"
- 4410 PRINT "110 read c"
- 4420 PRINT "120 data .27"
- 4430 PRINT "130 print "; CHR$(34); "Cost is"; CHR$(34); ";c,"; CHR$(34); "Sales price is"; CHR$(34); ";fnp(c)"
- 4440 PRINT "140 end";CRLF$
- 4450 PRINT T10$;"Do you wish to see the results of running this program? ";
- 4460 GOSUB 40900 : A$ = CVTSTR$ : IF LEFT$(A$,1) <> "Y" THEN 4500
- 4470 GOSUB 37100
- 4480 DEF FNP(C) = C + .57 * C : READ C : DATA .27
- 4490 PRINT : PRINT "Cost is"; C, "Sales price is"; FNP(C) : PRINT "Ok"
- 4500 PRINT
- 4510 PRINT T10$;" For a complicated function used more than once in a program,"
- 4520 PRINT T10$;"the define statement has obvious advantages. More examples"
- 4530 PRINT T10$;"of using defined functions will be included in later lessons."
- 4540 PRINT
- 4550 PRINT T10$;"Lesson 13 discusses subroutines and the 'REM' statement"
- 4560 PRINT CRLF$;FNCENTER$("press any key for menu");
- 4570 FOR CT = 1 TO 22 : PRINT CHR$(8); : NEXT CT : GOSUB 40800
- 4580 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 12");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 12 version 2.0 released to nls 1 aug 83
-
- 39999 RUN "MENU" 'end of overlay
-
- utr to get all variables
- 38030 ' tutor lesson 12 version 2.0