Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

MATLAB & GNU Octave  Module 1 – Start here: MATLAB, Octave and a working setup

Install GNU Octave 11.3 and run your first script

Install GNU Octave 11.3 on Windows, macOS or Linux, check its version and BLAS, run scripts from a terminal, read exit codes and control startup files.

  • Beginner
  • 25 minutes
  • Examples run with octave 11.3.0 and Python 3.14.8
  • By MySmartCoPilot
Free lesson, Pro answers: 25 minutes
Free: the whole lesson. With a pass: the model answers to its 2 interview questions.

What you will learn

  • Install Octave 11.3 on Windows, macOS or Linux and confirm the version and BLAS in use
  • Start the GUI or the command line and run a script file and a one-line command
  • Use exit codes so that other programs and continuous integration can run your scripts
  • Configure startup files and know when to skip them

Before you start

What you’ll learn · Before you start

What you will learn

  • Install Octave 11.3 on Windows, macOS or Linux and confirm the version and BLAS in use
  • Start the GUI or the command line and run a script file and a one-line command
  • Use exit codes so that other programs and continuous integration can run your scripts
  • Configure startup files and know when to skip them

Before you start

On this page

A script that computes the stress in a 12 mm steel rod pulled by 15 kN should print 132.6 MPa on your computer, on a classmate’s and on the server that checks your coursework. Getting there takes an Octave installation, a way to run the file, and two habits that keep runs repeatable: reading the exit status, and knowing which startup files ran first.

Below you install Octave 11.3 on Windows, macOS or Linux, check its version and maths library, run a script from a terminal as a file and as a line of code, use exit codes so that other programs can tell whether a script worked, and see how one line in a startup file changes what a script prints.

Windows uses an installer, macOS and Linux a package manager

Find the row for your system. Each route installs Octave 11.3.0, the version every example of this track ran on, or a distribution’s own build, which may be older:

Your system How to install Octave
Windows, 64-bit octave-11.3.0-w64-installer.exe from octave.org/download, about 540 MB
macOS Homebrew: brew install octave; MacPorts: sudo port install octave
Debian or Ubuntu sudo apt install octave
Fedora sudo dnf install octave
Any Linux Flathub: flatpak install flathub org.octave.Octave

Windows. Run the installer and follow its steps; it creates the shortcuts that start Octave. The download page also offers the same build as a .zip or .7z archive, and builds marked w64-64, which pay off only for arrays of more than about two billion elements on computers with more than about 32 GB of memory. 32-bit Windows is no longer supported.

macOS. octave.org offers no Mac installer of its own: the Octave wiki recommends package manager: A program that installs, updates and removes software with one command from a repository of packages, such as Homebrew on macOS or apt on Ubuntu., Homebrew first, after the command-line developer tools (sudo xcode-select --install). Homebrew’s octave formula depends on about thirty other formulae, among them OpenBLAS, Qt and FFTW, which bring their own, so allow time and disk space for the first install.

Linux. Each distribution packages Octave itself, so its version can trail the latest release; when it is too old, the wiki points to Flathub, whose org.octave.Octave is version 11.3.0, or to the container images of gnuoctave/octave.

One Octave for the whole course

Install the same version as everyone you share code with, and check it as the next section shows. Two installations of different major versions can disagree on what a script accepts, as the news for each version lists.

Checkpoint

Check: Installing Octave on your system

  1. Question 1 of 2 octave.org has no installer of its own for macOS. How does the Octave wiki recommend installing Octave on a Mac?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: With Homebrew, brew install octave, or with MacPorts

    On a Mac, Octave comes from a package manager: brew install octave with Homebrew, or sudo port install octave with MacPorts, after sudo xcode-select --install.

  2. Question 2 of 2 Your Linux distribution packages an older Octave, and the course needs 11.3. What does the Octave wiki suggest?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: A distribution-independent build, such as Flathub's org.octave.Octave

    Distribution packages may trail the latest release. Flathub (flatpak install flathub org.octave.Octave) offers 11.3.0 on any Linux, and the wiki also names container images.

Check the version and the maths library before anything else

