Welcome to Nelson: a high-level, numerical computing language inspired by MATLAB(c)/Octave and designed for fast, productive engineering and scientific work.
This guide gives you a quick path from installation to running your first commands, writing scripts, plotting, and finding help. It’s intended for new users who want a working quickstart and a few ready-to-run examples.
This tutorial is organized as short lessons you can work through at the REPL or by running small script files.
Nelson is a high-level numerical computing language whose core data type is the array (vectors and matrices). Like MATLAB, Nelson focuses on interactive computing, visualization, and rapid prototyping. This tutorial helps you learn the essentials: REPL usage, basic math, plotting, arrays, scripts, and simple programming constructs.
nmm).nh5, .mat)This quick session shows how to start, perform simple calculations, and quit.
Open a terminal (PowerShell on Windows, bash/zsh on Unix) and run:
nelson
You will be presented with a prompt. This prompt accepts Nelson expressions.
At the prompt try:
a = 1 + 2 * 3
b = sin(pi/4)
If you don’t assign a variable, results are stored in the default variable ans.
Type:
quit
or use the REPL shortcut for exiting.
Variables are created with an assignment:
x = 2*pi
v = [1, 2, 3]
Nelson uses square brackets for vectors and semicolons to separate rows in matrices:
A = [1 2; 3 4]
Reassigning is allowed. To suppress immediate printing, terminate a statement with ;:
t = 5;
Typos produce an error — use the up-arrow to recall previous commands, edit them and re-run.
Use parentheses to control precedence:
(1+2)*3 % yields 9
1+2*3 % yields 7
Useful commands:
clear — remove all variableswho — list variable nameswhos — detailed list (size, type)save('s.nh5') — save workspace (HDF5 .nh5 default)load('s.nh5') — restore workspaceRecord all input/output with:
diary('session.txt')
diary off
Nelson provides a rich set of mathematical functions: sin, cos, tan, exp, log, sqrt, abs, and more. Constants such as pi, Inf, and NaN are available.
Examples:
y = exp(-5)*sin(2) + 10*sqrt(8)
log(142)
sin(pi/4)
To plot data, prepare x and y vectors and call plot:
x = linspace(0, 2*pi, 201)
y = sin(x)
plot(x, y)
xlabel('x')
ylabel('sin(x)')
title('Sine')
Multiple data sets:
plot(x, 2*cos(x), '--', x, cos(x), '-', x, 0.5*cos(x), ':')
legend('2*cos(x)', 'cos(x)', '0.5*cos(x)')
Line styles, colors and markers follow common short codes: r, b, k, --, :, o, *, etc.
Row vector:
v = [1 4 7 10]
Column vector:
w = [1; 4; 7; 10]
Transpose:
w = v'
Indexing and submatrices:
v(1:3) % elements 1 to 3
A(2,:) % second row
A(:,2:3) % columns 2 and 3
Colon operator and linspace:
0:0.1:5
linspace(0, 2*pi, 101)
A * BA .* BUse . prefix for element-wise operators: .*, ./, .^ when needed.
Solve Ax = b with the backslash operator (preferred for numerical stability):
x = A \ b
You can also compute inv(A)*b but using A\b is generally recommended.
Create script files (e.g., example1.m) containing a sequence of commands. Run them with:
nelson -f example1.m
Simple script example (save as example1.m):
% example1.m
A = [1 2 3; 3 3 4; 2 3 3];
b = [1; 1; 2];
x = A \ b
Variables created in a script are placed in the global workspace — be aware of side-effects.
Functions have their own local workspace and avoid polluting the global scope. Example function file fact.m:
function f = factorial(n)
% FACTORIAL(n) Compute factorial using prod
f = prod(1:n);
end
Call with factorial(5) to get 120.
Prompt for input inside a script using input(...) and format output with printf/disp equivalents available in Nelson.
If structure:
if expr
statements
elseif expr2
statements
else
statements
end
For loop:
for i = 1:5
s = i*i
end
While loop:
while x <= 10
x = 3*x
end
Comparison: >, <, >=, <=, ==, ~=
Logical: &, |, ~ (element-wise) and &&, || (short-circuit where supported)
This short list collects the most frequently used commands.
General
quit — exit Nelsondoc <command> — show help for a commandWorkspace and files
clear, who, whos, save('file.nh5'), load('file.nh5'), diary('session.txt')Arrays and matrices
: colon operator, linspace(a,b,n), zeros(m,n), ones(m,n), eye(n)Linear algebra
A\b solve, inv(A), det(A), eig(A), rank(A)Plotting
plot(x,y), xlabel(), ylabel(), legend(), title(), axis()Happy computing with Nelson!