• API
• FAQ
• Tools
• Archive
daily pastebin goal
15%
SHARE
TWEET

# Untitled

a guest Dec 18th, 2018 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. % Earthquake simulation
2.
3. % 1. create a grid 100x100m long, sampling 1 m
4. time       = 80; % seconds
5. SouthNorth = 100;
6. EastWest   = 100;
7. dx         = 1;
8. canvas = zeros(SouthNorth,EastWest);
9. time_sampling = 1;
10. measurement_time = 0:1/time_sampling:time-1/time_sampling;
11.
12. % 2. create the positions for the optical fiber (L shaped)
13. fiber_position_SouthNorth = [21,80];
14. fiber_position_WestEast   = [21,80];
15. fiber_plot = canvas;
16. fiber_plot(fiber_position_SouthNorth(1):fiber_position_SouthNorth(2),fiber_position_WestEast(1)) = 1;
17. fiber_plot(fiber_position_SouthNorth(2),fiber_position_WestEast(1):fiber_position_WestEast(2))  = 1;
18.
19. % figure, imagesc(fiber_plot);
20. nVect = [canvas(fiber_position_SouthNorth(1):fiber_position_SouthNorth(2),fiber_position_WestEast(1))' canvas(fiber_position_SouthNorth(2),fiber_position_WestEast(1):fiber_position_WestEast(2))];
21. nVect = repmat(nVect,[length(measurement_time),1]);
22.
24. phase_velocity = 6;
25. omeg = wavenumber*phase_velocity;
26.
27. angle_deg=85;
28.
29. main_dir    = [cosd(angle_deg), sind(angle_deg)];
30. rotMatrix   = [cosd(90) -sind(90); sind(90) cosd(90)];
31. ortogVector = main_dir*rotMatrix;
32.
33. idx = 1;
34. h = figure(3);
35. set(h, 'WindowStyle', 'Docked');
36.
37. max_pert_length = ceil(sqrt(size(canvas,1)^2+size(canvas,2)^2));
38. ps = 0:max_pert_length;
39. for t = measurement_time
40.
41.     perturbation = sin(omeg*t - wavenumber*dx*ps).*exp(-((ps-phase_velocity*t).^2)/32);
42.
43.     pert_points = 1:0.5:(length(perturbation)-1);
44.
45.     for idd = 1:(length(pert_points)-1)
46.
47.         main_pos = floor(pert_points(idd)*main_dir);
48.         idd2 = -100;
49.
50.         while idd2 < 100
51.             p = main_pos+floor(idd2*ortogVector)+1;
52.             if all(p    > 0)          && ...
53.                all(p(2) < EastWest)   && ...
54.                all(p(1) < SouthNorth)
55.                 canvas(p(1),p(2)) = perturbation(floor(pert_points(idd)));
56.             end
57.             idd2 = idd2 + 1;
58.         end
59.     end
60.     subplot(1,2,1), imagesc(canvas+fiber_plot), drawnow;
61.     idx = idx+1;
62.     nVect(idx,:) = [canvas(fiber_position_SouthNorth(1):fiber_position_SouthNorth(2),fiber_position_WestEast(1))' canvas(fiber_position_SouthNorth(2),fiber_position_WestEast(1):fiber_position_WestEast(2))];
63.     subplot(1,2,2), plot(nVect(idx,:)),   axis([0 size(nVect,2) -1 1]),    drawnow;
64. end
65. %
66. % y = mx+b
67. % function [fiber_canvas] = generateFiberPositionMatrix(canvas, nodes)
68. %
69. % y_vec = 1:size(canvas,1)
70. % x_vec = 1:size(canvas,2)
71. %
72. % % 2. create the positions for the optical fiber (L shaped)
73. % fiber_position_SouthNorth = [21,80];
74. % fiber_position_WestEast   = [21,80];
75. % fiber_plot = canvas;
76. % fiber_plot(fiber_position_SouthNorth(1):fiber_position_SouthNorth(2),fiber_position_WestEast(1)) = 1;
77. % fiber_plot(fiber_position_SouthNorth(2),fiber_position_WestEast(1):fiber_position_WestEast(2))  = 1;
78. %
79. % % figure, imagesc(fiber_plot);
80. % nVect = [canvas(fiber_position_SouthNorth(1):fiber_position_SouthNorth(2),fiber_position_WestEast(1))' canvas(fiber_position_SouthNorth(2),fiber_position_WestEast(1):fiber_position_WestEast(2))];
81. % nVect = repmat(nVect,[length(measurement_time),1]);
82. %
83. % prev_node = nodes(1,:)
84. %     for node_idx = 2:size(nodes,1)
85. %         node = nodes(node_idx,:)
86. %         m = (node(2)-prev_node(2))/(node(1)-prev_node(1));
87. %         nVect = [nVect canvas(
88. %     end
89. % end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top