Scrutinize papers

Everything related to BASIC version 1.x (Oric 1 and Atmos) or HYPERBASIC (Telestrat).
Don't hesitate to give your small program samples, technical insights, or questions...
vrozos
Officer Cadet
Posts: 63
Joined: Mon Nov 21, 2011 12:36 pm
Location: Athens, Greece
Contact:

Scrutinize papers

Post by vrozos »

Having completed more than 20 paper reviews, I have to say that I am
fed up with bad mathematics coming from people that are supposed to be
the scientific elite (Professors, Doctors, Ph.D candidates etc). The
majority of the papers I have reviewed had problems with the units and
the dimensions (i.e. high school mathematics). To help me with the
review process I prepared two programs.

The first program identifies the units of an expression and the second
scrutinizes matrix operations.
vrozos
Officer Cadet
Posts: 63
Joined: Mon Nov 21, 2011 12:36 pm
Location: Athens, Greece
Contact:

Check expression units

Post by vrozos »

General

This program determines the units of an expression based on the units
of the variables involved in this expression. Only basic units of SI (i.e. kg,
m, s and K) can be used. For example a force of 1 N should be written
as 1*kg*m/s^2.

Instructions

First define the variables in lines 200-299 (value and units) and then
the expression in line 310. The program is run with RUN 10. The results
need some decryption and for this reason a "translation table" is
printed to help in their interpretation. For example if the program
identifies the units of an expression as:

KG= 2
M = 0.5
S = 0.25
KV= 1

this means (see translation table in lines 20-25) that the units are
kg/(m s^2).

Furthermore, you can print the value of the expression with ? XSN. If
you have defined reasonable values for the variables, the expression
should have a reasonable value too.

Restrictions of variable names in Oric: Only capitals, only the two
first letters of the variable name matter (i.e. for Oric KV is the same
with KVANTOUM), Basic tokens cannot be used as variable names (i.e.
EXP=1 is a SYNTAX ERROR).

1 LIST 10-19
5 ' Evangelos Rozos Jan. 2012
10 ' This program calculates the
11 ' units of an expression. Define
12 ' the variables in lines 200-299
13 ' and the expression in line 310.
14 ' Run the program with RUN 10.
15 '
20 ' Translation of results
21 ' .0625 .125 .25 .5 1
22 ' -4 -3 -2 -1 0
23 '
24 ' 16 8 4 2 1
25 ' 4 3 2 1 0
26 '
30 ' Basic units of physical quant
31 ' Force: KG*M/S^2
32 ' Pressure: KG/(M*S^2)
33 ' Viscosity: KG/(M*S)
34 '
100 ' Define Units
101 ' ************
110 KG=1: MG=KG/1000
120 M=1: LT=M^3/1000
130 S=1: HR=3600*S
140 KV=1
160 JL=N*M: KWH=3.6E06*JL
199 GOTO 400
200 '
201 ' Variables
202 ' *********
205 B=2: PHI=.2: I=1E-3
206 YIX=100*M
210 V=1*M/S
220 A=I/(V/PHI)^B
230 Q=V*YIX
298 GOSUB 300
299 RETURN
300 '
301 ' Expression
302 ' **********
310 XSN=-SQR(A*Q^2/(I*PHI^2))
311 RETURN
400 '
401 ' Investigate units
402 ' *****************
405 GOSUB 200: OSN=XSN
410 KG=KG*2: GOSUB 201: PRINT "KG=";XSN/OSN: KG=KG/2
420 M=M*2: GOSUB 201: PRINT "M =" ; XSN/OSN: M=M/2
430 S=S*2: GOSUB 201: PRINT "S =";XSN/OSN: S=S/2
450 KV=KV*2: GOSUB 201: PRINT "KV=";XSN/OSN: KV=KV/2
500 LIST 20-29



V.
vrozos
Officer Cadet
Posts: 63
Joined: Mon Nov 21, 2011 12:36 pm
Location: Athens, Greece
Contact:

Check dimensions

Post by vrozos »

General

This program checks out the multiplication and addition between
matrices. More specifically, the program checks if the dimensions of
matrices follow the requirements of the operation and if so, it returns
the dimensions of the resulting matrix.

Instructions

