i am tring to use matrices to solve for the linear equation. But the q in the matrices is itself a vector. The answer i need to get is a vector too.

1 view (last 30 days)
% prerequizte
A_E = 16;
E_C = 13;
F_E = 3;
O_F = 13;
D_F = 13;
B_C = 32;
O_E = 16;
A_E1 = 16;
A_C1 = 29;
D_C1 = 3;
O_F1 = 13;
D_F1 = 13;
D_B1 = 35
O_E1 = 16;
%A_0 = sqrt((x_a-x_0)^2-(y_a-y_0)^2);
r = 2; % opening time
t = [0:0.2:2];
%theta_b =
%q = acos(0.5)
% for 0
x_0 = 0;
y_0 = 0;
% for A
x_a = 0
y_a = -17.5-12.5*cos(pi*t/r);
y_aa = diff(y_a)
y_aaa = diff(y_aa)
A_0 = sqrt((y_a-y_0).^2);
% find angle
theta_a3 = acosd((O_E^2-A_E^2-A_0.^2)./(-2*A_0.*A_E)); %theta 3
theta_o0 = acosd((A_E^2-A_0.^2-O_E^2)./(-2*O_E*A_0)); %theta
theta_a33 = diff(theta_a3);
theta_a333 = diff(theta_a33);
theta_o00 = diff(theta_o0);
theta_o000 = diff(theta_o00);
theta_a = 90-acosd((O_E^2-A_E^2-A_0.^2)./(-2*A_0.*A_E)); %theta 3
theta_o = 90-acosd((A_E^2-A_0.^2-O_E^2)./(-2*O_E*A_0));
theta_f = acosd((A_0.^2-O_E^2-A_E^2)./(-2*O_E*A_E))-theta_o;
theta_e = theta_f;
theta_b = 180-(acosd((O_E^2-A_E^2-A_0.^2)./(-2*A_0.*A_E))+acosd((A_E^2-A_0.^2-O_E^2)./(-2*O_E*A_0)))-theta_e;
%define the position of each joint
% for E
x_e = x_0+cosd(theta_a)*A_E
y_e = y_a+sind(theta_a)*A_E;
% for F
x_f = x_0+cosd(theta_o)*O_F
y_f = y_e+sind(theta_o)*F_E
% for D
x_d = x_f+cosd(theta_f)*D_F
y_d = y_f+sind(theta_f)*D_F;
% for c
x_c = x_e+cosd(theta_e)*E_C;
y_c = y_e+sind(theta_e)*E_C;
% for B
x_b = x_c+cosd(theta_b)*B_C;
y_b = y_c-sind(theta_b)*B_C;
% find the velocity and the velocity plot
k = [0:0.105:2]
y_ee = diff(y_e)
y_fe = diff(y_f)
y_de = diff(y_d)
y_ce = diff(y_c)
y_be = diff(y_b)
x_ee = diff(x_e)
x_fe = diff(x_f)
x_de = diff(x_d)
x_ce = diff(x_c)
x_be = diff(x_b)
v_e = sqrt(y_ee.^2+x_ee.^2);
v_f = sqrt(y_fe.^2+x_fe.^2);
v_d = sqrt(y_de.^2+x_de.^2);
v_c = sqrt(y_ce.^2+x_ce.^2);
v_b = sqrt(y_be.^2+x_be.^2);
% find the acceleration and the acceleration plot
p = [0:0.25:2]
y_eee = diff(y_e,2)
y_fee = diff(y_f,2)
y_dee = diff(y_d,2)
y_cee = diff(y_c,2)
y_bee = diff(y_b,2)
x_eee = diff(x_e,2)
x_fee = diff(x_f,2)
x_dee = diff(x_d,2)
x_cee = diff(x_c,2)
x_bee = diff(x_b,2)
mAE = 1.6 %kg
mAC = 2.9 %kg
mOF = 1.3 %kg
mOE = 1.6 %kg
mDC = 0.3 %kg
mDB = 3.5 %kg
mDF = 1.3 %kg
mB = 2.0 %kg
% find the left hand side equation
q_1 = -A_E1*sin(theta_a3)
q_2 = A_E1*cos(theta_a3)
q_3 = -A_C1*sin(theta_a3)
q_4 = A_C1*cos(theta_a3)
q_5 = -O_F1*sin(theta_o0)
q_6 = O_F1*cos(theta_o0)
q_7 = -O_E1*sin(theta_o0)
q_8 = O_E1*cos(theta_o0)
q_9 = D_F1*sin(theta_a3)
q_10 = -D_F1*cos(theta_a3)
q_11 = D_C1*sin(theta_a3)
q_12 = D_C1*cos(theta_a3)
q_13 = D_B1*sin(theta_a3)
% find the right hand side equation
F2y = mAC*(y_aaa+ y_cee + y_eee)
F2x = mAC*(0+ x_cee+x_eee)
F3y = mOE*(0+y_fee+y_eee)
F3x = mOE*(0+x_fee+x_eee)
F4x = 0
F4y = 0
F5x = mDF*(x_dee+x_fee);
F5y = mDF*(y_dee+y_fee);
F6x = mDB*(x_dee+x_cee);
F6y = mDB*(y_dee+ y_cee)+mB*9.81;
M_1 = 1/12*mAC*(A_C1)^2*theta_a333;
M_2 = 1/12*mOE*(O_E1)^2*theta_o000;
M_3 = 1/12*mDF*(D_F1)^2*theta_a333;
M_4 = 1/12*mDB*(D_B1)^2*theta_a333%+D_B1.*theta_a3;
equ = [0 1 0 -1 0 0 0 0 0 0 0 -1;1 0 -1 0 0 0 0 0 0 0 -1 0;0 0 0 0 0 0 0 1 0 -1 0 1;0 0 0 0 0 0 1 0 -1 0 1 0;0 0 0 0 1 0 -1 0 0 0 0 0;0 0 0 0 0 1 0 -1 0 0 0 0;0 0 1 0 -1 0 0 0 0 0 0 0;0 0 0 1 0 -1 0 0 0 0 0 0;0 0 q_4 q_3 0 0 0 0 0 0 q_2 q_1;0 0 0 0 0 0 q_6 q_5 0 0 q_8 q_7;0 0 0 0 q_10 q_9 0 0 0 0 0 0;0 0 q_12 q_11 0 0 0 0 0 0 0 0]
equ_2 = [F2y;F2x;F3y;F3x;F4x;F4y;F5x;F5y;F6x;F6y;M_1;M_2:M_3;M_4];
Sol = inv(equ)*equ_2;
  4 Comments
