Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- close all; clear;
- N = 100;
- P = 200;
- x = 1:N;
- y = sin(2*pi/N*x);
- stored = y;
- pathF = zeros(1,P);
- pathB = zeros(1,P);
- path = zeros(1,P);
- figure;
- while (1)
- pathB(P) = -pathF(P);
- for i = 1:(P-1)
- pathB(i) = pathB(i+1);
- end
- for i = P:-1:2
- pathF(i) = pathF(i-1);
- end
- pathF(1) = stored(end);
- for i = N:-1:2
- stored(i) = stored(i-1);
- end
- stored(1) = 0;
- if (nnz(stored) == 0)
- stored = y;
- end
- path = pathF + pathB;
- plot(path); hold on;
- plot(pathF); plot(pathB);
- legend('Sum wave', 'Forward wave', 'Backward wave');
- axis([1 P -2.5 2.5]);
- hold off;
- drawnow;
- end
Add Comment
Please, Sign In to add comment