How to run a script 01 Type or paste a script. Statements end with a newline or semicolon; a trailing semicolon suppresses echo, exactly as in MATLAB. 02 Build matrices with brackets and semicolons. A = [2 1 -1; -3 -1 2; -2 1 2] is three rows separated by semicolons, columns by spaces.03 Solve, do not invert. x = A\b uses an LU-based solve; inv(A)*b is a different, usually less accurate route.04 Watch the workspace. After each run the variable list shows sizes, classes and previews; the session persists between runs, so a second cell can use variables the first one created. 05 Read errors by line. A failed run names the message and the line number, and the workspace keeps the variables that were successfully assigned before the failure.
Worked readouts This script:
produces, verbatim:
The residual norm of 8.882e-16 is at machine precision: the solve found x = [2, 3, −1] , and substituting it back into the three equations leaves nothing but rounding. The colon range 0:0.25:1 produced a 1×5 vector t , the elementwise product exp(-t).*cos(2*pi*t) produced the row 1.0000 0.0000 −0.6065 −0.0000 0.3679 , and max returned both the value 1 and its index 1 . The last line assigned s and let mean(y) answer as ans = **0.1523**. Run separately, a Fibonacci function and a sum check come out as expected: fib(10) prints 55 and sum(1:100) prints 5050 . format long changes only the display: π echoes as 3.141592653589793 instead of 3.1416 .
matlab A = [2 1 -1; -3 -1 2; -2 1 2];
b = [8; -11; -3];
x = A\b
detA = det(A)
fprintf("residual norm = %.3e\n", norm(A*x - b));
t = 0:0.25:1;
y = exp(-t).*cos(2*pi*t);
disp(y)
[ymax, idx] = max(y)
s = sum(y); mean(y)text x =
2.0000
3.0000
-1.0000
detA = -1.0000
residual norm = 8.882e-16
1.0000 0.0000 -0.6065 -0.0000 0.3679
ymax = 1
idx = 1
ans = 0.1523
Why the display and the arithmetic differ MATLAB's short format shows four decimal places by default, and the kernel reproduces that: x prints as 2.0000, 3.0000, −1.0000 even though the stored values are exact. The distinction matters at the edges. The residual printed with fprintf keeps three significant digits of the exponent — 8.882e-16 — while the same quantity displayed as a variable would round to zero. When you compare two results, compare the stored values, not the printed ones.
The backslash is the other teaching point. A\b does not form an inverse: it factorises A and solves the triangular systems, which is cheaper and better conditioned than inv(A)*b, whose entries can be wrong in the last digits even when the solve is exact. Elementwise versus matrix operators are the second distinction: * is matrix multiplication, .* multiplies entry by entry, and the script needs .* because both factors are 1×5 vectors. Replace it with * and the interpreter reports a dimension mismatch rather than guessing.
Limits and edges
A subset, not the full product. There are no toolboxes, no classes, no graphics handle objects and no Simulink; plotting support is limited to what the panel renders, and filesystem access does not exist. Scripts that rely on those features will fail with a clear error rather than silently misbehave.
Bounded execution. Long or infinite loops are stopped by operation and wall-clock budgets; the error names the limit. This is deliberate: a browser tab cannot host an unbounded kernel, and the panel would rather refuse than hang. What it does not do. It does not call Python, R or Octave, and it does not produce publication figures. For Python with NumPy and matplotlib use the Python kernel ; for R and its statistics packages the R kernel ; for numerical optimisation and ODE work the dedicated Optimization and ODE panels keep results in typed cards rather than text.
The elementwise trap Most interpreter errors in practice are shape errors, and the kernel reports them rather than broadcasting. A(3,1) on a 3×3 matrix is fine, but A(3,4) fails with Index exceeds matrix dimensions. (line 1) — MATLAB indexing is 1-based, and the row/column order is (row, column), not (x, y). A second trap is the echo rule: s = sum(y); mean(y) prints only the ans line because the semicolon suppressed s, and a script that "prints nothing" usually just ended every line with a semicolon. The third is session persistence: variables survive between runs, which is convenient for a REPL but means a stale x from an earlier cell can mask a bug; the workspace list and its preview column are there to catch exactly that.
Where it earns its place Checking a linear algebra exercise A 3×3 system solved by hand can be verified in one run: x = [2, 3, −1] , determinant −1 , residual 8.882e-16 . The residual is the evidence that the answer is right, not the printed digits.
Prototyping a numeric script before moving to a desktop The subset covers the core of teaching and engineering scripts — matrix construction, colon ranges, elementwise vector maths, functions, loops — so a prototype can be written and checked in the browser, then copied to MATLAB or Octave. The workspace bridge carries matrices and vectors out as typed values rather than screenshots.
Teaching what \ does Compare A\b with inv(A)*b on a Hilbert-like matrix and the residual difference is measurable; the panel gives both the numbers and the workspace to keep them in.
Privacy Scripts and variables are evaluated in your browser; nothing is sent to a server, and the kernel downloads no runtime.
References
MathWorks, mldivide, \ , mathworks.com (访问日期:2026-10-07)— the backslash solve and its factorisation.
MathWorks, Array vs. Matrix Operations , mathworks.com (访问日期:2026-10-07)— * against .*.
MathWorks, Colon, : , mathworks.com (访问日期:2026-10-07)— start:step:stop ranges.
Wikipedia, MATLAB , en.wikipedia.org (访问日期:2026-10-07)— the language and its 1-based indexing.
Wikipedia, LU decomposition , en.wikipedia.org (访问日期:2026-10-07)— the factorisation behind the solve.
Calculators in this hub
Hand-picked tools, one click away. The mini versions compute live and carry your values into the full calculator.
Sources & review
Reviewed by CalcX Editorial Team
Updated 2026-10-07