onlinecompiler.io

Octave online compiler

Write Octave 11 code below and run it free, with input, in a sandbox on our servers. No sign-in, no ads. The same compiler is an API and an embeddable editor, for running Octave in your own app, course or docs.

Também em portuguêsTambién en español

Share gives a link, no account needed. Save keeps it in your account.

Run Octave from your own app, bot or course. One API call returns the output, errors, exit code and run time. Free up to 100,000 runs a month, commercial use included, no card.

Checking a solution against several inputs? The Octave online compiler with test cases runs them all at once and marks each one passed or failed.

Octave examples: matrices, equations, statistics, plots and symbolic math

Solve a system of linear equations with the backslash operator, as in MATLAB. A line without a semicolon prints its value.

% Solve a system of linear equations: A x = b
A = [2 1 -1; -3 -1 2; -2 1 2];
b = [8; -11; -3];
x = A \ b

% Transpose, determinant and eigenvalues
At = A'
d = det(A)
e = eig([2 1; 1 2])'

It prints:

x =

   2
   3
  -1

At =

   2  -3  -2
   1  -1   1
  -1   2   2

d = -1.0000
e =

   1   3

Numbers from the Input tab: fgetl(stdin) reads a line, and str2num turns it into a vector.

data = str2num(fgetl(stdin));
printf('n = %d\n', numel(data));
printf('mean = %.2f\n', mean(data));
printf('median = %.2f\n', median(data));
printf('std = %.2f\n', std(data));
printf('max = %d\n', max(data));

With 12 15 11 19 23 15 17 in the Input tab it prints:

n = 7
mean = 16.00
median = 15.00
std = 4.12
max = 23

Plots come back as images: every figure still open when the program ends is returned as a PNG, here figure-1.png.

x = linspace(0, 2*pi, 100);
plot(x, sin(x), x, cos(x));
legend('sin', 'cos');
title('sin and cos');

The symbolic package differentiates, integrates and solves, as MATLAB's syms does:

pkg load symbolic
syms x
df = diff(x^3 + 2*x)
F = int(x^2, x)
s = solve(x^2 - 4 == 0, x)

It prints:

df = (sym)

     2
  3⋅x  + 2

F = (sym)

   3
  x
  ──
  3

s = (sym 2×1 matrix)

  ⎡-2⎤
  ⎢  ⎥
  ⎣2 ⎦

What runs your code

VersionOctave 11
Compiled withNo separate step: the run command compiles or interprets it
Run withoctave-cli --quiet --no-init-file --no-history code.m
Limits30 seconds, 512 MB of memory (up to 2 GB through the API on Pro and above), 2 CPUs, 64 KB of output per stream, no network
Typical run1.27 s, and 1.92 s for the slowest 1 in 20 (how we measured)

Good to know

  • Runs with octave-cli 11, the free MATLAB-compatible language. A line without a semicolon prints its value, as in MATLAB.
  • A file that starts with function is taken as a function file, so put another statement first, such as 1;. Define functions before the line that calls them: MATLAB's local functions at the end of a script don't work.
  • fgetl(stdin), input('') and scanf read from the Input tab. Plots work: every figure still open when the program ends comes back as a PNG image (figure-1.png, figure-2.png and so on), and print or saveas into $OUTPUT_DIR saves one yourself, next to data files such as a CSV.

Octave compiler API

To run Octave from your own app, send the code and its input to the sync endpoint with an API key, and the output comes back in the response. It's free up to 100,000 runs a month, with no credit card: get a free API key. The API docs cover the async endpoint with callbacks and every response field.

Terminal
curl -X POST https://api.onlinecompiler.io/api/run-code-sync/ \
  -H "Authorization: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "compiler": "octave-11",
    "code": "name = fgetl(stdin);\nprintf('\''Hello, %s!\\n'\'', name);",
    "input": "Ada"
  }'

The response has output ("Hello, Ada!\n" here), error, exit_code, time and memory.

Embed a Octave compiler in your website

The editor above is the embeddable widget. Add the script and a div with your widget key, and your readers can edit and run the code without an account:

example.html
<script src="https://onlinecompiler.io/widget.js"></script>

<div class="runcode" data-key="YOUR_WIDGET_KEY" data-lang="octave-11">
  <script type="text/plain">
    name = fgetl(stdin);
    printf('Hello, %s!\n', name);
  </script>
  <a data-credit href="https://onlinecompiler.io/">Runs on OnlineCompiler.io</a>
</div>

On a platform that takes an iframe but not a script, such as many course sites, use the iframe embed. For Docusaurus, MkDocs, Sphinx and Mintlify, see runnable code examples in docs.

Other languages

Python, C, C++, Java, C#, F#, Go, Rust, PHP, Ruby, Haskell, TypeScript, JavaScript, SQL, DuckDB, Bash, Fortran, Visual Basic, Kotlin, R, Swift, COBOL, Perl, Julia, Pascal, Assembly, Lua, OCaml, Common Lisp, Erlang, Elixir, Prolog, D, FreeBASIC, Dart, Clojure, Groovy, Scala, Zig, Nim, Crystal, Ada, PowerShell, Racket, Objective-C.

Frequently asked questions

Is this Octave online compiler free?

Yes. Running Octave on this page needs no account and shows no ads. To run Octave from your own app or site, the API and the widget are free up to 100,000 runs a month, commercial use included.

Is there a Octave compiler API?

Yes. POST the code, the compiler id octave-11 and any input to https://api.onlinecompiler.io/api/run-code-sync/ with an API key, and the response holds the output, errors, exit code, run time and memory. It's free up to 100,000 runs a month, and the same key works for the other 45 languages.

Can my Octave program read input?

Yes. Type it in the Input tab before you run, and the program reads it from standard input. The whole input is sent when you press Run, so a program can't ask for more while it runs.

Can I use Octave libraries?

Octave's built-in functions, and the symbolic package (pkg load symbolic, with SymPy) for derivatives, integrals and equations. Other Octave Forge packages, such as signal and statistics, aren't installed, and programs have no network access.

Can I run MATLAB code here?

Most core MATLAB code runs in Octave: matrices, indexing, A\b, loops, disp and printf. Plots come back as images, and pkg load symbolic gives you syms, diff, int and solve. Other toolbox functions don't, and functions must be defined before the line that calls them, not at the end of the script.

How do I read numbers from the Input tab?

fgetl(stdin) reads the next line as text, and str2num turns a line such as 12 15 11 into a vector, as in the statistics example above. input('') reads a line too.

Can I share or save my code?

Yes. Share gives you a link that anyone can open and run, lasts 90 days and needs no account. Save keeps the code in your OnlineCompiler.io account until you delete it. When you are signed in, each run you make on this page is also kept in your account's run history.

How long can a program run?

Up to 30 seconds, with 512 MB of memory (up to 2 GB through the API on Pro and above) and 2 CPUs. A program still running at 30 seconds is stopped with exit code 124, and output over 64 KB per stream is cut.

Where does my code run?

On our servers, in a fresh gVisor sandbox with no network access that is deleted when the run ends. Each run is kept in execution history with its output; the security page says what is stored.