update example
1 changed file+8−17
example1.mdmodified+8−17View file
@@ -26,26 +26,17 @@ disp(sum(sum(A)))
2626
2727 If it worked, you should see an embedded numbl above with a matrix operations example.
2828
29-Here's another example with numerical integration:
29+Here's an example with a Lissajous curve plot:
3030
3131 <numbl-embed>
3232 <iframe width="100%" height="600" frameborder="0"></iframe>
3333 <script type="text/plain" class="matlab-script">
34-% Numerical integration using trapezoidal rule
35-a = 0;
36-b = pi;
37-n = 100;
38-
39-% Create evenly spaced points
40-h = (b - a) / (n - 1);
41-x = a:h:b;
42-y = sin(x);
43-
44-% Trapezoidal rule: (h/2) * (y(1) + 2*sum(y(2:end-1)) + y(end))
45-integral_approx = (h/2) * (y(1) + 2*sum(y(2:end-1)) + y(end));
46-
47-disp(['Approximate integral of sin(x) from 0 to pi: ', num2str(integral_approx)])
48-disp('Exact value: 2')
49-disp(['Error: ', num2str(abs(integral_approx - 2))])
34+% Damped oscillation
35+t = linspace(0, 10, 200);
36+y = exp(-0.3 * t) .* sin(2 * pi * t);
37+plot(t, y)
38+title('Damped Oscillation')
39+xlabel('Time')
40+ylabel('Amplitude')
5041 </script>
5142 </numbl-embed>