A script that prints what it is running on answers the first questions anyone asks about a problem. This one runs in Octave only, because MATLAB has neither OCTAVE_VERSION nor compare_versions, and it asks version('-blas') and version('-lapack') for the maths libraries:

check_setup.m: version, BLAS and LAPACK (Octave-only) M · check_setup.m
% check_setup.m: which Octave is this, and which maths libraries does it use?
% Octave-only: MATLAB has no OCTAVE_VERSION or compare_versions.
fprintf('Octave version: %s\n', OCTAVE_VERSION);
fprintf('BLAS:   %s\n', version('-blas'));
fprintf('LAPACK: %s\n', version('-lapack'));
if compare_versions(OCTAVE_VERSION, '11.1.0', '>=')
  disp('Ready: this is Octave 11.1.0 or later.');
else
  disp('Too old: install Octave 11 for this track.');
  exit(2);
end
check_setup.m, run with GNU Octave 11.3.0 Python · check_setup_session.py
from session import run, version

version()
run("""
octave-cli check_setup.m
""")

Output

# GNU Octave (aarch64-apple-darwin25.4.0) version 11.3.0
$ octave-cli check_setup.m
Octave version: 11.3.0
BLAS:   OpenBLAS (config: OpenBLAS 0.3.34 DYNAMIC_ARCH NO_AFFINITY USE_OPENMP vortexm4 MAX_THREADS=56)
LAPACK: Linear Algebra PACKage Version 3.12.0
Ready: this is Octave 11.1.0 or later.

Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 check_setup_session.py

The version line says 11.3.0, and compare_versions confirmed that it is at least 11.1.0. The BLAS: Basic Linear Algebra Subprograms: the library of vector and matrix routines that Octave calls for matrix operations. version('-blas') names the one in use, such as OpenBLAS. line names the library that does the heavy work of matrix operations, OpenBLAS 0.3.34 here, and the LAPACK line the library for solving systems and other linear algebra built on it. On another computer these lines may name other libraries or versions: they are what to compare first when the same script runs faster or prints slightly different last digits elsewhere.

If the version were older than 11.1.0, the script would print a message and end with exit(2), a status that a program running the check can read, as the section on exit codes shows.

Checking the version by its first character

v = OCTAVE_VERSION; v(1) >= '9' compares single characters, so it fails as soon as a version has two digits: '1' is less than '9' although 11 is more than 9, and Octave 11.3 answers 0. compare_versions(OCTAVE_VERSION, '11.1.0', '>=') compares the numbers part by part.

Checkpoint

Check: Checking the version and BLAS

  1. Question 1 of 2 What does version('-blas') tell you?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: Which BLAS library Octave uses for matrix operations, such as OpenBLAS 0.3.34

    version('-blas') names the BLAS library and its configuration: "OpenBLAS (config: OpenBLAS 0.3.34 …)" on the Mac that ran this track. It is one of the first things to compare when two computers disagree.

  2. Question 2 of 2 What does compare_versions('9.4.0', '11.1.0', '>=') return?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: 0, because 9.4.0 is older than 11.1.0

    compare_versions splits each version into numbers and compares them in order: 9 against 11 decides it, so the answer is 0. A comparison of the text would get it wrong.

Three ways to run a script, and what Octave does with each

Octave is one program with two front doors. octave --gui opens its graphical window, with an editor and a command window, and the Windows installer adds shortcuts for the window and for the command line. In a terminal, octave starts the command line unless you add --gui, and octave-cli is the same interpreter without the graphical window, made for terminals and scripts. Follow one run of the rod script through Octave:

Interactive · stage by stage From a command to an exit status Step through one run of octave-cli first_script.m, then the two other ways a run can go.
From a command to an exit status, step 7 of 7. Showing You type the command, Octave starts, Startup files run, The script runs (prints 132.6 MPa), Octave exits (with an exit status). In focus: skip, The script runs.with --no-init-allerror: status 1You type the commandoctave-cli first_script.mOctave startsloads the interpreterStartup files runsite files, then .octavercThe script runsprints 132.6 MPaOctave exitswith an exit status

The drawing shows the whole scene; its 7 steps are listed below.

