Matlab Programming help! Please provide the code for following question. Conside
ID: 3163823 • Letter: M
Question
Matlab Programming help! Please provide the code for following question.
Consider a double pendulum as shown in Figure 2. There are two coordinates of this system: angles theta_1 and theta_2. Corresponding angular velocities are omega_1 and omega_2, and angular accelerations are alpha_1 and alpha_2. The governing equations of the system (with m_1 = m_2 = 1 kg and I_1 = I_2 = 1 m) can be written as: (2 cos(theta^n_1 - theta^n_2) cos(theta^n_1 - theta^n_2) 1) (alpha^n_1 alpha^n_1) = (- 19.6 sin(theta^n_1 + (omega^n_2)^2 sin(theta^n_1 - theta^n_2) - 9.8 sin(theta^n_2 + (omega^n_1)^2 sin(theta^n_1 - theta^n_2) omega^n + 1_1 = omega^n_1 + Delta t alpha^n_1 omega^n + 1_2 = omega^n_2 + Delta t alpha^n_2 theta^n + 1_1 = theta^n_1 + Delta t omega^n_1 theta^n + 1_2 = theta^n_2 + Delta t omega^n_2 At Here, the superscript is the time-step. That is, given each variable at n, we can calculate that at n + 1 using above equations. At n = 1, t^1 = 0, omega^1_1 = omega^1_2 = 0 rad/sec, theta^1_1 = 0 rad, and theta^1_2 = pi/20 rad (rad is radians). Using Delta t = 0.001, solve the above equation until 20 seconds. You will have to use the inverse operator of MATLAB to solve the matrix equation (the first equation). At the end, plot (a) theta_1, vs time, (b) theta_2 vs time and (c) theta_1 vs.theta_2.Explanation / Answer
Given m1=m2=1 kg
L1=l2=1m
u(1)=theta1 u(2)=theta 2 u(3)= rho1 u(4)=rho2
Matlab code
function uprime=doublependulum(t,u,flag,g,l1,l2,m1,m2)
A=(u(3).*u(4).*sin(u(1)-u(2)))./(l1*l2*(m1+m2*sin(u(1)-u(2))).^2);
B=((l2^2*m2*(u(3)).^2+l1^2*(m1+m2)*(u(4)).^2-l1*l2*m2*u(3).*u(4).*cos(u(1)-u(2)))./(2*l1^2*l2^2*(m1+m2*(sin(u(1)-u(2))).^2).^2)).*sin(2*(u(1)-u(2)));
uprime=zeros(4,1);
uprime(1)=(l2*u(3)-l1*u(4).*cos(u(1)-u(2)))./(l1^2*...
l2*(m1+m2*(sin(u(1)-u(2))).^2));
uprime(2)=(l1*(m1+m2)*u(4)-l2*m2*u(3).*cos(u(1)-u(2)))./(l1*l2^2*m2*(m1+m2*(sin(u(1)-u(2))).^2));
uprime(3)=-(m1+m2)*g*l1*sin(u(1))-A+B;
uprime(4)=-m2*g*l2*sin(u(2))+A-B;