|
| 1 | +% Author: Mansour Torabi |
| 2 | +% Email: smtoraabi@ymail.com |
| 3 | + |
| 4 | +%% |
| 5 | +clc, clear |
| 6 | + |
| 7 | +syms th0 th x Dth0 Dth Dx |
| 8 | +syms k M m l R r g |
| 9 | + |
| 10 | +%% Kinetic and Potential Energy |
| 11 | + |
| 12 | +v1x = l1*Dth1*cos(th1) ; |
| 13 | +v1y = -l1*Dth1*sin(th1); |
| 14 | + |
| 15 | +v2x = l2*Dth2*cos(th2) ; |
| 16 | +v2y = -l2*Dth2*sin(th2); |
| 17 | + |
| 18 | +v1t = v1x^2 + v1y^2; |
| 19 | +v2t = v2x^2 + v2y^2; |
| 20 | + |
| 21 | +T = 1/2*m1*v1t + 1/2*m2*v2t; |
| 22 | + |
| 23 | +dXX = l0 + l2*sin(th2) - l1*sin(th1); |
| 24 | +dYY = l1*cos(th1) - l2*cos(th2); |
| 25 | +dx = (dXX^2 + dYY^2)^0.5 - l3; |
| 26 | + |
| 27 | +V1 = -m1*g*(l1*cos(th1)) + 1/2*k*dx^2; |
| 28 | +V2 = -m2*g*(l2*cos(th2)); |
| 29 | +V = V1 + V2; |
| 30 | + |
| 31 | +L = T - V; |
| 32 | +%% |
| 33 | +q = [th1, th2]; |
| 34 | +Dq = [Dth1, Dth2]; |
| 35 | +tt = linspace(0, 20, 500); |
| 36 | +Eq = LagrangeDynamicEqDeriver(L, q, Dq); |
| 37 | +l0n = 2; l1n = 1; l2n = 1.5; l3n = 2; |
| 38 | +[SS, xx] = DynamicEqSolver(Eq, q, Dq, [k m1 m2 l0 l1 l2 l3 g],... |
| 39 | + [20,1,3, l0n, l1n, l2n, l3n, 9.81], tt, [pi/6, pi/2.5, 0, 0]); |
| 40 | +%% |
| 41 | +figure; |
| 42 | +plot(tt,xx(:,1),'color',[0,0.6,0],'linewidth',2); |
| 43 | +hold on; |
| 44 | +plot(tt,xx(:,2),'b','linewidth',2); |
| 45 | + |
| 46 | +S1 = sprintf('$ \\theta_1$'); |
| 47 | +S2 = sprintf('$ \\theta_2$'); |
| 48 | +H = legend(S1, S2); |
| 49 | +set(H,'interpreter','latex','fontsize',18,'location','SouthWest'); |
| 50 | + |
| 51 | +hx = xlabel('Time (sec)'); set(hx, 'fontsize', 18); |
| 52 | +hy = ylabel('Angles (rad)- Lenghth (m)'); set(hy, 'fontsize', 18); |
| 53 | +set(gca, 'fontsize', 18); |
| 54 | +saveas(gcf, 'Pic/Ex6.png') |
| 55 | +%% |
| 56 | +Animator6(xx(:,1:2), tt, [l0n, l1n, l2n]) |
| 57 | + |
0 commit comments