Octave
Online Octave
main.m runs as a script in GNU Octave 9.4, the free MATLAB-compatible language. Most MATLAB code for numbers and matrices runs unchanged. Plots and figures need a window, which this playground doesn’t have.
Try it aboveHow Octave runs here
- Versions
- GNU Octave 9.4
- Run
octave-cli main.m- Limits per run
- 256 MB memory, 15 s of CPU time on half a core, 2 MB of output
- Time
- Up to 10 minutes a run (30 on a paid plan); waits 2 minutes for input (5 on a paid plan)
- Sandbox
- Each run gets its own Linux sandbox with no network access. Text files your program writes next to your code open as new tabs.
- Good to know
- No plots: there is no display.
An Octave script with matrices and input
This main.m reads a matrix typed in MATLAB syntax, then uses det, inv and the backslash operator to solve a system:
A = input('Enter a 2x2 matrix like [1 2; 3 4]: '); printf('Determinant: %g\n', det(A)); disp('Inverse:'); disp(inv(A)); x = A \ [5; 6]; printf('Solution of A*x = [5; 6]: x = [%g; %g]\n', x(1), x(2));
$ octave-cli main.m Enter a 2x2 matrix like [1 2; 3 4]: [2 1; 1 3] Determinant: 5 Inverse: 0.6000 -0.2000 -0.2000 0.4000 Solution of A*x = [5; 6]: x = [1.8; 1.4]
Reading input and printing
- input('prompt') evaluates what you type, so [1 2; 3 4] becomes a matrix and 2*pi a number. input('prompt', 's') returns the text as a string.
- printf and fprintf format output like C; disp prints a value without its name.
- A line without a semicolon prints its result, as ans = … or x = …. End lines with ; to keep the output clean.
What isn’t available here
- Plots: plot, figure and imshow need a display. Compute and print instead.
- MATLAB toolboxes and Simulink.
Errors you’ll see
- “error: operator +: nonconformant arguments (op1 is 1x3, op2 is 1x2)” The matrix sizes don’t match. Use .* and ./ for element-wise operations.
- “error: 'totl' undefined” A variable used before it’s set, or a typo.
Questions
Does MATLAB code run here?
Code for numbers, matrices and strings mostly does: Octave is MATLAB-compatible. Toolboxes, Simulink and plotting don’t.
Which Octave version is this?
GNU Octave 9.4, running main.m with octave-cli.
How do I read input in Octave?
x = input('Number: ') for a value or matrix, s = input('Name: ', 's') for text. Type it in the terminal while the script runs.