Plot Rows of Matrix which are a function

1 view (last 30 days)
ZackFF
ZackFF on 19 Nov 2019
Edited: dpb on 20 Nov 2019
I was tasked with solving a slider crank mechanism's kinetics analytically and i am unsure of how to plot the solved system of equations as they change over time. To clarify, I wrote out my equations for forces and moments then input the coefficients into a matrix and the summation into a sperate matrix as A = @(t) ... and B = @(t) ... then solved using X = @(t) A(t)\B(t) and now require to plot how each value of x changes over time. Thank you
  5 Comments
ZackFF
ZackFF on 20 Nov 2019
clear;clc
disp('Assume system starts at top dead center (theta=0)')
mc = 0.89; %input('Please input a mass for the crank (kg): ');
ml = 0.51; %input('Please input a mass for the connecting rod(kg): ');
mp = 0.32; %input('Please input a mass for the piston(kg): ');
omega1i = 4000*(2*pi)/60; %input('Please input an initial angular velocity for the crank (rad/s): ');
alpha1 = 0; %input('Please input an angular acceleration for the crank (rad/s2): ');
r = 0.047; %input('Please input a length for the crank(m): ');
l = 0.2254; %input('Please input a length for the connecting rod(m): ');
mrecip = mp +(ml/2);
n=l/r;
Ig1 = (1/12)*mc*r^2;
Ig2 = (1/12)*ml*l^2;
omega2i = (omega1i)*(1/n);
angle = [(1/2)*alpha1, omega1i, -4*pi];
tt = roots(angle);
ttp = tt(tt>0);
theta = @(t) (1/2)*alpha1*t.^2 + omega1i.*t;
omega1t = @(t) alpha1.*t + omega1i ;
omega2t = @(t) omega1t(t).*(1/n).*cos(theta(t)) + omega2i;
alpha2 = @(t) omega1t(t).^2.*(1/n).*sin(theta(t)) + omega2i.*t;
ag1x = @(t) -(alpha1.*t + omega1i).^2 .*(r/2).*cos(theta(t)) - alpha1.*(r/2).*sin(theta(t));
ag1y = @(t) -(alpha1.*t + omega1i).^2 .*(r/2).*sin(theta(t)) + alpha1.*(r/2).*cos(theta(t));
ag2x = @(t) -omega1t(t).^2.*r.*cos(theta(t))-alpha1.*r.*sin(theta(t))-omega2t(t).^2.*(l/2) + alpha2(t).*(r/2).*sin(theta(t));
ag2y = @(t) -omega1t(t).^2.*r.*sin(theta(t))+alpha1.*r.*cos(theta(t))+omega2t(t).^2*(r/2).*sin(theta(t)) + alpha2(t).*(l/2);
ag3x = @(t) -omega1t(t).^2.*r.*cos(theta(t))-alpha1.*r.*sin(theta(t))-omega2t(t).^2.*(l) + alpha2(t).*(r).*sin(theta(t));
FOOBx = @(t) mrecip.*r.*(omega1t(t)).^2.*(cos(theta(t)) + (1/n).*cos(2*theta(t))) + mc*(r/2)*(omega1t(t))^2 * cos(theta(t)) +(ml/2)*r*(omega1t(t))^2*cos(theta(t));
FOOBy = @(t) mc.*(r/2)*(omega1t(t))^2 * sin(theta(t)) +(ml/2)*r*(omega1t(t))^2*sin(theta(t));
A = @(t) [1,0,1,0,0,0,0;0,1,0,1,0,0,0;(r/2)*sin(theta(t)), (-r/2)*cos(theta(t)),(-r/2)*sin(theta(t)),(r/2)*cos(theta(t)),0,0,0;0,0,-1,0,1,0,0;0,0,0,-1,0,1,0;0,0,(r/2)*sin(theta(t)),(l/2),(r/2)*sin(theta(t)),(l/2),0;0,0,0,0,-1,0,0];
B = @(t) [mc*ag1x(t);mc*ag1y(t);Ig1*alpha1;ml*ag2x(t);ml*ag2y(t);Ig2*alpha2(t);mp*ag3x(t)];
X = @(t) A(t)\B(t)
t1 = linspace(0,ttp);
figure(1)
plot(t1,omega1t(t1),t1,omega2t(t1));
title('Line Plot of Angular Velocities of Links 1 and 2')
xlabel('Time (s)')
ylabel('Angular Velocity (rad/s)')
legend({'link 1', 'link 2'}, 'Location','east')
figure(2)
plot(t1,alpha1,t1,alpha2(t1));
title('Line Plot of Angular Accelerations of Links 1 and 2')
xlabel('Time (s)')
ylabel('Angular Acceleration (rad/s2)')
legend({'link 1', 'link 2'}, 'Location','east')
figure(3)
plot(t1,ag1x(t1), t1, ag1y(t1))
figure(4)
plot(t1,ag2x(t1), t1, ag2y(t1))
figure(5)
plot(t1,FOOBx(t1),t1,FOOBy(t1))
dpb
dpb on 20 Nov 2019
Edited: dpb on 20 Nov 2019
Something's wrong in your formulation...the A matrix is singular...
>> arrayfun(@(x)rcond(A(x)),t)
ans =
Columns 1 through 7
0 0 0 0 0 0 0
Columns 8 through 14
0 0 0 0 0 0 0
Columns 15 through 20
0 0 0 0 0 0
>>
If you look at the reformatted construction of A I did above to align elements, the last column is all zeros.
All X values thus end up turning out as either +/-inf or nan...

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!