Thursday, November 28, 2019

BASIC vs SMALL BASIC 2020 Edition!!!

BASIC vs SMALL BASIC 2020 Edition!!!




So, here is an iterated logistic difference equation that I've posted about before showing animal population growth. I'm re-posting the old-timey BASIC version...and at the bottom giving the year 2019/2020 SMALL BASIC version that you can pop into Microsoft's still up and running (!) Small BASIC online app (there is a downloadable version too!).



First the original old-timey BASIC from 1980s version:

If you run it on an online BASIC simulator it works. For this, an online simulator works fine. Try this one:  https://repl.it/repls/InsignificantTepidEquipment


If you type "2" as your input the population hovers at around half an animal. If you type "5" as your starting population it goes to infinity (which is an error). So you need numbers less than 4 to keep it running true. The population levels out if you put in 1.5 as a start:


10 N=.1
20 INPUT"VALUE OF R";R
30 FOR I=1 TO 30
40 N1=R*N*(1-N)
50 PRINT N1
60 N=N1
70 NEXT I




Here is the screen capture of it in action:


Infinity: that's a lot of kitties! But an error in the program of going too high (R=5).

So here is R = 3.999





SMALL BASIC YEAR 2020 VERSION:


There is a new version of BASIC from Microsoft available as a download or an online simulator here: https://smallbasic-publicwebsite.azurewebsites.net/

It's called Small Basic...and the language is different!!! I had to use my mind-brain for about 2 minutes to port the program over (copy/paste, delete line numbers, search and find new variable command words like "textwindow.readnumber", etc.)


Here's a cut and paste version of the above script in the new language (it works, but doesn't give as many lines of results):

N=0.1
TextWindow.Write("What is the value of R? ")
R = TextWindow.ReadNumber()
FOR I=1 TO 30
N1=R*N*(1-N)
TextWindow.WriteLine("The result it " + N1 + ".")
N=N1
ENDfor

Each one of these lines is a seperate line in Small Basic (just number them 1, 2, 3, etc.) like this screenshot:

Oddly, it cannot handle decimals for the R value, so here is R=5:



Fun in (Small) BASIC for the year 2020!!!!!!!!!!!

How did I actually convert it? I pasted my old BASIC program into the new Microsoft Small Basic online window. It gave errors on almost every line.

Then I posted at the end a working program.

Then I compared them visually to see how they do know what they used to do and what new words (commands) did those things.  Old-timey "Print" became that "Textwindow.WriteLine" thing. Also, at the last line you must write "ENDfor" or else it won't run. Annoying but neat.

One day maybe I'll do the Fractal Mandelbrot program in the new Small Basic language.


Here's a cool modification that won't crash your computer since Small BASIC is modern:

N=0.1
TextWindow.Write("What is the value of R? ")
R = TextWindow.ReadNumber()
FOR I=1.00 TO 100.00
N1=R*N*(1-N)
TextWindow.WriteLine("The result it " + N1 + ".")
N=N1
ENDfor

See above, make the 4th line say "FOR I=1.00 to 100.00" and it will run a longer amount of lines.
You can make the second number 5000 and watch your computer just spew out the maths.

After a couple runs you need to copy and paste your program in again, it will stop working.
Of course, I wasn't saving and loading (or compiling) the program, just make changes. Copy,
click to reload the online simulator, re-paste in your program and make any changes. Annoying!
But fun.




-Happy Thanksgiving 2019!!!!