Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

***MUST USE MATLAB - help please! Consider the pendulum of Fig. 1, whose dynamic

ID: 2293918 • Letter: #

Question

***MUST USE MATLAB - help please!

Consider the pendulum of Fig. 1, whose dynamics is linearized by the following equation when the angel ? is small where l is the pendulum's length, m is the mass, k is the friction coefficient at the hinge, g is the gravity constant, and x(t) is the external force. Assume that m = 1kg, l = 1m, k = 1, and g-10m/s 2 . The unit of ? is radian. The output signal of the system is ?(t) x(t) Figure 1. A simple pendulum. (1) Suppose no external force is applied to the pendulum (a) Plot the system response for t 2 0 given that both the initial angle and the initial angular velocity is O at time t 0 (b) Plot the system response for t 2 0 given that the initial angle is 0 and the initial angular velocity is 1 radian/sec at time t = 0 (c) Plot the system response for t 2 0 given that the initial angle is 0.2 radian/sec and the initial angular velocity is 0 at time t 0 (d) Plot the system response for t 2 0given that the initial angle is 0.2 radian and the initial angular velocity is 1 radian/sec at time t0. Compare this response with the sum of the responses in (b) and (c), and discuss your observation. (e) Suppose there is no friction in the system, i.e., I = 0. Plot he system response for t 0 given that the initial angle is 0.2 radian and the initial angular velocity is 1 radian/sec at time t 0 Explain the plot in terms of eigenvalues. Analyze and discuss each of the above plots and draw your conclusions. (2) Suppose initially the pendulum has zero angle and zero angular velocity (a) Plot the system response for t 2 0 given that a unit impulse force is applied to the pendulum at time 0. This is called the impulse response of the system. (b) Plot the system response for t 20 given that a unit step force is applied to the pendulum at time 0. This is called the step response of the system. (c) Plot the system response for t 20 given that a unit ramp function (i.e., (t)-t) is applied to the pendulum at time 0. This is called the ramp response of the system (d) Plot the system response for t 2 0 given that a periodic force x(t)-cos(t) is applied to the pendulum at time 0. (e) Plot the system response for t 2 0 given that a periodic force x(t) 0.5 cos(2t) is applied to the pendulum at time 0 Plot the above system response long enough in time so that you can view the entire profile Analyze and explain each of the above results and draw your conclusions. Pay attention to the frequencies of the input and output. (3) Plot the system response for t2 0 given that the initial angle is 0.2 radian/sec, the initial angular velocity is 1 raidan, and the external unit impulse force is applied, at time t = 0. Compare this response with the sum of the responses found in (1-d) and (2-a). Discuss your findings

Explanation / Answer

%==========================================================================
% Matlab program to simulate the movement of a simple pendulum.
% The differential equations find the unknown angles of the pendulum.
% These are then converted into cartesian co ordinates x and y for the
% simulation.
% In addition, the user has the option of selecting either a phase portrait
% or a time series plot. These remain in polar coordinates.
%
%==========================================================================

clear % Clears command history
clc % Clears command window
clf % Clears figure window

%========= Sets initial parameters for pendulum ===========================
g = 9.81; % Gravity (ms-2)
l = 4; % pendulum length (m)
initialangle1 = pi/2; % Initial angle 1
initialangle2 = 0; % Initial angle 2

%====== Sets x and y coordinates of pendulum top =========================
pendulumtopx = 0;
pendulumtopy = l;

fprintf('Single pendulum simulation by James Adams ')
choice = input('Press 1 for a phase portrait or 2 for a time serie plot : ');

iterations = 1; % Sets initial iteration count to 1
pausetime = 0.1; % Pauses animation for this time
runtime = 50; % Runs simulations for this time
tx = 0; % Ensures time series plot remains in the figure window

%============== Solves simple pendulum differential equations =============
deq1=@(t,x) [x(2); -g/l * sin(x(1))]; % Pendulum equations uncoupled
[t,sol] = ode45(deq1,[0 runtime],[initialangle1 initialangle2]); % uses a numerical ode solver
sol1 = sol(:,1)'; % takes the transpose for plots
sol2 = sol(:,2)';

arraysize = size(t); % Defines array size of time intervals
timestep = t(runtime) - t(runtime-1); % Calculates the time step of these intervals
cartesianx = l*sin(sol1); % Converts angles into cartesian coordinates
cartesiany = l*cos(sol2);  
  
%============== plots results at each time interval =======================
for i = 1 : max(arraysize)
subplot(2,1,1)
plotarrayx = [pendulumtopx cartesianx(iterations)];
plotarrayy = [pendulumtopy cartesiany(iterations)];
plot(cartesianx(iterations),cartesiany(iterations),'ko',plotarrayx,plotarrayy,'r-')
title(['Simple pendulum simulation heta = ' num2str(sol1(iterations))],'fontsize',12)
xlabel('x [m]','fontsize',12)
ylabel('y [m]','fontsize',12)
axis([min(cartesianx) max(cartesianx) min(cartesiany) max(cartesiany)])

subplot(2,1,2)
  
% Plots either a phase portrait or time series depending on choice
if choice == 1
plot(sol1(iterations),sol2(iterations),'bo')
hold on
title('Simple pendulum phase portrait','fontsize',12)
xlabel(' heta1','fontsize',12)
ylabel(' heta2','fontsize',12)
axis([min(sol1) max(sol1) min(sol2) max(sol2)])
elseif choice == 2
plot(t(iterations),sol1(iterations),'bo')
title(['Simple pendulum time series for heta1 t = ' num2str(t(iterations))],'fontsize',12)
xlabel('t [seconds]','fontsize',12)
ylabel(' heta1','fontsize',12)
hold on % Holds previous values
axis([0 t(iterations)+(t(2)-t(1)) min(sol1) max(sol1)])
tx = tx + timestep; % Aligns results with the figure window
end
pause(pausetime) % Shows results at each time interval
iterations = iterations + 1; % increases iteration count by 1
end
%=========================== End of program ===============================