// Files seeded into a new sample project. const readme = `# numbl sample project This project runs MATLAB-syntax \`.m\` files in your browser with [numbl](https://numbl.org). Open a script and press the **▶** button in the tab bar: - \`waves.m\` — damped oscillations: printed output goes to the **Output** panel at the bottom, the plot opens as **Figure 1** in the side bar to the right. Calls \`damped_wave.m\` (functions next to the script are found automatically, like MATLAB's path rules). - \`scripts/surface_demo.m\` — a 3-D surface. Uses \`addpath\` to call a function from the \`lib/\` folder. - \`scripts/animation.m\` — figures update live during the run (\`drawnow\`). - \`scripts/write_results.m\` — writes a file; it appears in the Explorer when the run finishes. - \`scripts/mip_demo.m\` — installs the \`inpoly\` package from the [mip](https://mip.sh) registry on first run (\`mip load --install\`) and uses it. Installed packages are cached in your browser, shared by all projects, and refreshed automatically after 30 minutes of inactivity. Edits are saved with **Ctrl+S** and persist in your browser. Runs use the current editor contents, saved or not. Press **⏹** to stop a runaway run. `; const wavesM = `% Damped harmonic oscillation — press the run button (▶) above. f = 2.5; % frequency (Hz) tau = 0.8; % decay time constant (s) t = linspace(0, 3, 600); y = damped_wave(t, f, tau); fprintf('samples: %d\\n', numel(t)); fprintf('peak amplitude: %.4f\\n', max(abs(y))); fprintf('rms amplitude: %.4f\\n', sqrt(mean(y.^2))); figure; plot(t, y); hold on; plot(t, exp(-t / tau), '--'); plot(t, -exp(-t / tau), '--'); hold off; title('Damped oscillation'); xlabel('t (s)'); ylabel('amplitude'); legend('signal', 'envelope', '-envelope'); `; const dampedWaveM = `function y = damped_wave(t, f, tau) % DAMPED_WAVE Exponentially decaying sine wave. y = exp(-t / tau) .* sin(2 * pi * f * t); end `; const surfaceDemoM = `% 3-D surface demo. mexican_hat lives in ../lib, so put that folder on % the search path first (files next to the running script are found % automatically; other folders follow MATLAB's addpath rules). addpath('../lib'); [X, Y] = meshgrid(linspace(-3, 3, 80), linspace(-3, 3, 80)); Z = mexican_hat(X, Y); figure; surf(X, Y, Z); title('Mexican hat'); xlabel('x'); ylabel('y'); disp('surface rendered — drag to rotate'); `; const mexicanHatM = `function z = mexican_hat(x, y) % MEXICAN_HAT Ricker wavelet surface. r2 = x.^2 + y.^2; z = (1 - r2) .* exp(-r2 / 2); end `; const animationM = `% Live figure updates: drawnow flushes the figure mid-run. % This one takes a while — try the stop button (⏹) in the tab bar. x = linspace(0, 4 * pi, 400); figure; for k = 1:200 plot(x, sin(x - k / 4) .* exp(-x / 8)); axis([0 4*pi -1 1]); title(sprintf('frame %d / 200', k)); drawnow; pause(0.04); end disp('animation done'); `; const writeResultsM = `% Scripts can write files: results/summary.txt shows up in the Explorer % when the run finishes. mkdir('results'); fid = fopen('results/summary.txt', 'w'); fprintf(fid, 'n, n^2, sqrt(n)\\n'); for n = 1:10 fprintf(fid, '%d, %d, %.4f\\n', n, n^2, sqrt(n)); end fclose(fid); disp('wrote results/summary.txt'); `; const mipDemoM = `% mip package demo: installs the inpoly package (point-in-polygon test) % from the mip registry (https://mip.sh) on first run, then reuses the % cached install. See https://mip.sh for available packages. mip load --install inpoly % a star-shaped polygon k = (0:9)'; r = 1 + 0.6 * (-1).^k; node = [r .* cos(pi/5 * k + pi/2), r .* sin(pi/5 * k + pi/2)]; % classify random points rng(42); pts = 4 * rand(2000, 2) - 2; inside = inpoly2(pts, node); fprintf('points inside: %d / %d\\n', sum(inside), length(inside)); figure; plot(pts(inside, 1), pts(inside, 2), '.'); hold on; plot(pts(~inside, 1), pts(~inside, 2), '.'); plot([node(:, 1); node(1, 1)], [node(:, 2); node(1, 2)]); hold off; axis equal; title('inpoly2: points inside a star'); legend('inside', 'outside', 'polygon'); `; export const sampleWorkspace: Record = { '/README.md': readme, '/waves.m': wavesM, '/damped_wave.m': dampedWaveM, '/scripts/surface_demo.m': surfaceDemoM, '/scripts/animation.m': animationM, '/scripts/write_results.m': writeResultsM, '/scripts/mip_demo.m': mipDemoM, '/lib/mexican_hat.m': mexicanHatM, };