Every step as text
  1. The command. You type octave-cli first_script.m in a terminal and press Enter. The file name tells Octave what to run.
  2. Octave starts. Octave loads its interpreter and sets up its search path. This takes a moment every time, so related calculations belong in one script, not one start each.
  3. Startup files. Before your script, Octave runs its startup files, if they exist, the installation's site files first, then ~/.octaverc in your home folder, then .octaverc in the current folder.
  4. Your script. The script runs from its first line to its last. first_script.m prints the cross-section, 113.1 mm^2, and the stress, 132.6 MPa.
  5. Status 0. No line raised an error, so Octave exits with status 0, which tells the terminal, or a program that started Octave, that the run succeeded.
  6. After an error. Had a line raised an error, Octave would have printed it and exited with status 1. A script can also end Octave on purpose with exit(n), and the status is then n.
  7. No startup files. With --no-init-all, Octave skips every startup file and goes straight from starting to your script, so the run depends on no one's settings.

Here is the script. It converts millimetres to metres, computes the area of the cross-section and divides the force by it:

first_script.m: the stress in a steel rod M · first_script.m
% first_script.m: the axial stress in a steel rod pulled by a force.
force_kN = 15;                          % pulling force, kilonewtons
diameter_mm = 12;                       % rod diameter, millimetres
area_m2 = pi * (diameter_mm / 1000)^2 / 4;
stress_MPa = force_kN * 1e3 / area_m2 / 1e6;
fprintf('Cross-section: %.1f mm^2\n', area_m2 * 1e6);
fprintf('Axial stress:  %.1f MPa\n', stress_MPa);

The same script, run from a terminal as a file and as code, and a one-line calculation:

Running a script from a terminal, GNU Octave 11.3.0 Python · first_script_session.py
from session import run, version

version()
run("""
octave-cli first_script.m
octave-cli --eval "first_script"
octave-cli -e "disp(pi * 0.012^2 / 4)"
""")

Output

# GNU Octave (aarch64-apple-darwin25.4.0) version 11.3.0
$ octave-cli first_script.m
Cross-section: 113.1 mm^2
Axial stress:  132.6 MPa
$ octave-cli --eval "first_script"
Cross-section: 113.1 mm^2
Axial stress:  132.6 MPa
$ octave-cli -e "disp(pi * 0.012^2 / 4)"
1.1310e-04

Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 first_script_session.py

  • octave-cli first_script.m runs the file and exits when it ends.
  • octave-cli --eval "first_script" evaluates a line of code and exits. A script’s name, without .m, runs the script of that name in the current folder.
  • octave-cli -e "…" is the short form of --eval, new in Octave 10, here with a one-line calculation of the area: 1.1310e-04 square metres.

Both runs of the script printed 132.6 MPa, and the one-line area is the script’s 113.1 mm^2, written in square metres. octave --no-gui first_script.m runs the same file through the octave program, without its window.

Options new in Octave 10

Octave 10 added -e, and the --no-init-all and --init-trace options that the section on startup files uses. On an older Octave, such as a distribution’s own package, write --eval for -e, and -f, also spelled --norc, for --no-init-all.

Stress, Strain & Young's Modulus Calculator Enter a 15 kN axial force on a 12 mm round bar and compare its stress with the 132.6 MPa above.

Checkpoint

Check: Running a script from a terminal

  1. Question 1 of 2 What does octave-cli --eval "first_script" do, run in the folder that holds first_script.m?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: It evaluates the name, which runs the script first_script.m, and exits

    --eval runs a line of code and exits. The code here is the name of a script in the current folder, so the script runs, printing 132.6 MPa, and Octave exits.

  2. Question 2 of 2 Which option, new in Octave 10, is the short form of --eval?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: -e

    Octave 10 added -e for --eval, -g for --gui and -G for --no-gui, and the option --no-init-all.

Exit codes tell other programs whether a script worked

A person reads the output; a program reads the exit status: The number a program hands back when it ends: 0 for success, any other number for a failure. Shells and automated jobs read it to decide what to do next., the number every program returns when it ends: 0 for success, anything else for failure. rod_check.m stops with an error when the stress is above a limit, 250 MPa in this example:

