/ concept-collection / numbl-embed-example
Sign in
concept-collection / numbl-embed-example
numbl-embed-example / example1.md
51 lines · 1.3 KBPreviewCodeBlameHistoryRaw
1<script src="https://numbl.org/numbl-embed.js"></script>
3This demonstrates how to embed numbl in a markdown file that can be rendered on GitHub Pages.
5<numbl-embed>
6<iframe width="100%" height="600" frameborder="0"></iframe>
7<script type="text/plain" class="matlab-script">
8% Matrix operations example
9A = [8, 1, 6; 3, 5, 7; 4, 9, 2];
10disp('Matrix A:')
11disp(A)
13disp('Sum of each row:')
14disp(sum(A, 2))
16disp('Sum of each column:')
17disp(sum(A, 1))
19disp('Sum of diagonal:')
20disp(sum(diag(A)))
22disp('Total sum:')
23disp(sum(sum(A)))
24</script>
25</numbl-embed>
27If it worked, you should see an embedded numbl above with a matrix operations example.
29Here's another example with numerical integration:
31<numbl-embed>
32<iframe width="100%" height="600" frameborder="0"></iframe>
33<script type="text/plain" class="matlab-script">
34% Numerical integration using trapezoidal rule
35a = 0;
36b = pi;
37n = 100;
39% Create evenly spaced points
40h = (b - a) / (n - 1);
41x = a:h:b;
42y = sin(x);
44% Trapezoidal rule: (h/2) * (y(1) + 2*sum(y(2:end-1)) + y(end))
45integral_approx = (h/2) * (y(1) + 2*sum(y(2:end-1)) + y(end));
47disp(['Approximate integral of sin(x) from 0 to pi: ', num2str(integral_approx)])
48disp('Exact value: 2')
49disp(['Error: ', num2str(abs(integral_approx - 2))])
50</script>
51</numbl-embed>
moveopenescclose