Guide
Toolboxes
Beyond the core language, MathLab includes the everyday parts of several MATLAB toolboxes, with the same function names. Each section links to its functions in the reference and its examples in the gallery.
These are compact re-implementations for learning, teaching and exploring — accurate on standard problems (they reproduce MATLAB's documented examples) but not a replacement for the full toolboxes on large or delicate problems.
Optimisation
linprog and intlinprog (simplex, branch and bound), quadprog (active set), fmincon (constraints of every kind), fminunc, lsqcurvefit, lsqnonlin and optimoptions. → functions · examples
% minimise cost subject to constraints: linprog, quadprog, fmincon, lsqcurvefit
f = @(x) (x(1) - 2)^2 + (x(2) - 1)^2;
[x, fval] = fmincon(f, [0; 0], [1 2], 2, [], [], [0; 0], []) % stay below the line x1 + 2 x2 = 2
[X, Y] = meshgrid(linspace(-0.5, 2.5, 80));
contour(X, Y, (X - 2).^2 + (Y - 1).^2, 15), hold on
plot([0 2], [1 0], 'k', 'LineWidth', 1.5), plot(x(1), x(2), 'rp', 'MarkerSize', 12), hold off
axis equal, title('fmincon: the best point on the boundary')Try it ↗Control systems
Transfer functions you can add, multiply and feed back (s = tf('s')), step, impulse, lsim, stepinfo, bode, margin, nyquist, rlocus, pzmap, pid and pidtune. → functions · examples
s = tf('s');
G = 1 / (s^3 + 3*s^2 + 3*s + 1); % three lags
C = pidtune(G, 'PID'); % a tuned PID controller
step(G, feedback(C*G, 1), 15)
legend('open loop', 'with PID control')Try it ↗Symbolic maths
syms x and ordinary operators build exact expressions: diff, int (definite and indefinite), solve, subs, simplify, expand, factor, limit, taylor, jacobian, vpa, matlabFunction and latex — handy for papers and for LabTeX. Exact for polynomials, the elementary functions and the usual integration techniques; numbers where no closed form is found. → functions · examples
syms x
f = exp(-x)*sin(2*x)
F = int(f, x, 0, Inf) % exact: 2/5
d = diff(f, x)
fplot(f, [0 6]), hold on, fplot(d, [0 6], '--'), hold off
legend('f', "f'"), title(['f''(x) = ' char(d)])Try it ↗Econometrics and statistics
fitlm (coefficient table with standard errors, t statistics, p-values, R², F test), predict, regress; arima and garch models with estimate, forecast, infer and simulate; autocorr, parcorr, lbqtest, adftest; and the t, F and χ² distributions. → functions · examples
rng(4)
y = simulate(arima('AR', 0.8, 'Constant', 0.5, 'Variance', 1), 200);
EstMdl = estimate(arima(1, 0, 0), y) % coefficient table in the console
[yF, mse] = forecast(EstMdl, 20, y);
plot(1:200, y, 201:220, yF, 'r', 'LineWidth', 1.5)
title(sprintf('AR(1) estimated: %.2f (true 0.8)', EstMdl.AR))Try it ↗Mapping
worldmap (world, continents, countries or a globe), geoplot, geoscatter, geobubble, distance — and countrymap to colour countries by data such as World Bank indicators. Country outlines come from Natural Earth (public domain) and are served with this site. → functions · examples
worldmap('Europe')
countrymap({'NLD', 'BEL', 'LUX', 'DEU', 'FRA', 'ESP', 'PRT', 'ITA'}, [1 2 3 4 5 6 7 8])
geoscatter([52.37 50.85 49.61], [4.90 4.35 6.13], 60, 'r')
title('Benelux and neighbours')Try it ↗Image processing, signals, finance
Covered in their own sections: images (filters, edges, histograms, morphology, regions), signal processing (FFT, filters, windows, spectra) and finance (cash flows, loans, bonds, Black–Scholes, portfolios).
I = testimage('shapes');
subplot(1, 2, 1), imshow(I)
subplot(1, 2, 2), imshow(edge(rgb2gray(I), 'canny'))Try it ↗