rod_check.m: an error when the stress is too high M · rod_check.m
% rod_check.m: stops with an error when the stress in the rod is too high.
% Set force_kN before it runs:  octave-cli --eval "force_kN = 15; rod_check"
diameter_mm = 12;
limit_MPa = 250;                        % the allowed stress in this example
stress_MPa = force_kN * 1e3 / (pi * (diameter_mm / 1000)^2 / 4) / 1e6;
fprintf('Force %g kN: stress %.1f MPa\n', force_kN, stress_MPa);
if stress_MPa > limit_MPa
  error('Stress %.1f MPa is above the %d MPa limit', stress_MPa, limit_MPa);
end
disp('Within the limit');
ask_rods.m: a script that asks a question M · ask_rods.m
% ask_rods.m: asks a question, which an automated run cannot answer.
n = input('How many rods? ');
fprintf('Checking %d rods\n', n);
Exit statuses of octave-cli, GNU Octave 11.3.0 Python · exit_codes_session.py
from session import run, version

version()
run("""
octave-cli --eval "force_kN = 15; rod_check"
!octave-cli --eval "force_kN = 40; rod_check"
octave-cli --eval "force_kN = 40; rod_check" || echo "rod_check failed: stopping here"
!octave-cli --eval "exit(3)"
!octave-cli ask_rods.m
""")

Output

# GNU Octave (aarch64-apple-darwin25.4.0) version 11.3.0
$ octave-cli --eval "force_kN = 15; rod_check"
Force 15 kN: stress 132.6 MPa
Within the limit
$ octave-cli --eval "force_kN = 40; rod_check"
Force 40 kN: stress 353.7 MPa
error: Stress 353.7 MPa is above the 250 MPa limit
error: called from
    rod_check at line 8 column 3
[exit status 1]
$ octave-cli --eval "force_kN = 40; rod_check" || echo "rod_check failed: stopping here"
Force 40 kN: stress 353.7 MPa
error: Stress 353.7 MPa is above the 250 MPa limit
error: called from
    rod_check at line 8 column 3
rod_check failed: stopping here
$ octave-cli --eval "exit(3)"
[exit status 3]
$ octave-cli ask_rods.m
How many rods? error: input: reading user-input failed!
error: called from
    ask_rods at line 2 column 1
[exit status 1]

Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 exit_codes_session.py

At 15 kN the check passed and the status was 0, so the session shows none. At 40 kN the stress, 353.7 MPa, broke the limit: error printed the message and where it happened, and Octave exited with status 1. The third command is how other programs use that: in a shell, || runs what follows only when the command before it fails. exit(3) ends Octave with the status 3, which lets a script report different kinds of failure.

The last run shows a trap. input waits for someone to type an answer, and when no one can, as in an automated run with its input closed, Octave stops with reading user-input failed! and status 1. That is the right outcome: a script for continuous integration: Running a project's checks automatically on every change, on a service or server, so that a check ending with a non-zero exit status stops the change. should never ask questions, and a closed input, such as < /dev/null after the command in a macOS or Linux shell, makes such a script fail at once instead of waiting.

MATLAB works the same way when it is started with -batch: MathWorks documents that it exits with status 0 when the code runs and with a non-zero status when it fails. In PowerShell the status of the last program is in $LASTEXITCODE, and in a macOS or Linux shell in $?.

Key idea

An uncaught error makes octave-cli exit with status 1 and exit(n) with status n, so a script signals failure without anyone reading its output.

Checkpoint

Check: Exit codes

  1. Question 1 of 2 With force_kN = 40, rod_check.m stops with an error. What exit status does octave-cli return?

    Type a number.

    A hint

    Look at the line after the error in the recorded run.

    Show the answer: Question 1 of 2

    Answer: 1

    An uncaught error ends octave-cli with status 1, which the session showed as [exit status 1]. exit(n) gives other statuses on purpose.

  2. Question 2 of 2 In a shell, when does the echo run in octave-cli --eval "force_kN = 40; rod_check" || echo "rod_check failed"?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: Only when octave-cli exits with a non-zero status

    The shell reads the exit status, not the printed error: status 1 counts as a failure, so the echo after || runs. In the recorded run, "rod_check failed: stopping here" appeared for that reason.

Startup files run before your script, so checks skip them

