Maths and Algebra for 1K

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
User avatar
AN7805
Posts: 91
Joined: Fri Oct 16, 2020 4:17 am

Re: Maths and Algebra for 1K

Post by AN7805 »

Thanks Xav m(_ _)m

I have loaded this program on my 1k Zeddie and not working :oops:

Thanks again,

Matt
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Maths and Algebra for 1K

Post by XavSnap »

You can use 10 blocs with 8 characters.
But a "+" or "-" character is a bloc.

[9*2] [+] [15/3] [+] [4] [+] [12/4*2] [-] [3*5*2]

You can't add more chars in the V$ string … :mrgreen: memory error !!!
… 23 characters, no more.

Code: Select all

5 DIM A$(VAL "10",VAL "8")
10 LET V$="9*2+15/3+4+12/4*2-3*5*2"
15 LET B=PI/PI
16 LET C=B
17 LET I=B
20 FOR A=I TO LEN V$
30 IF V$(A)<>"+" AND V$(A)<>"-" THEN NEXT A
40 LET A$(B)=V$(C TO A-I)
42 LET B=B+I
45 IF A<LEN V$+I THEN LET A$(B)=V$(A)
46 LET B=B+I
47 LET C=A+I
48 NEXT A
49 LET A$(B-I)=V$(C TO)
50 LET R$=""
51 FOR A=I TO B-I-I 
60 IF A$(A,I)="+" OR A$(A,I)="-" THEN GOTO VAL"68"
65 PRINT A$(A);"=";VAL A$(A)
67 LET R$=R$+STR$ VAL A$(A)
68 LET R$=R$+("+" AND A$(A,I)="+")+("-" AND A$(A,I)="-")
70 NEXT A
80 PRINT ,,V$,R$;"=";VAL V$
1K.P
(552 Bytes) Downloaded 154 times
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
AN7805
Posts: 91
Joined: Fri Oct 16, 2020 4:17 am

Re: Maths and Algebra for 1K

Post by AN7805 »

m(_ _)m

Yes; after write the program my Zeddie said 2/10.

Matt 8-)
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Maths and Algebra for 1K

Post by dr beep »

I could make it in MC, assuming only integers occur, then it could be much bigger.
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Maths and Algebra for 1K

Post by dr beep »

The result of a calculation is always smaller in length than the calculation you read.
If you replace the calculation by the result you don't need to define 80 bytes in A$.
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Maths and Algebra for 1K

Post by XavSnap »

In this test, i was disappointed to discover (again?) the DIM command !
I use to program with many Basics, and, in my mind, this command assume the simply "DIM A$(10)" … was store in fixe length!

10 DIM A$(10)
20 LET A$(1)="A CAT"
30 LET A$(2)="A DOG"

10 LET A$(10)="A MAN"

Don't run : A$="AA A" !

:roll:
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Maths and Algebra for 1K

Post by XavSnap »


Code Meaning Situations
0 Successful completion, or jump to line number bigger than any existing. A report with code 0 does not change the line number used by CONT. Any

1 The control variable does not exist (has not been set up by a FOR statement) but there is an ordinary variable with the same name. NEXT

2 An undefined variable has been used.
For a simple variable this will happen if the variable is used before it has been assigned to in a LET statement.
For a subscripted variable it will happen if the variable is used before it has been dimensioned in a DIM statement.
For a control variable this will happen if the variable is used before it has been set up as a control variable in a FOR statement, when there is no ordinary simple variable with the same name.
Any

3 Subscript out of range.
If the subscript is hopelessly out of range (negative, or bigger than 65535) then error B will result.
Subscripted variables

4 Not enough room in memory. Note that the line number in the report (after the /) may be incomplete on the screen, because of the shortage of memory: for instance 4/20 may appear as 4/2. See chapter 23. For GOSUB see exercise 6 of chapter 14. LET, INPUT, DIM, PRINT, LIST, PLOT, UNPLOT, FOR, GOSUB. Sometimes during function evaluation.

5 No more room on the screen. CONT will make room by clearing the screen. PRINT, LIST.

6 Arithmetic overflow: calculations have led to a number greater than about 1038. Any arithmetic

7 No corresponding GOSUB for a RETURN statement. RETURN

8 You have attempted INPUT as a command (not allowed). INPUT

9 STOP statement executed. CONT will not try to re-execute the STOP statement. STOP

A Invalid argument to certain functions. SQR, LN, ASN, ACS

B Integer out of range. When an integer is required, the floating point argument is rounded to the nearest integer. If this is outside a suitable range then error B results.
For array access, see also report 3.
RUN, RAND, POKE, DIM, GOTO, GOSUB, LIST, LLIST, PAUSE, PLOT, UNPLOT, CHR$, PEEK, USR
Array access

C The text of the (string) argument of VAL does not form a valid numerical expression. VAL

D (i) Program interrupted by BREAK.
(ii) The INPUT line starts with STOP.
At end of any statement, or in LOAD, SAVE, LPRINT, LLIST or COPY.
INPUT

E Not used

F The program name provided is the empty string.



Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Maths and Algebra for 1K

Post by XavSnap »

On a 1K basic program, a LIST can hang or crash the computer. (no enought memory to create the D_File)
type CLS, CLEAR and RUN… no GOTO 1 to run it.

We had to clean the Vars, the D_file and all of RAM's artefacts.
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: Maths and Algebra for 1K

Post by XavSnap »

Tips:

-To avoid to fill the D_File, use PRINT AT NOT PI,NOT PI; AND SCROOL to clear the screen ! (NOT PI=0)
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Maths and Algebra for 1K

Post by dr beep »

Saving didn't work, but I have a screenshot.

I stored the result in V$, if you replace line 10 wih INPUT V$ you can add own formula's
Output is same as earlier version, in numbers that is, show a bit different.
My1K.jpg
Post Reply