2 "cells": [
3 {
4 "cell_type": "markdown",
5 "id": "intro-title",
6 "metadata": {},
7 "source": [
8 "# MATLAB syntax, entirely in your browser\n",
9 "\n",
10 "This notebook runs on the **numbl kernel for JupyterLite**. Every cell executes\n",
11 "in a Web Worker in *your* browser tab — there is no server and no kernel\n",
12 "process behind this page, and nothing to install.\n",
13 "\n",
14 "The engine is [numbl](https://github.com/flatironinstitute/numbl), an\n",
15 "open-source MATLAB-syntax language implementation in TypeScript.\n",
16 "\n",
17 "Run the cells below with **Shift+Enter**."
18 ]
19 },
20 {
21 "cell_type": "code",
22 "execution_count": null,
23 "id": "intro-matrix",
24 "metadata": {},
25 "outputs": [],
26 "source": [
27 "A = [4 2 1; 2 5 3; 1 3 6]"
28 ]
29 },
30 {
31 "cell_type": "code",
32 "execution_count": null,
33 "id": "intro-solve",
34 "metadata": {},
35 "outputs": [],
36 "source": [
37 "% Variables persist across cells; solve a linear system with backslash\n",
38 "b = [1; 2; 3];\n",
39 "x = A \\ b\n",
40 "residual = norm(A*x - b)"
41 ]
42 },
43 {
44 "cell_type": "code",
45 "execution_count": null,
46 "id": "intro-indexing",
47 "metadata": {},
48 "outputs": [],
49 "source": [
50 "% MATLAB indexing: rows, and logical masks\n",
51 "A(2, :)\n",
52 "A(A > 3)'"
53 ]
54 },
55 {
56 "cell_type": "code",
57 "execution_count": null,
58 "id": "intro-loop",
59 "metadata": {},
60 "outputs": [],
61 "source": [
62 "total = 0;\n",
63 "for k = 1:10\n",
64 " total = total + k^2;\n",
65 "end\n",
66 "fprintf('sum of squares 1..10 = %d\\n', total);"
67 ]
68 },
69 {
70 "cell_type": "code",
71 "execution_count": null,
72 "id": "intro-anon",
73 "metadata": {},
74 "outputs": [],
75 "source": [
76 "% Anonymous functions work in cells (named functions belong in .m files)\n",
77 "f = @(t) exp(-t) .* cos(2*pi*t);\n",
78 "vals = arrayfun(f, 0:0.5:2)"
79 ]
80 },
81 {
82 "cell_type": "markdown",
83 "id": "intro-next",
84 "metadata": {},
85 "source": [
86 "Next: [plotting](./02-plotting.ipynb) and\n",
87 "[installing packages](./03-packages.ipynb) — both also fully client-side."
88 ]
89 }
90 ],
91 "metadata": {
92 "kernelspec": {
93 "display_name": "MATLAB (numbl)",
94 "language": "matlab",
95 "name": "numbl"
96 },
97 "language_info": {
98 "codemirror_mode": "octave",
99 "file_extension": ".m",
100 "mimetype": "text/x-octave",
101 "name": "matlab",
102 "pygments_lexer": "matlab"
103 }
104 },
105 "nbformat": 4,
106 "nbformat_minor": 5
107}