Need help with creating a pendulum in Matlab. DO NOT COPY PASTE FROM SOMEWHERE E
ID: 3143724 • Letter: N
Question
Need help with creating a pendulum in Matlab. DO NOT COPY PASTE FROM SOMEWHERE ELSE!!
pendulum example: https://www.dropbox.com/s/g228uu2bskn9i8o/pendulum_example.avi?dl=0
This is what I've done so far, but I'm not sure what I'm doing wrong.
L = 2
g = 9.81
T = 2*pi*sqrt(L/g)
myVideo2 = VideoWriter('pendulum')
open(myVideo2)
set(figure, 'Visible', 'on')
for t = 0:0.001:T;
theta = 60*cos(sqrt(g/L*t));
x = L*sin(theta);
y = L*(1 - cos(theta));
x2 = [0 x];
y2 = [L y];
plot(x, y, 'b.', 'MarkerSize', 40)
hold on
plot(x2, y2,'k' ,'linewidth', 3)
hold off
axis equal
axis([-2,2,-2,2])
drawnow
frame = getframe;
writeVideo(myVideo2, frame)
end
close(myVideo2)
The motion of a pendulum (more specifically, the "bob" at the end of the pendulum) can be described mathematically by the equations y: L(1-cos()) Here x and y are the coordinates of the bob at time t , and ("theta") is the angle the rod makes with the vertical (see Figure 4.3). The parameters in this model are the the length of the rod L, the acceleration due to gravity g and the initial angleExplanation / Answer
In the given code the line 4 : myVideo2 = VideoWriter('pendulum') has a syntax error.
You need to mention the extension of the video file you want to genarate like (.avi)
The correct code would be myVideo2 = VideoWriter('pendulum.avi')
Also while capturing the frame using getframe try usign it's functionalities like
getframe(ax)
getframe(fig)
getframe(___,rect)
according to the requirement. This will help dispalying the frame with more details.
Otherwise the code looks fine !