summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcomputeA.m32
1 files changed, 32 insertions, 0 deletions
diff --git a/computeA.m b/computeA.m
new file mode 100755
index 0000000..aa1ca08
--- /dev/null
+++ b/computeA.m
@@ -0,0 +1,32 @@
+function [ A ] = computeA( C, X, Y, Sx, Sy )
+% computes the A matrix for solving a truss
+
+ [j, m] = size(C);
+ A = zeros(2*j, m+3);
+ for row = 1:j
+ for col = 1:m
+ if C(row,col)
+ p = findother(C(:,col), row);
+ p1 = [X(row), Y(row)];
+ p2 = [X(p), Y(p)];
+ d = distance(p1, p2);
+ A(row,col) = (X(p) - X(row))/d;
+ A(row+j,col) = (Y(p) - Y(row))/d;
+ end
+ end
+ end
+ A(m+1:m+3,1:j)=Sx;
+ A(m+1:m+3,j+1:2*j)=Sy;
+end
+
+function [ p ] = findother(col, row)
+ for i = 1:size(col)
+ if col(i) ~= row && col(i)
+ p = i;
+ end
+ end
+end
+
+function [ d ] = distance( p1, p2 )
+ d = sqrt((p1(1)-p2(1))^2 + (p1(2)-p2(2))^2);
+end \ No newline at end of file