SHOW:
|
|
- or go back to the newest paste.
1 | close all; clear; | |
2 | N = 100; | |
3 | P = 200; | |
4 | x = 1:N; | |
5 | y = sin(2*pi/N*x); | |
6 | stored = y; | |
7 | pathF = zeros(1,P); | |
8 | pathB = zeros(1,P); | |
9 | path = zeros(1,P); | |
10 | ||
11 | figure; | |
12 | while (1) | |
13 | pathB(P) = -pathF(P); | |
14 | for i = 1:(P-1) | |
15 | pathB(i) = pathB(i+1); | |
16 | end | |
17 | for i = P:-1:2 | |
18 | pathF(i) = pathF(i-1); | |
19 | end | |
20 | pathF(1) = stored(end); | |
21 | for i = N:-1:2 | |
22 | stored(i) = stored(i-1); | |
23 | end | |
24 | stored(1) = 0; | |
25 | if (nnz(stored) == 0) | |
26 | stored = y; | |
27 | end | |
28 | path = pathF + pathB; | |
29 | plot(path); hold on; | |
30 | plot(pathF); plot(pathB); | |
31 | legend('Sum wave', 'Forward wave', 'Backward wave'); | |
32 | axis([1 P -2.5 2.5]); | |
33 | hold off; | |
34 | drawnow; | |
35 | end |