The flow above showed Octave running startup files before your script. A startup file: A file of commands that Octave runs every time it starts, before anything else, such as ~/.octaverc or a .octaverc in the current folder. MATLAB's is startup.m. is a script Octave runs every time it starts, and a single line in one changes what every script prints. This session writes format long into a .octaverc in the current folder and runs the same two-line script three times:

show_area.m: the cross-section in square metres M · show_area.m
% show_area.m: the cross-section of a 12 mm rod, in square metres.
area_m2 = pi * 0.012^2 / 4
A startup file at work, GNU Octave 11.3.0 Python · startup_session.py
from session import run, version

version()
run("""
printf 'format long\\n' > .octaverc
octave-cli show_area.m
octave-cli --no-init-all show_area.m
octave-cli --init-trace show_area.m
""")

Output

# GNU Octave (aarch64-apple-darwin25.4.0) version 11.3.0
$ printf 'format long\n' > .octaverc
$ octave-cli show_area.m
area_m2 = 1.130973355292325e-04
$ octave-cli --no-init-all show_area.m
area_m2 = 1.1310e-04
$ octave-cli --init-trace show_area.m
executing commands from /opt/homebrew/Cellar/octave/11.3.0_1/share/octave/site/m/startup/octaverc ... done.
executing commands from /opt/homebrew/Cellar/octave/11.3.0_1/share/octave/11.3.0/m/startup/octaverc ... done.
executing commands from .octaverc ... done.
area_m2 = 1.130973355292325e-04

Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 startup_session.py

With the startup file, the area showed 16 significant digits, 1.130973355292325e-04. With --no-init-all, which skips every startup file, it showed the default five, 1.1310e-04. The value is the same; only its display changed, yet a classmate without your .octaverc sees other output, and a check that compares printed text fails. --init-trace, new in Octave 10, lists the files that ran: the two site files of the installation, then .octaverc.

Octave reads, in order: the site files of the installation, a per-user file in your configuration folder, ~/.octaverc in your home folder, .octaverc in the current folder, and a startup.m for MATLAB-style setups, though its manual prefers ~/.octaverc. MATLAB runs a startup.m that it finds on its search path, and MathWorks advises against putting cd commands in it. Three options control the Octave files: --no-init-all skips them all, --no-init-user only yours, --no-init-site only the installation’s.

Putting a script's settings in your startup file

format long, addpath or cd in ~/.octaverc make your scripts work on your computer only. Put what a script needs into the script, keep startup files for personal comfort, and run every check with --no-init-all.

Checkpoint

Check: Startup files

  1. Question 1 of 2 With format long in a .octaverc, show_area.m printed area_m2 = 1.130973355292325e-04. What does it print when Octave skips startup files?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: area_m2 = 1.1310e-04

    The startup file changed only the display. With --no-init-all the same value appeared as 1.1310e-04, which is what a classmate without your .octaverc sees.

  2. Question 2 of 2 Which option makes Octave skip every startup file, for a check that must not depend on anyone's settings?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: --no-init-all

    --no-init-all (also --norc or -f) reads no system or user startup file. --no-init-user and --no-init-site skip one kind each.

Practise: set up Octave and check it

Five steps on your own computer turn this lesson into a working setup; take them in this order:

  1. Install Octave for your system as the first section shows, and start octave-cli once to see it work.
  2. Save check_setup.m and run octave-cli check_setup.m. It should print your version and end with the Ready line.
  3. Save first_script.m and run it as a file, with --eval and, if you have Octave 10 or later, with -e. Each way should print 132.6 MPa.
  4. Save rod_check.m, run octave-cli --eval "force_kN = 40; rod_check", then echo $? in macOS or Linux, or echo $LASTEXITCODE in PowerShell, and confirm the status is 1.
  5. Put format long into a .octaverc in a test folder, run show_area.m with and without --no-init-all there, and delete the file afterwards.

Then test the five ideas of the page, from installing to startup files. The session picks your weakest idea first, shows one question at a time and tells you straight away why an answer is right or what it missed:

Practice that adapts to you

Practise this lesson

