MATLAB Code and Comments

The MATLAB code is based on the equations given in the analysis section. The model plots the mechanical advantage and force_out when force_in is 180lb. The code is made using MATLAB 2020a.


The majority of the calculations are done in a single for loop. This represents the input variable, theta_2. For every degree for theta_2 between 165° and 15°, the position and velocity of the other vectors in the mechanism are calculated and stored.

The code uses the syms library to create equations with unknown variables. Vectors are described using phasor notation when available. For each position and velocity analysis, 2 equations are created: real and imaginary. Both of these are set to 0, and are labeled in pairs (ex: eqn1 & eqn2, eqn3 & eqn4, etc.). These equations are solved numerically using vpasolve, which returns the numerical answers for the syms variables in the equations. The variables are updated for every iteration of the for loop.


MATLAB Analysis
%ME 350R Project Analysis
clear all
close all
e=exp(1);
%Smaller 4-bar mechanism with toggle
a =2.5; % toggle link
b =7;
c =6; % plastic link between back of chair and armrest
d =10.5; % inches, grounded link
f = 6+5/8;% Distance from rear to front leg along armrest
g =7; % from armrest to the middle connection of the front leg
h =12.5; % length of the seat (from front leg to toggle connection)
hi = 1.25; % length normal to g, used to connect to the backrest
k = 23.5; % total length of front leg
r_seat = 20; % radius of force applied to seat
r_back = 28; % radius of force applied to 

t2=deg2rad([180-15:-1:15]); % theta of toggle link from close to open pos.

%intial guesses (closed pos.)

t3=deg2rad(45);
t4=deg2rad(120);
t6=deg2rad(175);
t7=deg2rad(175);
w2=1;

%arrays for memory managment

t3_arr=zeros(1,length(t2));
t4_arr=zeros(1,length(t2));
w3_arr=zeros(1,length(t2));
w4_arr=zeros(1,length(t2));
t6_arr=zeros(1,length(t2));
t7_arr=zeros(1,length(t2));
w6_arr=zeros(1,length(t2));
w7_arr=zeros(1,length(t2));
LL_arr_x=zeros(1,length(t2));
LL_arr_y=zeros(1,length(t2));
Ma_seat=zeros(1,length(t2));
Ma_back=zeros(1,length(t2));
Fa_seat=zeros(1,length(t2));
Fa_back=zeros(1,length(t2));

for i=1:length(t2)
    
    %Initial Four Bar mechanism assumption
    
    t3_old=double(t3);
    t4_old=double(t4);
    syms t3 t4
    R2=a*e^(j*t2(i));
    R3=b*e^(j*t3);
    R4=c*e^(j*t4);
    R0=d;
    % Vector Loop:  R2+R3=R0+R4
    eqn1=b*cos(t3)-c*cos(t4)==real(R0-R2);
    eqn2=b*sin(t3)-c*sin(t4)==imag(R0-R2);
    [t3,t4]=vpasolve([eqn1,eqn2],[t3,t4],[t3_old,t4_old]);
    t3_arr(i)=double(t3);
    t4_arr(i)=double(t4);
    R3=eval(R3);
    R4=eval(R4);

	% Velocity Analysis
    syms w3 w4
    V2=j*w2*R2;
    V3=j*w3*R3;
    V4=j*w4*R4;
    % V3-V4=V2
    eqn5=w3*real(j*R3)-w4*real(j*R4)==real(V2);
    eqn6=w3*imag(j*R3)-w4*imag(j*R4)==imag(V2);
    [w3,w4]=solve([eqn5,eqn6],[w3,w4]);
    w3_arr(i)=double(w3);
    w4_arr(i)=double(w4);
    V3=eval(V3);V4=eval(V4);
    
    %Extending Results to 2nd Four Bar Mechanism
    
    % Vector loop of second Mechanism
    % R4=R5+R6+R7+R3
    % R4 and R3 are known, R5 is derived from R4, 2 variables can be solved
    t6_old=double(t6);
    t7_old=double(t7);
    syms t6 t7
    R5=eval(f*e^(j*(t4-pi))); % rear leg to front leg along armrest
    R6=g*e^(j*t7); % Front leg to seat
    R7=h*e^(j*t7)+hi*e^(j*(t7-pi/2)); % link needs to include a normal offset
    % R7+R6=R4-R3-R5
    eqn3=h*cos(t7)+hi*sin(t7)+g*cos(t6)==real(R4-R3-R5);
    eqn4=h*sin(t7)-hi*cos(t7)+g*sin(t6)==imag(R4-R3-R5);
    [t6,t7]=vpasolve([eqn3,eqn4],[t6,t7],[t6_old,t7_old]);
    t6_arr(i)=double(t6);
    t7_arr(i)=double(t7);
    R6=eval(R6);R7=eval(R7);
    
	% Calculate the position of the end of the lower leg
    % It should track the curvature of the slider
    R_LL=eval(R5+k*e^(j*t6));
    LL_arr_x(i)=real(R_LL);
    LL_arr_y(i)=imag(R_LL);
    
	% Velocity Analysis
    syms w6 w7
    V5=eval(j*w4*R5);
    V6=j*w6*R6;
    V7=j*w7*R7;
    eqn7=w7*real(j*R7)+w6*real(j*R6)==real(V4-V3-V5);
    eqn8=w7*imag(j*R7)+w6*imag(j*R6)==imag(V4-V3-V5);
    [w6,w7]=solve([eqn7,eqn8],[w6,w7]);
    w6_arr(i)=double(w6);
    w7_arr(i)=double(w7);
    V6=eval(V6);V7=eval(V7);
    
	%Calculate Position of tip of Backrest and seat for force application
    R_BR=R2+R3/b*r_back;
    R_seat=R2-hi*e^(j*(double(t7)-pi/2))+r_seat*e^(j*double(t7));
    
	% Caluclate Mechanical Advantage
    Ma_seat(i)=abs(w7/w6);
    Ma_back(i)=abs(w3/w6);
    % Calculate Force Applied based on Mechanical Advantage
    Fa_seat(i)=abs(Ma_seat(i)*abs(R_seat)*180/abs(R0+R5+R_LL));
    Fa_back(i)=abs(Ma_back(i)*abs(R_BR)*180/abs(R0+R5+R_LL));
end

plot(rad2deg(t2),Ma_seat,'-')
hold on
plot(rad2deg(t2),Ma_back,'--')
title("Mechanical Advantage from chair to locking pin vs Theta (deg)")
xlabel("Toggle Positon Relative to closest link (deg)")
ylabel("Mechanical Advantage")
legend("Seat","Backrest")
figure
plot(rad2deg(t2),Fa_seat,'-')
hold on
plot(rad2deg(t2),Fa_back,'--')
legend("Seat","Backrest")
title("Force Applied to Locking Pin vs Theta (deg)")
xlabel("Toggle Positon Relative to closest link (deg)")
ylabel("Force at Pin from Force Applied at Maxmimum Positions")