summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcomputeTrussCost.m15
-rwxr-xr-xprintForce.m18
-rwxr-xr-xprintHeader.m7
-rwxr-xr-xsolveTruss.m4
-rwxr-xr-xtruss_data_1.m24
-rwxr-xr-xtruss_solver.m27
-rwxr-xr-xweakestMember.m3
7 files changed, 98 insertions, 0 deletions
diff --git a/computeTrussCost.m b/computeTrussCost.m
new file mode 100755
index 0000000..df7daad
--- /dev/null
+++ b/computeTrussCost.m
@@ -0,0 +1,15 @@
+function [ cost ] = computeTrussCost( C, X, Y )
+ cost = 0;
+ [ j, m ] = size(C);
+ cost = cost + 10*j;
+ for i = 1:m
+ memb = C(:,i);
+ points = [X(memb == 1); Y(memb == 1)];
+ d = dist(points(:,1), points(:,2));
+ cost = cost + d;
+ end
+end
+
+function [ d ] = dist(p1, p2)
+ d = sqrt((p1(1)-p2(1))^2+(p1(2)-p2(2))^2);
+end \ No newline at end of file
diff --git a/printForce.m b/printForce.m
new file mode 100755
index 0000000..c22b2eb
--- /dev/null
+++ b/printForce.m
@@ -0,0 +1,18 @@
+function [ ] = printForce( forces, idx )
+%UNTITLED Summary of this function goes here
+% Detailed explanation goes here
+
+
+ f = abs(forces(idx));
+ s = sign(forces(idx));
+ fprintf('m%d: %.3f ', idx, f);
+ if s < 0
+ fprintf('(C)\n');
+ elseif s > 0
+ fprintf('(T)\n');
+ else
+ fprintf('\n');
+ end
+
+end
+
diff --git a/printHeader.m b/printHeader.m
new file mode 100755
index 0000000..6209edb
--- /dev/null
+++ b/printHeader.m
@@ -0,0 +1,7 @@
+function [] = printHeader()
+ fprintf('\% EK301');
+ fprintf('Michael Abed');
+ fprintf('Joseph Stone');
+ fprintf('Ben Havey');
+
+end \ No newline at end of file
diff --git a/solveTruss.m b/solveTruss.m
new file mode 100755
index 0000000..d8ffed9
--- /dev/null
+++ b/solveTruss.m
@@ -0,0 +1,4 @@
+function [ T ] = solveTruss( C, Sx, Sy, X, Y, L )
+ A = computeA(C, X, Y, Sx, Sy);
+ T = A\(-L);
+end \ No newline at end of file
diff --git a/truss_data_1.m b/truss_data_1.m
new file mode 100755
index 0000000..b3aca7f
--- /dev/null
+++ b/truss_data_1.m
@@ -0,0 +1,24 @@
+% EK301
+% Michael Abed
+% Ben Havey
+% Joseph Stone
+
+C = [
+ 1 1 0 0 0 0 0 0 0 0 0 0 0
+ 1 0 1 1 0 0 0 0 0 0 0 0 0
+ 0 0 0 1 1 1 0 0 0 0 0 0 0
+ 0 1 1 0 1 0 1 1 0 0 0 0 0
+ 0 0 0 0 0 1 1 0 1 1 0 0 0
+ 0 0 0 0 0 0 0 1 1 0 1 1 0
+ 0 0 0 0 0 0 0 0 0 1 1 0 1
+ 0 0 0 0 0 0 0 0 0 0 0 1 1
+];
+
+Sy = zeros(8,3); Sy(1,2)=1; Sy(8,3)=1;
+Sx = zeros(8,3); Sx(1,1)=1;
+
+X = [0 0 4 4 8 8 12 12];
+Y = [0 4 8 4 8 4 4 0];
+
+L = zeros(16,1); L(8+4)=-25;
+
diff --git a/truss_solver.m b/truss_solver.m
new file mode 100755
index 0000000..4a7a1aa
--- /dev/null
+++ b/truss_solver.m
@@ -0,0 +1,27 @@
+
+filename = input('Input truss data-file name: ', 's');
+
+run(filename);
+
+forces = solveTruss(C, Sx, Sy, X, Y, L);
+forces(abs(forces) < 0.00001) = 0;
+[j, m] = size(C);
+
+Ln = L(L~=0);
+for i = 1:length(Ln)
+
+ fprintf('Load: %.3f N\n', abs(Ln(i)));
+end
+fprintf('Member forces in Newtons:\n');
+for i = 1:m
+ printForce(forces, i);
+end
+fprintf('Reaction forces in Newtons\n');
+for i = 1:length(forces)-m
+ fprintf('r%d: %.3f\n', i, forces(m+i));
+end
+
+cost = computeTrussCost(C, X, Y);
+fprintf('Cost of truss: $%d\n', round(cost));
+
+fprintf('Theoretical max load/cost ratio in N/$: %.4f\n', abs(sum(L))/cost); \ No newline at end of file
diff --git a/weakestMember.m b/weakestMember.m
new file mode 100755
index 0000000..60485c9
--- /dev/null
+++ b/weakestMember.m
@@ -0,0 +1,3 @@
+function [ idx ] = weakestMember(C, X, Y, T)
+
+end \ No newline at end of file