MATLAB: Resonance frequency in enclosures

resonance frecuency

Hi, I want to know how to make a code to know the resonance frecuency with different modes. The formula is the following but in nx, ny, nz I want to change the modes until (4,4,4), I tried to use a "for" and "break" but I failed completely.
I wanted the results to be shown in a table, where I only have to change the lenght of the enclosure (lx, ly, lz).
If someone could help me I would be completely grateful.

Best Answer

Hi,
you can use this function:
function Frequencia_Table = Frequencia(v,lx,ly,lz)
% Building the array of values
nx = [zeros(5,1); repelem([1:4]',6,1)];
ny = [0; repmat(repelem([1 2 0]',2,1),4,1); 1; 1; 2; 2];
nz = [repmat([1;0],14,1); 1];
Freq = [nx, ny, nz, nan(size(nx,1),1)];
% Function handle
f = @(lx,ly,lz) v/2.*sqrt((nx./lx).^2 + (ny./ly).^2 + (nz./lz).^2);
% Calculate Frequencies (lx = 2, ly = 3, lz = 4) --> Enter the lengths here
Freq(:,4) = f(lx,ly,lz);
% Create a table of the results
Frequencia_Table = table(Freq(:,1),Freq(:,2),Freq(:,3),Freq(:,4),'VariableNames',{'Nx','Ny','Nz','Frequencia'});
end
Save it as Frequencia.m inside your Matlab project folder. Then call the function like this:
% Call the function with v=0.2, lx=2, ly=3, lz=4 and save the result in the variable res
res = Frequencia(0.2,2,3,4)
which gives the following result:
res =
29×4 table
Nx Ny Nz Frequencia
__ __ __ __________
0 0 1 0.025
0 1 0 0.033333
0 1 1 0.041667
0 2 0 0.066667
0 2 1 0.0712
1 0 0 0.05
1 0 1 0.055902
1 1 0 0.060093
1 1 1 0.065085
1 2 0 0.083333
1 2 1 0.087003
2 0 0 0.1
2 0 1 0.10308
2 1 0 0.10541
2 1 1 0.10833
2 2 0 0.12019
2 2 1 0.12276
3 0 0 0.15
3 0 1 0.15207
3 1 0 0.15366
3 1 1 0.15568
3 2 0 0.16415
3 2 1 0.16604
4 0 0 0.2
4 0 1 0.20156
4 1 0 0.20276
4 1 1 0.20429
4 2 0 0.21082
4 2 1 0.2123
Best regards
Stephan