Representing dinamyc Euller-Bernoulli beam matrix in matlab? -
how can represent in matlab left matrix dynamically, allowing me grow iterative given n.
given n
, following code constructs matrix show, provided pattern stays same.
n = 5; d(n) = -12; d(1) = 12; d(2:end-1) = 6; b1(n-1) = 6; b1(1:end-1) = -4; b2(n-2) = 4/3; b2(1:end-1) = 1; a1 = b1(end:-1:1); a1(1) = -a1(1); = diag(d) + diag(b1, -1) + diag(b2, -2) + diag(a1, 1) + diag(b2(end:-1:1), 2)
output n=5
:
a = 12.0000 -6.0000 1.3333 0 0 -4.0000 6.0000 -4.0000 1.0000 0 1.0000 -4.0000 6.0000 -4.0000 1.0000 0 1.0000 -4.0000 6.0000 -4.0000 0 0 1.3333 6.0000 -12.0000
output n=8
:
a = 12.0000 -6.0000 1.3333 0 0 0 0 0 -4.0000 6.0000 -4.0000 1.0000 0 0 0 0 1.0000 -4.0000 6.0000 -4.0000 1.0000 0 0 0 0 1.0000 -4.0000 6.0000 -4.0000 1.0000 0 0 0 0 1.0000 -4.0000 6.0000 -4.0000 1.0000 0 0 0 0 1.0000 -4.0000 6.0000 -4.0000 1.0000 0 0 0 0 1.0000 -4.0000 6.0000 -4.0000 0 0 0 0 0 1.3333 6.0000 -12.0000
to use sparse representation a
can use pass command spdiags
4 arguments:
- a matrix
b
columns diagonals ofa
. - a vector
d
suchd(j)
diagonal ina
elements filled elements inb(:,j)
(the j-th column ofb
). - the number of rows in
a
. - the number of columns in
a
.
i use names start a
(above) super-diagonals , names start b
(below) sub-diagonals (i don't use u
(upper) , l
(lower) because l looks lot 1 in editor). here relevant code.
n = 8; d(n, 1) = -12; d(1) = 12; d(2:n-1) = 6; bb1(n, 1) = 0; bb1(n-1, 1) = 6; bb1(1:n-2) = -4; bb2(n-1:n, 1) = 0; bb2(n-2, 1) = 4/3; bb2(1:n-3) = 1; aa1 = bb1(n:-1:1); aa1(2) = -aa1(2); aa2 = bb2(n:-1:1); // sparse = spdiags([bb2 bb1 d aa1 aa2], -2:2, n, n); // double-checking: converting full matrix should give constructed previous method. - full(as) // should 0 matrix
Comments
Post a Comment