How do you simulate 15 pendulums in Matlab 98 Wed 629 PM Pat
Solution
1) Start up MATLAB
2)Type 1:10 in the command window and press return.
3) For sine functions plot, define a vectorof time points t=0:0.01:2. Use a semicolon to supress output.
4) Now define a vector of corresponding sine values: x=sin(2*pi*t);
5) Open a figure window by typing figure.
6) Plot the sine: plot(t,x).
7) Add the more plots to the same figure window by typing hold on.
8) Add sines with higher frequencies:
plot (t, sin(2*pi*2*t), \'b\', t, sin(2*pi*3*t), \'k--\')
9) How many times does sin(2*pi*f*t) oscillate on the interval [0,1]?
Now we will move on to scripts
1) Create a new script by using the file menu.
2) In the editor window, type the following
t=0:0.013:3;
figure;hold on
xlim( [ t(1) t(end) ] )
ylim( [ -1.1 1.1] )
for f=1.6
plot (t, sin(2*pi*f*t)
end
The for-loop will run trough the 6 frequency and plot each one. The axis command fixes x-axis to be shown from the first value of the time vector t(1) to the last value t(end). The y axis is set to the interval [-1.1 1.1].
3) Now save the file with any name with .m extension.
Notice that the pattern repeats with all sine curves passing through the same points at certain times.
Since frequency is inversely proportional to square root of its length. To construct a series of pendla with frequencies say 5 through 19 we will take 15 weights and hang hem on a string of lengths proportional to 1/52, 1/62, .....1/192.
Plotting Pendula
1) To keep the things simple we will graph the postion position of the weights as seen by someone looking straight down at the pendula from above. Create a new script and save it as \"Pendulumwave.m\".
2) Next choose a range of frequencies to using in your simulated pendula, freqs= 5:20.
3) Have a script open a figure window and plot a pendula at rest:
pendula=plot(zeros(size(freqs)), freqs, \'k.\' , \'MarkerSize\' , 25) ;
4) Fix the X-limits to be [-1.1 1.1] and y-limits to cover the smallest to largest frequency in your freqs vector.
5) Make a for loop to repeatedly update the plot over time:
for t=0:0.001:1
x= sin(2*pi*freqs*t);
set (pendula, \'xData\' , x);
drawnow; pause(0.03)
end
6) Save your script and run it. Adjust the value in pause command to slow down or speed up the movie.

