3D matrix manipulation problems
2 views (last 30 days)
Show older comments
I struggle with this generally and have come up against a barrier again.
I'm trying to create vibrational mode functions for a rectangular membrane. The equation is simple enough: -
W_n = sin(x*pi*i/L_x)*sin(y*pi*i/L_y)
Here's where I'm up to: -
L_x = 27.4e-3; %membrane width (m)
L_y = 27.4e-3; %membrane height (m)
N_x = 10; %no. of eigenfreqs considered in x dimension
N_y = 10; %no. of eigenfreqs considered in y dimension
N = N_x*N_y; %total no. of eigenfreqs considered
x = (linspace(0.5*L_x/N_x,L_x - 0.5*L_x/N_x,N_x))';
%membrane x-dimension mapping points
%each at the centre of an element
y = (linspace(0.5*L_y/N_y,L_y - 0.5*L_y/N_y,N_y));
%membrane y-dimension mapping points
%each at the centre of an element
x_ref = 1:length(x);
y_ref = 1:length(y);
W_n = zeros(N_x,N_y,N);
W_n(:,:,01) = (sin(x(x_ref,:,:)*1*pi/L_x)...
*sin(y(:,y_ref,:)*1*pi/L_y));
W_n(:,:,02) = (sin(x(x_ref,:,:)*1*pi/L_x)...
*sin(y(:,y_ref,:)*2*pi/L_y));
W_n(:,:,18) = (sin(x(x_ref,:,:)*2*pi/L_x)...
*sin(y(:,y_ref,:)*8*pi/L_y));
W_n(:,:,46) = (sin(x(x_ref,:,:)*5*pi/L_x)...
*sin(y(:,y_ref,:)*6*pi/L_y));
W_n(:,:,89) = (sin(x(x_ref,:,:)*9*pi/L_x)...
*sin(y(:,y_ref,:)*9*pi/L_y));
W_n(:,:,100) = (sin(x(x_ref,:,:)*10*pi/L_x)...
*sin(y(:,y_ref,:)*10*pi/L_y));
The numbers on the left hand side - 01, 02, 18, 46, 89, 100 - actually need to be 1,2,3,...,100, i.e.
n = 1:100; %mode number counting from 1 to 100
These refer to the mode numbers - although this is a bit odd - but still not too complicated. Basically if n = 01, then the mode is (1,1). If n = 59 the mode is (6,9), i.e. i = 6 & j = 9. I have solved this using the following: -
i = floor((n/10 - n/1000)) + 1;
%mode number from 1 to 10 in x dimension
j = n - 10*(floor((n/10 - n/1000)));
%mode number from 1 to 10 in y dimension
Now I just need to put n, i and j into my W_n equation, but I can't figure out how!
Any help would be greatly appreciated :)
0 Comments
Accepted Answer
Simon
on 19 Sep 2013
Hi!
I don't understand why the x and y spacing depends on the number of modes/frequencies.
Take a look at the following code:
L_x = 27.4e-3; %membrane width (m)
L_y = 27.4e-3; %membrane height (m)
N_x = 5; %no. of eigenfreqs considered in x dimension
N_y = 10; %no. of eigenfreqs considered in y dimension
N = N_x*N_y; %total no. of eigenfreqs considered
NumX = 50; % number of mapping points in x-direction
NumY = 50; % number of mapping points in y-direction
% create X and Y array in 2d
[X,Y] = meshgrid(...
(linspace(0.5*L_y/NumY, L_y - 0.5*L_y/NumY, NumY)), ...
(linspace(0.5*L_x/NumX, L_x - 0.5*L_x/NumX, NumX)));
% modify X and Y array for 3d
XFull = repmat(X, [1 1 N]);
YFull = repmat(Y, [1 1 N]);
% create mode array for X
Mx = ones(NumX, NumY, N_y);
MxFull = [];
for n = 1:N_x
MxFull = cat(3, MxFull, n*Mx);
end
% create mode array for Y
My = ones(NumX, NumY);
MyFull = [];
for n = 1:N_y
MyFull = cat(3, MyFull, n*My);
end
MyFull = repmat(MyFull, [1 1 N_x]);
% modes for each direction
Wx_n = arrayfun(@(x,mx) sin(x .* (mx *pi/L_x)), XFull, MxFull);
Wy_n = arrayfun(@(y,my) sin(y .* (my *pi/L_x)), YFull, MyFull);
% superposition of modes
W_n = Wx_n .* Wy_n;
% plot
figure(1); cla
surface(W_n(:,:,23));
7 Comments
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!