First define the dimensions of matrices in lines 20-100. The
dimensions should be a string of three characters with the form "nxm"
("n" and/or "m" could be numbers or letters). Then define the
expression string in line 110. Only "*" and "+" can be used in this
program (parentheses cannot be processed). Run the program with RUN 10.

The matrices in lines 25-65 and the expression in 110 in this code
concern the Kalman filter (see http://en.wikipedia.org/wiki/Kalman_filter)


1 LIST 10-19
5 ' Evangelos Rozos Jan. 2012
11 ' This program investigates the
12 ' dimensions of matrices in
13 ' algebraic formulas.
14 '
15 ' Define matrices in lines
16 ' 20-99, define the expression in
17 ' line 110 (valid operands are +
18 ' and *). Run with RUN 10.
19 '
20 ' Define matrix dimensions
21 ' ************************
25 X$="nx1" ' n=no. of variables
35 Z$="ox1" ' o=no. of observations
40 E$=Z$
45 P$="nxn": Q$=P$: F$="nxn": FT$=F$
55 H$="oxn": HT$="nxo"
60 R$="oxo": S$=R$
65 K$="nxo"
100 '
101 ' Expression
102 ' **********
110 XSN$= H$ + "*" + P$ + "*" + HT$ + "+" + R$
200 '
201 ' Parse multiplications
202 ' *********************
205 LR$=MID$(XSN$,1,1)
207 LC$=MID$(XSN$,3,1)
210 FOR II=3 TO LEN(XSN$)-3 STEP 4
220 : OPER$=MID$(XSN$,II+1,1)
230 : RR$=MID$(XSN$,II+2,1)
240 : RC$=MID$(XSN$,II+4,1)
250 : IF OPER$="*" THEN GOTO 300
255 : IF OPER$<>"+" THEN GOTO 600
260 : XPN$=XPN$+LR$+"x"+LC$+"+"
270 : LR$=RR$: LC$=RC$
280 NEXT
290 XPN$=XPN$+LR$+"x"+LC$
295 GOTO 400
300 '
301 ' Check multiplication
302 ' ********************
305 IF LC$=RR$ THEN GOTO 335
307 IF LR$="1" AND LC$="1" THEN GOTO 333
310 PRINT "Multiplication error!"
315 PRINT "LCOL,RROW="LC$","RR$
330 END
333 LR$=RR$
335 LC$=RC$
340 GOTO 280 ' RETURN
400 '
401 ' Parse additions
402 ' ***************
403 IF LEN(XPN$)=3 THEN GOTO 498
405 LR$=MID$(XPN$,1,1)
407 LC$=MID$(XPN$,3,1)
410 FOR II=3 TO LEN(XPN$)-3 STEP 4
420 : OPER$=MID$(XPN$,II+1,1)
430 : RR$=MID$(XPN$,II+2,1)
440 : RC$=MID$(XPN$,II+4,1)
460 : GOSUB 500
470 NEXT
497 '
498 PRINT "Result is "LR$"x"RC$
499 END
500 '
501 ' Check addition
502 ' **************
505 IF LC$=RC$ AND LR$=RR$ THEN GOTO 535
510 PRINT "Addition error!"
515 PRINT "Left is "LR$"x"LC$
517 PRINT "Rght is "RR$"x"RC$
530 END
535 RETURN
600 '
601 PRINT "Invalid operand!"
602 END


V.
User avatar
Dbug
Site Admin
Posts: 4437
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: Check dimensions

Post by Dbug »

vrozos wrote:14 ' Run the program with RUN 10.
I believe you must have changed the program but forgot to change that :)
vrozos
Officer Cadet
Posts: 63
Joined: Mon Nov 21, 2011 12:36 pm
Location: Athens, Greece
Contact:

Post by vrozos »

This is why last minute changes should always be followed by a thorough
check :(

Dbug is right, of course. Line 14 should be:
14 ' Run the program with RUN 11.
or change line 11 to be line 10.


BTW, if you find these programs useful then you may want to run them
directly from your prompt without the Oric-nostalgia thing. With minor
modifications (replace single quotes (') with REM, remove the lines that
do LIST) you can use VintageBasic (http://www.vintage-basic.net/) for
this reason. An extra advantage of using VintageBasic is that some of the
restrictions of the Oric variables' naming are lifted.

V.
Post Reply