kaixi gu
kaixi gu on 4 Mar 2023
Thank you for correcting my mistakes. yes that make sense. i corrected with the gradient. now i just can't figure out how to plug in those 1*11 value into the matrixes. Because i do want to get the Sol with respect to those 1*11 q value.
Star Strider
Star Strider on 4 Mar 2023
All the columns in ‘equ’ must be equal lengths ‘N’ to create the 11xN matrix. You need to decide what ‘N’ should be, and then create the matrix.

Sign in to comment.

Answers (1)

Arka
Arka on 6 Mar 2023
Edited: Arka on 6 Mar 2023
Hi,
The code and the error generated from the code are given below:
% prerequizte
A_E = 16;
E_C = 13;
F_E = 3;
O_F = 13;
D_F = 13;
B_C = 32;
O_E = 16;
A_E1 = 16;
A_C1 = 29;
D_C1 = 3;
O_F1 = 13;
D_F1 = 13;
D_B1 = 35;
O_E1 = 16;
%A_0 = sqrt((x_a-x_0)^2-(y_a-y_0)^2);
r = 2; % opening time
t = [0:0.2:2];
%theta_b =
%q = acos(0.5)
% for 0
x_0 = 0;
y_0 = 0;
% for A
x_a = 0;
y_a = -17.5-12.5*cos(pi*t/r);
y_aa = diff(y_a);
y_aaa = diff(y_aa);
A_0 = sqrt((y_a-y_0).^2);
% find angle
theta_a3 = acosd((O_E^2-A_E^2-A_0.^2)./(-2*A_0.*A_E)); %theta 3
theta_o0 = acosd((A_E^2-A_0.^2-O_E^2)./(-2*O_E*A_0)); %theta
theta_a33 = diff(theta_a3);
theta_a333 = diff(theta_a33);
theta_o00 = diff(theta_o0);
theta_o000 = diff(theta_o00);
theta_a = 90-acosd((O_E^2-A_E^2-A_0.^2)./(-2*A_0.*A_E)); %theta 3
theta_o = 90-acosd((A_E^2-A_0.^2-O_E^2)./(-2*O_E*A_0));
theta_f = acosd((A_0.^2-O_E^2-A_E^2)./(-2*O_E*A_E))-theta_o;
theta_e = theta_f;
theta_b = 180-(acosd((O_E^2-A_E^2-A_0.^2)./(-2*A_0.*A_E))+acosd((A_E^2-A_0.^2-O_E^2)./(-2*O_E*A_0)))-theta_e;
%define the position of each joint
% for E
x_e = x_0+cosd(theta_a)*A_E;
y_e = y_a+sind(theta_a)*A_E;
% for F
x_f = x_0+cosd(theta_o)*O_F;
y_f = y_e+sind(theta_o)*F_E;
% for D
x_d = x_f+cosd(theta_f)*D_F;
y_d = y_f+sind(theta_f)*D_F;
% for c
x_c = x_e+cosd(theta_e)*E_C;
y_c = y_e+sind(theta_e)*E_C;
% for B
x_b = x_c+cosd(theta_b)*B_C;
y_b = y_c-sind(theta_b)*B_C;
% find the velocity and the velocity plot
k = [0:0.105:2];
y_ee = diff(y_e);
y_fe = diff(y_f);
y_de = diff(y_d);
y_ce = diff(y_c);
y_be = diff(y_b);
x_ee = diff(x_e);
x_fe = diff(x_f);
x_de = diff(x_d);
x_ce = diff(x_c);
x_be = diff(x_b);
v_e = sqrt(y_ee.^2+x_ee.^2);
v_f = sqrt(y_fe.^2+x_fe.^2);
v_d = sqrt(y_de.^2+x_de.^2);
v_c = sqrt(y_ce.^2+x_ce.^2);
v_b = sqrt(y_be.^2+x_be.^2);
% find the acceleration and the acceleration plot
p = [0:0.25:2];
y_eee = diff(y_e,2);
y_fee = diff(y_f,2);
y_dee = diff(y_d,2);
y_cee = diff(y_c,2);
y_bee = diff(y_b,2);
x_eee = diff(x_e,2);
x_fee = diff(x_f,2);
x_dee = diff(x_d,2);
x_cee = diff(x_c,2);
x_bee = diff(x_b,2);
mAE = 1.6; %kg
mAC = 2.9; %kg
mOF = 1.3; %kg
mOE = 1.6; %kg
mDC = 0.3; %kg
mDB = 3.5; %kg
mDF = 1.3; %kg
mB = 2.0; %kg
% find the left hand side equation
q_1 = -A_E1*sin(theta_a3);
q_2 = A_E1*cos(theta_a3);
q_3 = -A_C1*sin(theta_a3);
q_4 = A_C1*cos(theta_a3);
q_5 = -O_F1*sin(theta_o0);
q_6 = O_F1*cos(theta_o0);
q_7 = -O_E1*sin(theta_o0);
q_8 = O_E1*cos(theta_o0);
q_9 = D_F1*sin(theta_a3);
q_10 = -D_F1*cos(theta_a3);
q_11 = D_C1*sin(theta_a3);
q_12 = D_C1*cos(theta_a3);
q_13 = D_B1*sin(theta_a3);
% find the right hand side equation
F2y = mAC*(y_aaa+ y_cee + y_eee);
F2x = mAC*(0+ x_cee+x_eee);
F3y = mOE*(0+y_fee+y_eee);
F3x = mOE*(0+x_fee+x_eee);
F4x = 0;
F4y = 0;
F5x = mDF*(x_dee+x_fee);
F5y = mDF*(y_dee+y_fee);
F6x = mDB*(x_dee+x_cee);
F6y = mDB*(y_dee+ y_cee)+mB*9.81;
M_1 = 1/12*mAC*(A_C1)^2*theta_a333;
M_2 = 1/12*mOE*(O_E1)^2*theta_o000;
M_3 = 1/12*mDF*(D_F1)^2*theta_a333;
M_4 = 1/12*mDB*(D_B1)^2*theta_a333;%+D_B1.*theta_a3;
equ = [0 1 0 -1 0 0 0 0 0 0 0 -1;1 0 -1 0 0 0 0 0 0 0 -1 0;0 0 0 0 0 0 0 1 0 -1 0 1;0 0 0 0 0 0 1 0 -1 0 1 0;0 0 0 0 1 0 -1 0 0 0 0 0;0 0 0 0 0 1 0 -1 0 0 0 0;0 0 1 0 -1 0 0 0 0 0 0 0;0 0 0 1 0 -1 0 0 0 0 0 0;0 0 q_4 q_3 0 0 0 0 0 0 q_2 q_1;0 0 0 0 0 0 q_6 q_5 0 0 q_8 q_7;0 0 0 0 q_10 q_9 0 0 0 0 0 0;0 0 q_12 q_11 0 0 0 0 0 0 0 0]
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
equ_2 = [F2y;F2x;F3y;F3x;F4x;F4y;F5x;F5y;F6x;F6y;M_1;M_2:M_3;M_4];
Sol = inv(equ)*equ_2;
From the error, it seems that the equ matrix cannot be created, because there is a mismatch in the dimensions of the arrays that you are trying to concatenate.
If you check, the q_x (where x = 1:13) variables have a dimension of 1x11, but the other values (0, 1, and -1) are scalars, i.e. they have a dimension of 1x1.
In rows such as [0 1 0 -1 0 0 0 0 0 0 0 -1], the dimension is 1x12, but in rows such as [0 0 q_12 q_11 0 0 0 0 0 0 0 0], the dimension is 1x32.
This is causing the error.
You need to modify the code so that the vector values are consistent. Then, the concatenation will be successful.

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!