In class we wrote the procedure DPenddT, and visualizePend
function dPdT = dPenddT(t,p) u = p(1); v = p(2); g = -9.8; L = 1; uPrime = v; vPrime = (g/L) * sin(u); % no friction dPdT = [uPrime vPrime]'; |
................ |
function visualizePend(p)
%loop over each time point
for ix = 1:size(p,1);
%plot the top of the pendulum
plot(0,0,'+');hold on;
%plot the bottom of the pendulum
plot(sin(p(ix,1)),-cos(p(ix,1)),'o');hold off;
% force it to draw
axis([-1 1 -1 1]);
drawnow;
end
|
(old version) y'' = -(g / L) * sin(y), we have: (new version) y'' = -(g / L) * sin(y) - 2*(L'/L) * y';Where the new term is the "centripetal acceleration" of pulling something into the center of a circle.
Task 1 Adjust both the dPenddT and the visualizePend functions to be able to simulate and visualize the behavior of the pendulum as it becomes shorter. Look up the "xlabel" and "ylabel" commands and make a plot of the phase space with the axes labelled. When you're done, run and visualize the command:
[t p] = ode23('dPenddT',[0:0.01:8],[pi/2 -1]);
Your phase space plot should look something like the one pictured below. I've
drawn an extra 'o' at the end of the plot (to tell it from the
beginning.
Show the TA both your visualization of the pendulum swinging and your phase space plot for your first check-off.
Task 2 Instead of including alpha as a "hard coded" value that we've set to 1, we can include L as another parameter in our differential equation. This requires that you make dPenddT(t,p) take a vector p of 3 arguments, where the 3rd argument is the "length" of the pendulum. Then, dPenddT must return a 3 element vector, dPdt, that you might set as:
[t p] = ode23('dPenddT',[0:0.01:10],[pi/2 -1 1]);
This will give you a result "p" which is is an array with the shape:
Task 3 Now, we are going to make a schedule of how to winch up the pendulum, without it going faster and faster. The goal is to winch the pendulum all the way up to be zero length, and to never let the "theta" angle exceed pi/6.
To do this we are going to allow the "alpha" term in you dPenddT function to vary. Instead of setting alphaPrime = -0.1, you must figure out "when" to winch the pendulum in. (Imagine holding a pendulum by a string. When does shortening the string make it go faster? When does it make it go slower?).
This might include terms like:
if abs(u)>0.1, % if the winch isn't at the bottom of its swing, pull up alphaPrime = -0.1 else % otherwise, let it down (which may slow down the motion) alphaPrime = 0.1 end --- or --- if abs(u)<0.1, % if the winch is going slowly, pull up alphaPrime = -0.1 else % otherwise, keep string the same length alphaPrime = 0.0 end --- or --- Many other possibilitiesAt the end, you need to show the TA: