what is the problem with the code?

clc;
close all;
clear all;
% The variabel
L0 = 0.5;
k = 10;
AO = 0.3;
Hyp = 0.8 ;
BD = Hyp * sind(20) + 0.3;
DP = BD/2;
OD = 0.8 * cosd(20);
DBdiff = (BD/2) - (AO/2);
Sl = sqrt((OD^2) + (DBdiff^2));
DeltX = Sl - L0;
F = k * DeltX;
alpha = atand(DBdiff/OD)
alpha = 10.3141
%OA Part
Sx = F * cosd(alpha)
Sx = 2.5983
Sy = F * sind(alpha)
Sy = 0.4729
%SUMFx=0 -> Ax + Ox + Sx = 0
%SUMfy=0 -> Oy - Ay + Sy = 0
%SUMM0=0 -> T + (0.15)(Sx)-(0.3)(Ax) = 0
%BD Part
Px = -F * acosd(alpha)
Px = -0.0000e+00 - 4.5763e+02i
Py = -F * asind(alpha)
Py = -2.3769e+02 + 4.5763e+02i
%SUMFx=0 -> Dx + Bx - Px = 0
%SUMFy=0 -> Dy - By - Py = 0
%SUMM0=0 -> (DP)(Px) + (Bx)(BD) = 0
%AB Part
F1 = 0.3 * 10 * 1/2
F1 = 1.5000
F2 = 0.3 * 5
F2 = 1.5000
F1x = F1 * cosd(70)
F1x = 0.5130
F2x = F2 * cosd(70)
F2x = 0.5130
F1y = F1 * sind(70)
F1y = 1.4095
F2y = F2 * sind(70)
F2y = 1.4095
%SUMFx=0 -> Ax + Bx + F1x + F2x = 0
%SUMFy=0 -> -Ay - By - F1y - F2y = 0
%SUMMa=0 -> -F1y(Hyp-(2/3)*0.3*cosd(20)) - F2y(Hyp-(1/2)*0.3*cosd(20)) -
%By(Hyp) + Bx(BD-AO) - F1x(0.6 * sind(20)) - F2x(0.65 * sind(20)) = 0
M = [1 0 0 0 1 0 0 0 0
0 -1 0 0 0 1 0 0 0
-(0.3) 0 0 0 0 0 0 0 1
0 0 1 0 0 0 1 0 0
0 0 0 -1 0 0 0 1 0
0 0 (BD) 0 0 0 0 0 0
1 0 1 0 0 0 0 0 0
0 -1 0 -1 0 0 0 0 0
0 0 (BD-AO) -(Hyp) 0 0 0 0 0]
M = 9×9
1.0000 0 0 0 1.0000 0 0 0 0 0 -1.0000 0 0 0 1.0000 0 0 0 -0.3000 0 0 0 0 0 0 0 1.0000 0 0 1.0000 0 0 0 1.0000 0 0 0 0 0 -1.0000 0 0 0 1.0000 0 0 0 0.5736 0 0 0 0 0 0 1.0000 0 1.0000 0 0 0 0 0 0 0 -1.0000 0 -1.0000 0 0 0 0 0 0 0 0.2736 -0.8000 0 0 0 0 0
N= [-Sx;
-Sy;
-(F1)*(Sx);
Px;
Py;
-(DP)*(Px);
-(F1x) -(F2x);
(F1y) + (F2y);
(F1y)*(Hyp-(2/3)*0.3*cosd(20))+(F2y)*(Hyp-(1/2)*0.3*cosd(20))+(F1x)*(0.6*sind(20)) + (F2x)*(0.65*sind(20));]
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
X = M\N

2 Comments

i get "Dimensions of arrays being concatenated are not consistent." on N = [-Sx
N= [-Sx;...
-Sy;...
-(F1)*(Sx);...
Px;...
Py;...
-(DP)*(Px);...
-(F1x)-(F2x);...
(F1y)+(F2y);...
(F1y)*(Hyp-(2/3)*0.3*cosd(20))+(F2y)*(Hyp-(1/2)*0.3*cosd(20))+(F1x)*(0.6*sind(20))+(F2x)*(0.65*sind(20))];

Sign in to comment.

 Accepted Answer

-(F1x) -(F2x);
That is not subtraction giving back a scalar. That is two independent elements. Just like in M you have
0 -1
and you expect it to be a vector of length two, when you have something of the form
A -B
inside [] or {} then you get a pair of elements.
-(F1x) - (F2x);
on the other hand would be subtraction.

More Answers (1)

Cris LaPierre
Cris LaPierre on 3 Mar 2022
Edited: Cris LaPierre on 3 Mar 2022
There is ambiguity in one of your rows and, since the code is building an array, MATLAB is not doing what you intended. Specifically, a '-' can indicate subtraction as well as a negative number. Since you are building an array, how you use your spaces matters.
The problem is in this line:
-(F1x) -(F2x);
Because of the spacing inside square brackets, this is being treated as two negative numbers rather than a subtraction. Either of the following fixes that.
-(F1x)-(F2x);
% or
-(F1x) - (F2x);

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!