6b31a9aSync .m workspace files from the notebook directory into the sessionJeremy Magland 2 "cells": [
3 {
4 "cell_type": "markdown",
5 "id": "intro-title",
6 "metadata": {},
80cd178Update numbl links and tidy copyJeremy Magland 7 "source": "# numbl: MATLAB syntax, entirely in your browser\n\nThis notebook runs on the **numbl kernel for JupyterLite**. Every cell executes\nin a Web Worker in *your* browser tab, with no server and no kernel process\nbehind this page, and nothing to install.\n\n[numbl](https://numbl.org) is an open-source numerical-computing engine\nwritten in TypeScript. It uses MATLAB syntax, so `.m` code runs unchanged.\n\nRun the cells below with **Shift+Enter**."
10 "cell_type": "code",
11 "execution_count": null,
12 "id": "intro-matrix",
13 "metadata": {},
14 "outputs": [],
15 "source": [
16 "A = [4 2 1; 2 5 3; 1 3 6]"
17 ]
18 },
19 {
20 "cell_type": "code",
21 "execution_count": null,
22 "id": "intro-solve",
23 "metadata": {},
24 "outputs": [],
25 "source": [
26 "% Variables persist across cells; solve a linear system with backslash\n",
27 "b = [1; 2; 3];\n",
28 "x = A \\ b\n",
29 "residual = norm(A*x - b)"
30 ]
31 },
32 {
33 "cell_type": "code",
34 "execution_count": null,
35 "id": "intro-indexing",
36 "metadata": {},
37 "outputs": [],
77bc6b7Soften rebrand: keep MATLAB syntax visible alongside numblJeremy Magland 38 "source": "% MATLAB-style indexing: rows, and logical masks\nA(2, :)\nA(A > 3)'"
40 {
41 "cell_type": "code",
42 "execution_count": null,
43 "id": "intro-loop",
44 "metadata": {},
45 "outputs": [],
46 "source": [
47 "total = 0;\n",
48 "for k = 1:10\n",
49 " total = total + k^2;\n",
50 "end\n",
51 "fprintf('sum of squares 1..10 = %d\\n', total);"
52 ]
53 },
54 {
55 "cell_type": "code",
56 "execution_count": null,
57 "id": "intro-anon",
58 "metadata": {},
59 "outputs": [],
60 "source": [
61 "% Anonymous functions work in cells (named functions belong in .m files)\n",
62 "f = @(t) exp(-t) .* cos(2*pi*t);\n",
63 "vals = arrayfun(f, 0:0.5:2)"
64 ]
65 },
66 {
67 "cell_type": "markdown",
68 "id": "1e814d6c",
80cd178Update numbl links and tidy copyJeremy Magland 69 "source": "## Named functions live in `.m` files\n\nnumbl's cells work like the MATLAB console: you can't define a *named*\nfunction directly in a cell. Instead, put it in a `.m` file next to the\nnotebook. This kernel syncs `.m` files from the file browser into the\nsession before every cell runs, so functions defined there are callable\nimmediately, and edits take effect the next time you run a cell.\n\nThis notebook ships with [statsutils.m](./statsutils.m); open it and try\nediting it (e.g. add a `median` field) while the cell below is still there.",
6b31a9aSync .m workspace files from the notebook directory into the sessionJeremy Magland 70 "metadata": {}
71 },
72 {
73 "cell_type": "code",
74 "id": "55d6bb19",
75 "source": "data = [2 4 4 4 5 5 7 9];\ns = statsutils(data);\nfprintf('mean=%.4f std=%.4f range=%.4f\\n', s.mean, s.std, s.range);",
76 "metadata": {},
77 "execution_count": null,
78 "outputs": []
79 },
80 {
81 "cell_type": "markdown",
82 "id": "intro-next",
83 "metadata": {},
80cd178Update numbl links and tidy copyJeremy Magland 84 "source": "Next: [plotting](./02-plotting.ipynb) and\n[installing packages](./03-packages.ipynb), both also fully client-side."
86 ],
87 "metadata": {
88 "kernelspec": {
f44f6a3Rebrand numbl-first: this runs numbl (which uses MATLAB syntax)Jeremy Magland 89 "display_name": "numbl (MATLAB syntax)",
90 "language": "numbl",
6b31a9aSync .m workspace files from the notebook directory into the sessionJeremy Magland 91 "name": "numbl"
92 },
93 "language_info": {
94 "codemirror_mode": "octave",
95 "file_extension": ".m",
96 "mimetype": "text/x-octave",
f44f6a3Rebrand numbl-first: this runs numbl (which uses MATLAB syntax)Jeremy Magland 97 "name": "numbl",
6b31a9aSync .m workspace files from the notebook directory into the sessionJeremy Magland 98 "pygments_lexer": "matlab"
99 }
100 },
101 "nbformat": 4,
102 "nbformat_minor": 5
103}