MATLAB Cable Tension and Cost Optimization Script
Classified in Mathematics
Written on in
English with a size of 1.99 KB
MATLAB Cable Tension and Cost Optimization
This script calculates cable tensions and optimizes costs for a structural system by iterating through coordinate positions.
Initialization
ACMatrix = zeros(51,51);
ABMatrix = zeros(51,51);
ADMatrix = zeros(51,51);
CostMatrix = zeros(51,51);
countery = 0;
MinCost = 1;
A = [6 2 1]';
B = [3.5 0 -0.5]';
D = [0 -1 5.5]';
F = -[160 20 -30]';
rab = B - A;
rad = D - A;
ead = rad/norm(rad);
eab = rab/norm(rab);Iterative Calculation
The following loop calculates tensions and costs across a range of Y and Z coordinates:
- C: Point position of the system.
- Tensions: Solved using the unit vector matrix.
- Cost: Calculated based on cable length and tension.
for y = 1:.1:6
countery = countery + 1;
counterz = 0;
for z = -1:.1:4
counterz = counterz + 1;
C = [0 y z]';
rac = C - A;
NormRac = sqrt(rac(1)^2+rac(2)^2+rac(3)^2);
eac = rac/NormRac;
UnitVectorMatrix = [eab eac ead];
Tensions = UnitVectorMatrix\F;
ACMatrix(countery,counterz) = Tensions(2);
ABMatrix(countery, counterz) = Tensions(1);
ADMatrix(countery, counterz) = Tensions(3);
CostMatrix(countery,counterz) = NormRac * Tensions(2);
end
endVisualization and Results
The script generates surface plots to visualize the effect of coordinate changes on cost and tension.
m = min(min(CostMatrix));
y = 1:.1:6;
z = -1:.1:4;
figure; surf(y,z,CostMatrix'); title('Effect on cost by changing y and z');
figure; surf(y,z,ACMatrix); title('Effect on Tension of AC');
figure; surf(y,z,ABMatrix); title('Effect on Tension of AB');
figure; surf(y,z,ADMatrix); title('Effect on Tension of AD');Final Output
The script concludes by printing the minimum cost and the optimal position for point C, followed by the components of vector F.