Vertcat, I think I need to have consistent rows and columns, erroring out on B matrix creation. Can anyone show me how to make this correct?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
clear all
a=3;
b=13;
c=0;
rG2a=a/2;
rG3a=b/2;
omega2=2000*2*pi/60; %rad/s
alpha2=0;
W2=1;
W3=.5;
W4=.2;
I2=.002;
I3=.008;
mu=0;
m2=W2/32.2;
m3=W3/32.2;
m4=W4/32.2;
m2a=m2*rG2a/a;
m3a=m3*rG3a/(b);
m3b=m3*(b/2)/b;
mA=m2a+m3a;
mB=m3b+m4;
rcrankbalx=a/3*cosd(100); % x position of the crank balancing mass
rcrankbaly=a/3*sind(100); % y position of the crank balancing mass
mcrankbal=m2-mA; % mass of the crank balancing mass at r2/3
theta2=linspace(0,360);
force=zeros(size(theta2));
force (theta2>=0 & theta2<180)=100;
force(theta2>=180 & theta2<=360)=-2000;
theta3=-asind((a.*sind(theta2)./b))+180;
omega3=(a.*cosd(theta2).*omega2)./(b.*cosd(theta3));
alpha3=(a.*alpha2.*cosd(theta2)-a.*omega2.^2.*sind(theta2)+b.*omega3.^2.*sind(theta3))./(b.*cosd(theta3));
R12=-1/2*[a*cosd(theta2);a*sind(theta2)];
R32=1/2*[a*cosd(theta2);a*sind(theta2)];
R23=.5*b*[cosd(theta3);sind(theta3)];
R43=-.5*b*[cosd(theta3);sind(theta3)];
Dddot=-a.*alpha2.*sind(theta2)-a.*omega2.^2.*cosd(theta2)+b.*alpha3.*sind(theta3)+b.*omega3.^2.*cosd(theta3);
AG2=[-rG2a.*alpha2.*sind(theta2)-rG2a.*omega2.^2.*cosd(theta2);rG2a.*alpha2.*cosd(theta2)-rG2a.*omega2.^2.*sind(theta2)];
Aa=[-a.*alpha2*sind(theta2)-a.*omega2.^2.*cosd(theta2); a.*alpha2.*cosd(theta2)-a.*omega2.^2.*sind(theta2)];
Ag3a=[-rG3a.*alpha3.*sind(theta3)-rG3a.*omega3.^2.*cosd(theta3);rG3a.*alpha3.*cosd(theta3)-rG3a.*omega3.^2.*sind(theta3)];
AG3=Aa+Ag3a;
AG4=[Dddot];
A=[1 0 1 0 0 0 0 0
0 1 0 1 0 0 0 0
-R12(2) R12(1) -R32(2) R32(1) 0 0 0 1
0 0 -1 0 1 0 0 0
0 0 0 -1 0 1 0 0
0 0 R23(2) -R23(1) -R43(2) R43(1) 0 0
0 0 0 0 -1 0 0 0
0 0 0 0 0 -1 1 0]
B=[m2*AG2(1,:)
m2*AG2(2,:)
I2*alpha2
m3*AG3(1,:)-force(1,:)
m3*AG3(2,:)
I3*alpha3(1,:)
m4*AG4(1,:)-force(1,:)
0]
0 Commenti
Risposte (3)
Arif Hoq
il 4 Dic 2022
try this:
a=3;
b=13;
c=0;
rG2a=a/2;
rG3a=b/2;
omega2=2000*2*pi/60; %rad/s
alpha2=0;
W2=1;
W3=.5;
W4=.2;
I2=.002;
I3=.008;
mu=0;
m2=W2/32.2;
m3=W3/32.2;
m4=W4/32.2;
m2a=m2*rG2a/a;
m3a=m3*rG3a/(b);
m3b=m3*(b/2)/b;
mA=m2a+m3a;
mB=m3b+m4;
rcrankbalx=a/3*cosd(100); % x position of the crank balancing mass
rcrankbaly=a/3*sind(100); % y position of the crank balancing mass
mcrankbal=m2-mA; % mass of the crank balancing mass at r2/3
theta2=linspace(0,360);
force=zeros(size(theta2));
force (theta2>=0 & theta2<180)=100;
force(theta2>=180 & theta2<=360)=-2000;
theta3=-asind((a.*sind(theta2)./b))+180;
omega3=(a.*cosd(theta2).*omega2)./(b.*cosd(theta3));
alpha3=(a.*alpha2.*cosd(theta2)-a.*omega2.^2.*sind(theta2)+b.*omega3.^2.*sind(theta3))./(b.*cosd(theta3));
R12=-1/2*[a*cosd(theta2);a*sind(theta2)];
R32=1/2*[a*cosd(theta2);a*sind(theta2)];
R23=.5*b*[cosd(theta3);sind(theta3)];
R43=-.5*b*[cosd(theta3);sind(theta3)];
Dddot=-a.*alpha2.*sind(theta2)-a.*omega2.^2.*cosd(theta2)+b.*alpha3.*sind(theta3)+b.*omega3.^2.*cosd(theta3);
AG2=[-rG2a.*alpha2.*sind(theta2)-rG2a.*omega2.^2.*cosd(theta2);rG2a.*alpha2.*cosd(theta2)-rG2a.*omega2.^2.*sind(theta2)];
Aa=[-a.*alpha2*sind(theta2)-a.*omega2.^2.*cosd(theta2); a.*alpha2.*cosd(theta2)-a.*omega2.^2.*sind(theta2)];
Ag3a=[-rG3a.*alpha3.*sind(theta3)-rG3a.*omega3.^2.*cosd(theta3);rG3a.*alpha3.*cosd(theta3)-rG3a.*omega3.^2.*sind(theta3)];
AG3=Aa+Ag3a;
AG4=[Dddot];
A=[1 0 1 0 0 0 0 0
0 1 0 1 0 0 0 0
-R12(2) R12(1) -R32(2) R32(1) 0 0 0 1
0 0 -1 0 1 0 0 0
0 0 0 -1 0 1 0 0
0 0 R23(2) -R23(1) -R43(2) R43(1) 0 0
0 0 0 0 -1 0 0 0
0 0 0 0 0 -1 1 0]
B=[m2*AG2(1,:),m2*AG2(2,:),I2*alpha2,m3*AG3(1,:)-force(1,:),m3*AG3(2,:),I3*alpha3(1,:),m4*AG4(1,:)-force(1,:)]
0 Commenti
Walter Roberson
il 4 Dic 2022
clear all
a=3;
b=13;
c=0;
rG2a=a/2;
rG3a=b/2;
omega2=2000*2*pi/60; %rad/s
alpha2=0;
W2=1;
W3=.5;
W4=.2;
I2=.002;
I3=.008;
mu=0;
m2=W2/32.2;
m3=W3/32.2;
m4=W4/32.2;
m2a=m2*rG2a/a;
m3a=m3*rG3a/(b);
m3b=m3*(b/2)/b;
mA=m2a+m3a;
mB=m3b+m4;
rcrankbalx=a/3*cosd(100); % x position of the crank balancing mass
rcrankbaly=a/3*sind(100); % y position of the crank balancing mass
mcrankbal=m2-mA; % mass of the crank balancing mass at r2/3
theta2=linspace(0,360);
force=zeros(size(theta2));
force (theta2>=0 & theta2<180)=100;
force(theta2>=180 & theta2<=360)=-2000;
theta3=-asind((a.*sind(theta2)./b))+180;
omega3=(a.*cosd(theta2).*omega2)./(b.*cosd(theta3));
alpha3=(a.*alpha2.*cosd(theta2)-a.*omega2.^2.*sind(theta2)+b.*omega3.^2.*sind(theta3))./(b.*cosd(theta3));
R12=-1/2*[a*cosd(theta2);a*sind(theta2)];
R32=1/2*[a*cosd(theta2);a*sind(theta2)];
R23=.5*b*[cosd(theta3);sind(theta3)];
R43=-.5*b*[cosd(theta3);sind(theta3)];
Dddot=-a.*alpha2.*sind(theta2)-a.*omega2.^2.*cosd(theta2)+b.*alpha3.*sind(theta3)+b.*omega3.^2.*cosd(theta3);
AG2=[-rG2a.*alpha2.*sind(theta2)-rG2a.*omega2.^2.*cosd(theta2);rG2a.*alpha2.*cosd(theta2)-rG2a.*omega2.^2.*sind(theta2)];
Aa=[-a.*alpha2*sind(theta2)-a.*omega2.^2.*cosd(theta2); a.*alpha2.*cosd(theta2)-a.*omega2.^2.*sind(theta2)];
Ag3a=[-rG3a.*alpha3.*sind(theta3)-rG3a.*omega3.^2.*cosd(theta3);rG3a.*alpha3.*cosd(theta3)-rG3a.*omega3.^2.*sind(theta3)];
AG3=Aa+Ag3a;
AG4=[Dddot];
A=[1 0 1 0 0 0 0 0
0 1 0 1 0 0 0 0
-R12(2) R12(1) -R32(2) R32(1) 0 0 0 1
0 0 -1 0 1 0 0 0
0 0 0 -1 0 1 0 0
0 0 R23(2) -R23(1) -R43(2) R43(1) 0 0
0 0 0 0 -1 0 0 0
0 0 0 0 0 -1 1 0]
whos AG2 AG3 AG4 I2 I3 alpha2 alpha3 force m2 m3 m4
B = {m2*AG2(1,:)
m2*AG2(2,:)
I2*alpha2
m3*AG3(1,:)-force(1,:)
m3*AG3(2,:)
I3*alpha3(1,:)
m4*AG4(1,:)-force(1,:)
0 }
cellfun(@size, B, 'uniform', 0)
B = vertcat(B{:})
Notice that I2 and alpha2 are both scalars, so their product is scalar. You have a scalar there; and also a scalar 0 at the end
0 Commenti
Voss
il 4 Dic 2022
Try this:
n_col = size(AG2,2);
B=[m2*AG2(1,:)
m2*AG2(2,:)
I2*alpha2*ones(1,n_col)
m3*AG3(1,:)-force(1,:)
m3*AG3(2,:)
I3*alpha3(1,:)
m4*AG4(1,:)-force(1,:)
zeros(1,n_col)]
0 Commenti
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!