Problem with creating matrix

I'm trying to create a 36x36 matrix where each column has two 18x1 vectors stacked. The vectors correspond to deflections in both the y and z direction and were calculated by setting the loads in the y direction (1st potition) as a 1x18 vector where the first value is 1 and others zero ([1 0 0 0 0 ..]), the loads in the z direction were set all to zero with the same vector length.
For the second column of the matrix, the deflection in the y and z direction must be calculated by setting the loads in the z direction(still 1st position) as [0 1 0 0 0 ..] with the same 1x18 length, and the loads in the y direction were all zero.
The deflections in y and z are inside a for loop with 18 positions.
For the third column of the matrix, I need the deflections in y and z but setting the loads in the y direction(now 2nd position) to [0 0 1 0 0 ...] and the loads in z as zero. The forth column would correspond to the loads in the z directions as [0 0 0 1 0 0 ..] and loads in y zero.
Is there a way I could create this matrix with a for loop that changes where the value of "1" in the vectors for the loads is located? I'm trying to solve a vibrations problem involving a flexibility matrix

5 Comments

Most difficult to try to parse verbal description -- give a small example of the desired pattern.
If you can compute the wanted vectors as implied, you can certainly put them together -- just have to have the rule by which to do so.
I need to create a matrix (on the right) where the colums are the u vector, but the p vector changes values. In the first position i=1, p2y=1 and other variables 0. Then, still in the first position, p2z=1 and other variables 0. I need to do this until N, which is i=18
That takes a lot of delving into to decipher still -- just gives us a small example of the form
%FIRST COLUM OF MATRIX, WHERE UX1 AND UY1 ARE COMBINED
pz = zeros(length(r_vec),1);
p1y = zeros(length(r_vec),1);
p1y(1) = 1;
for i = N:-1:2
Ty1(i-1) = Ty1(i) + 0.5*(p1y(i-1) + p1y(i)*(x(i) - x(i-1)));
Tz1(i-1) = Tz1(i) + 0.5*(pz(i-1) + pz(i)*(x(i) - x(i-1)));
My1(i-1) = My1(i) - Tz1(i)*(x(i) - x(i-1)) - (((1/6)*(pz(i-1))) + (((1/3)*(pz(i))))*((x(i) - x(i-1))^2));
Mz1(i-1) = Mz1(i) + Ty1(i)*(x(i) - x(i-1)) + (((1/6)*(p1y(i-1))) + (((1/3)*(p1y(i))))*((x(i) - x(i-1))^2));
end
for i = 1:N
M11(i) = (My1(i)*cosd(twist_vec(i) + pitch)) - (Mz1(i)*sind(twist_vec(i) + pitch));
M21(i) = (My1(i)*sind(twist_vec(i) + pitch)) + (Mz1(i)*cosd(twist_vec(i) + pitch));
k11(i) = M11(i)/EI1(i);
k21(i) = M21(i)/EI2(i);
kz1(i) = (-k11(i)*sind(twist_vec(i) + pitch)) + (k21(i)*cosd(twist_vec(i) + pitch));
ky1(i) = (k11(i)*cosd(twist_vec(i) + pitch)) + (k21(i)*sind(twist_vec(i) + pitch));
end
for i = 1:N-1
thetay1(i+1) = thetay1(i) + (0.5*(ky1(i+1) + ky1(i))*(x(i+1) - x(i)));
thetaz1(i+1) = thetaz1(i) + (0.5*(kz1(i+1) + kz1(i))*(x(i+1) - x(i)));
uy1(i+1) = uy1(i) + (thetaz1(i)*(x(i+1) - x(i))) + ((1/6*kz1(i+1)) + (1/3*kz1(i)))*(x(i+1) - x(i))^2;
uz1(i+1) = uz1(i) - (thetay1(i)*(x(i+1) - x(i))) - ((1/6*ky1(i+1)) + (1/3*ky1(i)))*(x(i+1) - x(i))^2;
end
%SECOND COLUMN OF MATRIX
p1z = zeros(length(r_vec),1);
p1z(2) = 1;
py = zeros(length(r_vec),1);
%SAME LOOPS TO GET TO UY AND UZ
I would like to do this without setting the values for the pz and py vectors every time
What's so hard to just show a small example???
Is the following the pattern you for a 4-element case instead of 18?
M=[1 0 0 0
0 0 1 0
0 1 0 0
0 0 0 1];
?
It's two identity matrices except with alternate 0 columns in the two halves?

Sign in to comment.

Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Asked:

on 27 Nov 2020

Commented:

dpb
on 27 Nov 2020

Community Treasure Hunt

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

Start Hunting!