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)
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]

Risposte (3)

Arif Hoq
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]
A = 8×8
1.0000 0 1.0000 0 0 0 0 0 0 1.0000 0 1.0000 0 0 0 0 0 -1.5000 0 1.5000 0 0 0 1.0000 0 0 -1.0000 0 1.0000 0 0 0 0 0 0 -1.0000 0 1.0000 0 0 0 0 0 6.5000 0 6.5000 0 0 0 0 0 0 -1.0000 0 0 0 0 0 0 0 0 -1.0000 1.0000 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,:)]
B = 1×601
1.0e+03 * -2.0434 -2.0393 -2.0270 -2.0065 -1.9779 -1.9414 -1.8970 -1.8450 -1.7856 -1.7190 -1.6455 -1.5653 -1.4789 -1.3865 -1.2885 -1.1853 -1.0773 -0.9650 -0.8489 -0.7293 -0.6067 -0.4817 -0.3548 -0.2265 -0.0972 0.0324 0.1619 0.2908 0.4185 0.5445

Walter Roberson
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]
A = 8×8
1.0000 0 1.0000 0 0 0 0 0 0 1.0000 0 1.0000 0 0 0 0 0 -1.5000 0 1.5000 0 0 0 1.0000 0 0 -1.0000 0 1.0000 0 0 0 0 0 0 -1.0000 0 1.0000 0 0 0 0 0 6.5000 0 6.5000 0 0 0 0 0 0 -1.0000 0 0 0 0 0 0 0 0 -1.0000 1.0000 0
whos AG2 AG3 AG4 I2 I3 alpha2 alpha3 force m2 m3 m4
Name Size Bytes Class Attributes AG2 2x100 1600 double AG3 2x100 1600 double AG4 1x100 800 double I2 1x1 8 double I3 1x1 8 double alpha2 1x1 8 double alpha3 1x100 800 double force 1x100 800 double m2 1x1 8 double m3 1x1 8 double m4 1x1 8 double
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 }
B = 8×1 cell array
{[ -2.0434e+03 -2.0393e+03 -2.0270e+03 -2.0065e+03 -1.9779e+03 -1.9414e+03 -1.8970e+03 -1.8450e+03 -1.7856e+03 -1.7190e+03 -1.6455e+03 -1.5653e+03 -1.4789e+03 -1.3865e+03 -1.2885e+03 -1.1853e+03 -1.0773e+03 -965.0370 -848.8575 -729.2600 -606.7260 -481.7489 -354.8321 -226.4864 -97.2287 32.4205 161.9391 290.8056 418.5012 544.5116 668.3295 789.4562 907.4041 1.0217e+03 1.1319e+03 1.2375e+03 1.3381e+03 1.4334e+03 1.5229e+03 1.6062e+03 1.6831e+03 1.7532e+03 1.8162e+03 1.8720e+03 1.9202e+03 1.9606e+03 1.9932e+03 2.0177e+03 2.0341e+03 2.0424e+03 2.0424e+03 2.0341e+03 2.0177e+03 1.9932e+03 1.9606e+03 1.9202e+03 1.8720e+03 1.8162e+03 1.7532e+03 1.6831e+03 1.6062e+03 1.5229e+03 1.4334e+03 1.3381e+03 1.2375e+03 1.1319e+03 1.0217e+03 907.4041 789.4562 668.3295 544.5116 418.5012 290.8056 161.9391 32.4205 -97.2287 -226.4864 -354.8321 -481.7489 -606.7260 -729.2600 -848.8575 -965.0370 -1.0773e+03 -1.1853e+03 -1.2885e+03 -1.3865e+03 -1.4789e+03 -1.5653e+03 -1.6455e+03 -1.7190e+03 -1.7856e+03 -1.8450e+03 -1.8970e+03 -1.9414e+03 -1.9779e+03 -2.0065e+03 -2.0270e+03 -2.0393e+03 -2.0434e+03]} {[ 0 -129.6002 -258.6786 -386.7153 -513.1949 -637.6080 -759.4537 -878.2414 -993.4926 -1.1047e+03 -1.2115e+03 -1.3135e+03 -1.4101e+03 -1.5011e+03 -1.5860e+03 -1.6645e+03 -1.7363e+03 -1.8012e+03 -1.8587e+03 -1.9088e+03 -1.9512e+03 -1.9858e+03 -2.0124e+03 -2.0308e+03 -2.0411e+03 -2.0431e+03 -2.0370e+03 -2.0226e+03 -2.0001e+03 -1.9695e+03 -1.9310e+03 -1.8847e+03 -1.8309e+03 -1.7696e+03 -1.7013e+03 -1.6261e+03 -1.5443e+03 -1.4563e+03 -1.3625e+03 -1.2631e+03 -1.1587e+03 -1.0496e+03 -936.3384 -819.2600 -698.8827 -575.6913 -450.1817 -322.8595 -194.2372 -64.8327 64.8327 194.2372 322.8595 450.1817 575.6913 698.8827 819.2600 936.3384 1.0496e+03 1.1587e+03 1.2631e+03 1.3625e+03 1.4563e+03 1.5443e+03 1.6261e+03 1.7013e+03 1.7696e+03 1.8309e+03 1.8847e+03 1.9310e+03 1.9695e+03 2.0001e+03 2.0226e+03 2.0370e+03 2.0431e+03 2.0411e+03 2.0308e+03 2.0124e+03 1.9858e+03 1.9512e+03 1.9088e+03 1.8587e+03 1.8012e+03 1.7363e+03 1.6645e+03 1.5860e+03 1.5011e+03 1.4101e+03 1.3135e+03 1.2115e+03 1.1047e+03 993.4926 878.2414 759.4537 637.6080 513.1949 386.7153 258.6786 129.6002 0]} {[ 0]} {[ -1.9076e+03 -1.9053e+03 -1.8984e+03 -1.8869e+03 -1.8708e+03 -1.8499e+03 -1.8242e+03 -1.7937e+03 -1.7582e+03 -1.7176e+03 -1.6719e+03 -1.6208e+03 -1.5643e+03 -1.5022e+03 -1.4344e+03 -1.3608e+03 -1.2814e+03 -1.1961e+03 -1.1049e+03 -1.0077e+03 -904.7362 -796.0808 -681.9451 -562.6027 -438.4023 -309.7694 -177.2069 -41.2935 97.3198 237.9154 379.7164 521.8953 663.5842 803.8854 941.8833 1.0767e+03 1.2073e+03 1.3329e+03 1.4525e+03 1.5654e+03 1.6708e+03 1.7678e+03 1.8559e+03 1.9344e+03 2.0027e+03 2.0603e+03 2.1069e+03 2.1422e+03 2.1658e+03 2.1777e+03 4.2777e+03 4.2658e+03 4.2422e+03 4.2069e+03 4.1603e+03 4.1027e+03 4.0344e+03 3.9559e+03 3.8678e+03 3.7708e+03 3.6654e+03 3.5525e+03 3.4329e+03 3.3073e+03 3.1767e+03 3.0419e+03 2.9039e+03 2.7636e+03 2.6219e+03 2.4797e+03 2.3379e+03 2.1973e+03 2.0587e+03 1.9228e+03 1.7902e+03 1.6616e+03 1.5374e+03 1.4181e+03 1.3039e+03 1.1953e+03 1.0923e+03 995.1415 903.8912 818.5687 739.1579 665.6068 597.8354 535.7432 479.2154 428.1298 382.3612 341.7866 306.2886 275.7584 250.0982 229.2230 213.0617 201.5584 194.6727 192.3801]} {[0 -194.4003 -388.0178 -580.0730 -769.7923 -956.4120 -1.1392e+03 -1.3174e+03 -1.4902e+03 -1.6571e+03 -1.8173e+03 -1.9702e+03 -2.1152e+03 -2.2516e+03 -2.3790e+03 -2.4968e+03 -2.6045e+03 -2.7017e+03 -2.7881e+03 -2.8633e+03 -2.9269e+03 -2.9787e+03 -3.0185e+03 -3.0462e+03 -3.0616e+03 -3.0647e+03 -3.0555e+03 -3.0339e+03 -3.0001e+03 -2.9543e+03 -2.8965e+03 -2.8271e+03 -2.7463e+03 -2.6544e+03 -2.5519e+03 -2.4391e+03 -2.3164e+03 -2.1845e+03 -2.0437e+03 -1.8947e+03 -1.7381e+03 -1.5745e+03 -1.4045e+03 -1.2289e+03 -1.0483e+03 -863.5369 -675.2726 -484.2892 -291.3558 -97.2491 97.2491 291.3558 484.2892 675.2726 863.5369 1.0483e+03 1.2289e+03 1.4045e+03 1.5745e+03 1.7381e+03 1.8947e+03 2.0437e+03 2.1845e+03 2.3164e+03 2.4391e+03 2.5519e+03 2.6544e+03 2.7463e+03 2.8271e+03 2.8965e+03 2.9543e+03 3.0001e+03 3.0339e+03 3.0555e+03 3.0647e+03 3.0616e+03 3.0462e+03 3.0185e+03 2.9787e+03 2.9269e+03 2.8633e+03 2.7881e+03 2.7017e+03 2.6045e+03 2.4968e+03 2.3790e+03 2.2516e+03 2.1152e+03 1.9702e+03 1.8173e+03 1.6571e+03 1.4902e+03 1.3174e+03 1.1392e+03 956.4120 769.7923 580.0730 388.0178 194.4003 0]} {[ 0 4.8642 9.7181 14.5513 19.3526 24.1105 28.8122 33.4441 37.9912 42.4373 46.7646 50.9542 54.9859 58.8382 62.4890 65.9153 69.0940 72.0022 74.6176 76.9190 78.8869 80.5039 81.7553 82.6293 83.1177 83.2156 82.9221 82.2401 81.1761 79.7402 77.9458 75.8088 73.3478 70.5833 67.5370 64.2316 60.6902 56.9358 52.9911 48.8778 44.6169 40.2279 35.7293 31.1378 26.4692 21.7378 16.9566 12.1380 7.2931 2.4327 -2.4327 -7.2931 -12.1380 -16.9566 -21.7378 -26.4692 -31.1378 -35.7293 -40.2279 -44.6169 -48.8778 -52.9911 -56.9358 -60.6902 -64.2316 -67.5370 -70.5833 -73.3478 -75.8088 -77.9458 -79.7402 -81.1761 -82.2401 -82.9221 -83.2156 -83.1177 -82.6293 -81.7553 -80.5039 -78.8869 -76.9190 -74.6176 -72.0022 -69.0940 -65.9153 -62.4890 -58.8382 -54.9859 -50.9542 -46.7646 -42.4373 -37.9912 -33.4441 -28.8122 -24.1105 -19.3526 -14.5513 -9.7181 -4.8642 0]} {[ -1.1060e+03 -1.1029e+03 -1.0936e+03 -1.0782e+03 -1.0569e+03 -1.0297e+03 -997.0351 -959.0751 -916.1740 -868.7062 -817.0874 -761.7713 -703.2451 -642.0247 -578.6482 -513.6697 -447.6517 -381.1573 -314.7422 -248.9456 -184.2823 -121.2341 -60.2424 -1.7015 54.0474 106.7201 156.0924 202.0015 244.3456 283.0816 318.2223 349.8312 378.0176 402.9295 424.7472 443.6763 459.9404 473.7744 485.4187 495.1127 503.0900 509.5742 514.7747 518.8838 522.0740 524.4964 526.2786 527.5238 528.3103 528.6904 2.6287e+03 2.6283e+03 2.6275e+03 2.6263e+03 2.6245e+03 2.6221e+03 2.6189e+03 2.6148e+03 2.6096e+03 2.6031e+03 2.5951e+03 2.5854e+03 2.5738e+03 2.5599e+03 2.5437e+03 2.5247e+03 2.5029e+03 2.4780e+03 2.4498e+03 2.4182e+03 2.3831e+03 2.3443e+03 2.3020e+03 2.2561e+03 2.2067e+03 2.1540e+03 2.0983e+03 2.0398e+03 1.9788e+03 1.9157e+03 1.8511e+03 1.7853e+03 1.7188e+03 1.6523e+03 1.5863e+03 1.5214e+03 1.4580e+03 1.3968e+03 1.3382e+03 1.2829e+03 1.2313e+03 1.1838e+03 1.1409e+03 1.1030e+03 1.0703e+03 1.0431e+03 1.0218e+03 1.0064e+03 997.1231 994.0203]} {[ 0]}
cellfun(@size, B, 'uniform', 0)
ans = 8×1 cell array
{[1 100]} {[1 100]} {[ 1 1]} {[1 100]} {[1 100]} {[1 100]} {[1 100]} {[ 1 1]}
B = vertcat(B{:})
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
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

Voss
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)]

Categorie

Scopri di più su Particle & Nuclear Physics in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by