15 questions about 5 ideas of this lesson. Each answer is explained at once, and what you get right is kept in this browser.

  1. Question 1 of 15 Which download installs Octave 11.3 on 64-bit Windows, as octave.org recommends?

    Choose one answer.

    Show the answer: Question 1 of 15

    Answer: octave-11.3.0-w64-installer.exe

    On Windows the installer from octave.org/download is the usual route; a .zip or .7z holds the same build for unpacking by hand.

  2. Question 2 of 15 The Windows downloads include builds marked w64-64. When do they pay off?

    Choose one answer.

    Show the answer: Question 2 of 15

    Answer: For arrays of more than about two billion elements, on computers with more than about 32 GB of memory

    The w64-64 builds use 64-bit indices for linear algebra, which only helps with arrays above about two billion elements and more than about 32 GB of memory. Everyone else takes the w64 installer.

  3. Question 3 of 15 The same script stops with an error on a classmate's Ubuntu laptop but runs on your Octave 11.3. What do you compare first?

    Choose one answer.

    Show the answer: Question 3 of 15

    Answer: The Octave versions, with check_setup.m on both laptops

    Rule out the version first: run check_setup.m on both. If Ubuntu's package is older, install 11.3 from Flathub or use the same version as everyone you share code with.

  4. Question 4 of 15 What does version('-lapack') name?

    Choose one answer.

    Show the answer: Question 4 of 15

    Answer: The linear-algebra library for solving systems and similar work, LAPACK 3.12.0 on the recording Mac

    LAPACK is the library of linear-algebra routines, such as solving systems, built on the BLAS. check_setup.m prints both, because both decide how matrix work runs.

  5. Question 5 of 15 What does this print in Octave 11.3?

    Read the code, then choose one answer.

    v = OCTAVE_VERSION;
    disp(v(1) >= '9')
    Show the answer: Question 5 of 15

    Answer: 0

    v(1) is '1', the first character of '11.3.0', and '1' >= '9' is false. compare_versions compares the numbers instead and gets the right answer.

  6. Question 6 of 15 You run check_setup.m on a computer with Octave 10.3.0. What happens?

    Choose one answer.

    Show the answer: Question 6 of 15

    Answer: It prints the Too old line and exits with status 2

    compare_versions('10.3.0', '11.1.0', '>=') is false, so the script prints "Too old: install Octave 11 for this track." and calls exit(2), a status a program that runs the check can read.

  7. Question 7 of 15 Which command opens Octave's graphical window?

    Choose one answer.

    Show the answer: Question 7 of 15

    Answer: octave --gui

    octave --gui opens the window with its editor and command window; in a terminal, octave without --gui and octave-cli start the command line.

  8. Question 8 of 15 What does this command print, run with Octave 11.3?

    Read the code, then choose one answer.

    octave-cli -e "disp(pi * 0.012^2 / 4)"
    Show the answer: Question 8 of 15

    Answer: 1.1310e-04

    The command evaluates one line: the area of a 12 mm circle in square metres, 1.1310e-04, printed by disp without a name. It is the 113.1 mm^2 that first_script.m reported.

  9. Question 9 of 15 A shell loop starts octave-cli 500 times, once for each force value, to run rod_check. What is the better design?

    Choose one answer.

    Show the answer: Question 9 of 15

    Answer: One Octave run whose script loops over the 500 forces

    Starting Octave takes a moment each time, so related calculations belong in one script: a for loop over the 500 forces runs in one start.

  10. Question 10 of 15 What exit status does a program return when it succeeds?

    Type a number.

    Show the answer: Question 10 of 15

    Answer: 0

    0 means success; any other number means a failure. The session prints a status only when it is not 0.

  11. Question 11 of 15 An automated job runs ask_rods.m, which calls input(), with the job's input closed. What happens?

    Choose one answer.

    Show the answer: Question 11 of 15

    Answer: Octave stops at once with "reading user-input failed!" and exits with status 1

    The recorded run shows "error: input: reading user-input failed!" and status 1. A script for automated runs should never ask questions; closing its input makes such a mistake fail fast.

  12. Question 12 of 15 By MathWorks' documentation, which way of starting MATLAB runs a script without the desktop and exits with a non-zero status when it fails?

    Choose one answer.

    Show the answer: Question 12 of 15

    Answer: matlab -batch "rod_check"

    matlab -batch is MATLAB's way to run code from a script or a continuous-integration job: no desktop, status 0 on success and a non-zero status on failure.

  13. Question 13 of 15 Of the installation's site files, ~/.octaverc and .octaverc in the current folder, which does Octave run last?

    Choose one answer.

    Show the answer: Question 13 of 15

    Answer: .octaverc in the current folder

    The order is the site files, the per-user configuration file, ~/.octaverc, then .octaverc in the current folder, and startup.m for MATLAB-style setups.

  14. Question 14 of 15 Which option makes Octave list each startup file as it runs it?

    Choose one answer.

    Show the answer: Question 14 of 15

    Answer: --init-trace

    --init-trace, new in Octave 10, lists the startup files as they run: on the recording Mac, two site files and then the .octaverc of the current folder.

  15. Question 15 of 15 A colleague's script works only on their computer, and their ~/.octaverc contains addpath('~/tools'). What is the best fix?

    Choose one answer.

    Show the answer: Question 15 of 15

    Answer: Move the path setting into the project, and run checks with --no-init-all

    A startup file is personal. A script that needs a folder on the path should set it up itself, and a check run with --no-init-all shows at once whether it does.

