{ "cells": [ { "cell_type": "markdown", "id": "intro-title", "metadata": {}, "source": [ "# MATLAB syntax, entirely in your browser\n", "\n", "This notebook runs on the **numbl kernel for JupyterLite**. Every cell executes\n", "in a Web Worker in *your* browser tab — there is no server and no kernel\n", "process behind this page, and nothing to install.\n", "\n", "The engine is [numbl](https://github.com/flatironinstitute/numbl), an\n", "open-source MATLAB-syntax language implementation in TypeScript.\n", "\n", "Run the cells below with **Shift+Enter**." ] }, { "cell_type": "code", "execution_count": null, "id": "intro-matrix", "metadata": {}, "outputs": [], "source": [ "A = [4 2 1; 2 5 3; 1 3 6]" ] }, { "cell_type": "code", "execution_count": null, "id": "intro-solve", "metadata": {}, "outputs": [], "source": [ "% Variables persist across cells; solve a linear system with backslash\n", "b = [1; 2; 3];\n", "x = A \\ b\n", "residual = norm(A*x - b)" ] }, { "cell_type": "code", "execution_count": null, "id": "intro-indexing", "metadata": {}, "outputs": [], "source": [ "% MATLAB indexing: rows, and logical masks\n", "A(2, :)\n", "A(A > 3)'" ] }, { "cell_type": "code", "execution_count": null, "id": "intro-loop", "metadata": {}, "outputs": [], "source": [ "total = 0;\n", "for k = 1:10\n", " total = total + k^2;\n", "end\n", "fprintf('sum of squares 1..10 = %d\\n', total);" ] }, { "cell_type": "code", "execution_count": null, "id": "intro-anon", "metadata": {}, "outputs": [], "source": [ "% Anonymous functions work in cells (named functions belong in .m files)\n", "f = @(t) exp(-t) .* cos(2*pi*t);\n", "vals = arrayfun(f, 0:0.5:2)" ] }, { "cell_type": "markdown", "id": "intro-next", "metadata": {}, "source": [ "Next: [plotting](./02-plotting.ipynb) and\n", "[installing packages](./03-packages.ipynb) — both also fully client-side." ] } ], "metadata": { "kernelspec": { "display_name": "MATLAB (numbl)", "language": "matlab", "name": "numbl" }, "language_info": { "codemirror_mode": "octave", "file_extension": ".m", "mimetype": "text/x-octave", "name": "matlab", "pygments_lexer": "matlab" } }, "nbformat": 4, "nbformat_minor": 5 }