How to use GNU Octave on awanbox, in your browser
GNU Octave is a free language for numbers, matrices and plots, close to MATLAB. On an awx computer it installs in under a minute and runs in your browser, with nothing to install on your laptop.
This walk-through is a real run on a new computer: install Octave, solve a set of equations, run a script that draws a plot, and open the Octave desktop app. Every screenshot and number below comes from that run.
What you need
- An
awxcomputer. Small is enough for Octave in the terminal; for the Octave desktop app, Large is more comfortable. We used a Large computer calledoctave-labwith an 8 GiB disk (see Create your first awx computer). - About a minute to install Octave, and about 700 MB of the computer’s disk.
Install Octave
Open the computer and go to the Terminal tab. Type:
sudo apt-get update && sudo apt-get install -y octave
On our computer the install itself took 24 seconds, after a few seconds of apt-get update. It installed GNU Octave 8.4.0 and used about 700 MB. You only do this once: Octave stays on the computer when it sleeps.
You can also ask the agent on the Chat tab: “Install GNU Octave on this computer.”
Your first calculations
Make a folder for your work and start Octave in the terminal:
mkdir ~/octave && cd ~/octave
octave-cli
Now solve three equations at once. Type each line and press Enter:
A = [4 -2 1; -2 4 -2; 1 -2 4];
b = [11; -16; 17];
x = A \ b
eig(A)
A \ b solves the equations; eig(A) gives the eigenvalues.A semicolon at the end of a line hides the answer; without it Octave prints it. Type exit to leave Octave.
A script that draws a plot
Most coursework lives in .m files. Save this as projectile.m in ~/octave. Write it with nano projectile.m in the terminal, upload it on the Files tab, or copy it with a file app:
% projectile.m: a ball thrown at 20 m/s and 45 degrees
g = 9.81; v = 20; theta = 45;
t = linspace(0, 2*v*sind(theta)/g, 200);
x = v*cosd(theta)*t;
y = v*sind(theta)*t - 0.5*g*t.^2;
figure();
plot(x, y, "LineWidth", 2); grid on;
xlabel("distance (m)"); ylabel("height (m)");
title("A ball thrown at 20 m/s, 45 degrees");
print("-dpng", "projectile.png");
printf("Range %.1f m, highest point %.1f m\n", max(x), max(y));
Octave needs a screen to draw a plot. Your awx computer has one: its desktop. Tell Octave to use it, then run the script:
export DISPLAY=:0
octave-cli projectile.m
projectile.png.Without export DISPLAY=:0, Octave stops with “print: rendering with fltk toolkit requires visible figure”. It may also print a short warning about a missing font or XDG_RUNTIME_DIR; the plot is fine. This is the picture it saved:
projectile.png, as Octave saved it. Download it from the Files tab.The Octave desktop app
Octave also has a desktop app with an editor, a list of your variables and a file browser, much like MATLAB’s. Start it from the terminal:
export DISPLAY=:0
octave --gui &
Then open the Desktop tab and press Take over to use it. The first time, Octave shows three welcome screens: press Next, leave the box about community news unticked if you like, then Finish. In the Command Window, type cd ~/octave and then projectile to run the script by its name. The plot opens in its own window:
When you leave the Desktop tab, the agent can use the screen again. The Octave app keeps running until you close it.
Add packages
Octave’s extra packages come from Ubuntu, so they install in seconds. For statistics:
sudo apt-get install -y octave-statistics
Load a package in Octave before you use it:
pkg load statistics
normcdf(1.96)
That printed 0.9750 on our computer. Loading the statistics package also prints a warning that it “shadows a core library function”; it is harmless. Other packages work the same way, for example octave-signal, octave-control and octave-symbolic.
Get your work in and out
- Files tab: upload
.mfiles and download plots and results. - A file app: WinSCP or Cyberduck, to drag a whole folder across (how).
- The agent: on the Chat tab, ask it to write, run or fix a script, for example “Write an Octave script in ~/octave that plots y = sin(x) and cos(x) from 0 to 2π and saves it as a PNG.”
Common questions
Is GNU Octave the same as MATLAB?
No, but its language is very close, so most MATLAB scripts for coursework run in Octave as they are or with small changes. Octave is free. Some MATLAB toolboxes have no Octave version; many have an Octave package instead.
Do I have to install Octave again every time?
No. Octave stays installed on your computer, with your scripts and plots, when the computer sleeps or you close the page. You install it once per computer.
Why do I get 'print: rendering with fltk toolkit requires visible figure'?
Octave needs a screen to draw a plot. In the awx terminal, run export DISPLAY=:0 first, so plots are drawn on your computer's desktop, and use figure() rather than a hidden figure.
Which computer size should I use for Octave?
Small is enough for Octave in the terminal. For the Octave desktop app and bigger plots, use Large, which has more memory and a desktop that feels quicker.
Cautions
- Running time uses credit on the Free plan, and the desktop app keeps the computer busy. Stop the computer when you are done.
- Memory. Very large matrices can fill a computer’s memory; if Octave is stopped, use Large or smaller data. See what happens when a computer runs out of memory.
- Keep your own copy of your scripts and results.
awxis in early alpha.
Keep reading
- How to copy files to awx with WinSCP or Cyberduck
- Python and Linux with a tutor beside you
- Small or Large: which size to choose
- How running time and credit work
Getting started
Sign in with your Google account, make a computer, and type the install line in its Terminal tab.
Awi, signing off.