Interview questions

Warm-up: how do you find out which Octave version and which BLAS a computer uses?

Run OCTAVE_VERSION for the version, or octave-cli --version in a terminal, and version('-blas') and version('-lapack') for the maths libraries: on the computer that ran this track’s examples they named Octave 11.3.0, OpenBLAS 0.3.34 and LAPACK 3.12.0. To check a minimum version in a script, use compare_versions(OCTAVE_VERSION, '11.1.0', '>='), which compares the numbers part by part, never the text. Put these lines in a small script such as check_setup.m and run it first on any new computer: when a result differs between two machines, different versions or libraries are the first thing to rule out. OCTAVE_VERSION and compare_versions are Octave-only; in MATLAB, version returns its own version text, such as 26.2.0.3341813 (R2026b).

Model answers open with any pass: ₹79 for 1 week ($2.99), one payment that never renews.

  1. Mid to senior

    A continuous-integration job runs your checks with octave-cli --eval "run_checks" | tee log.txt, and it passed although one check printed an error. What went wrong, and how do you make a failing check fail the job?

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page. First step and follow-ups

  2. Fresher to mid

    The same script prints 1.130973355292325e-04 on your laptop and 1.1310e-04 on a classmate's, and a third laptop differs in the last digit of a long calculation. Explain each difference and how you make the outputs comparable.

    Model answer, Pro. First step and follow-ups

Key takeaways

  • Windows users install Octave 11.3 with the installer from octave.org, macOS users with Homebrew or MacPorts, and Linux users with their distribution’s package or Flathub’s org.octave.Octave when that is too old.
  • OCTAVE_VERSION, version('-blas') and compare_versions tell you which Octave and which maths libraries a computer uses, and they are the first things to compare when two computers disagree.
  • octave-cli file.m runs a script file, octave-cli --eval "code" or, from Octave 10, -e runs a line of code, and octave --gui opens the graphical window.
  • An uncaught error makes Octave exit with status 1 and exit(n) with status n, so shells and continuous integration can tell success from failure; a script that calls input fails at once when its input is closed.
  • Startup files such as .octaverc run before every script and can change what it prints, so checks run with --no-init-all and scripts carry their own settings.

Terms in this lesson

BLAS
Basic Linear Algebra Subprograms: the library of vector and matrix routines that Octave calls for matrix operations. version('-blas') names the one in use, such as OpenBLAS.
continuous integration
Running a project's checks automatically on every change, on a service or server, so that a check ending with a non-zero exit status stops the change.
exit status
The number a program hands back when it ends: 0 for success, any other number for a failure. Shells and automated jobs read it to decide what to do next.
package manager
A program that installs, updates and removes software with one command from a repository of packages, such as Homebrew on macOS or apt on Ubuntu.
startup file
A file of commands that Octave runs every time it starts, before anything else, such as ~/.octaverc or a .octaverc in the current folder. MATLAB's is startup.m.

References

Related tools

Report a problem with this lesson

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.