// 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. 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'); `; 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, '/lib/mexican_hat.m': mexicanHatM, };