For loops for matrices

12 ビュー (過去 30 日間)
Atreyu91
Atreyu91 2015 年 8 月 22 日
回答済み: Star Strider 2015 年 8 月 22 日
I am trying to link two equations, where I use a for loop calculate the value of k (wavenumber) from the range of frequencies (eg. 1-5 Hz) then substitute the values of k into a 6x6 matrix. Can anyone help show me how to create a matrix for each value of k in Matlab?
1st Equation
for f = 1:5; % Range of Frequencies (Hz)
f;
w = 2.*pi.*f; % Angular Frequency (Hz)
p = 8050;% Density of Mild Steel(kg/m^3)
v = 0.30; % Poissons Ratio of Mild Steel
R = 0.02; % Radius of Pipe (m)
E = 210*10^9; % Youngs Modulus of Mild Steel (pa)
a = (w.^2).*p;
b = (p.*(1-(v.^2)).*(R.^2).*(w.^2)-E);
c = (p.*(R.^2).*(w.^2)-E).*E;
k(f) = sqrt((a.*b)/c); % k = Wave Number
end
An example solution when f=1:5
f=1, k=0.0012
f=2, k=0.0025
f=3, k=0.0037
f=4, k=0.0049
f=5, k=0.0062
2nd Equation (6x6 Matrix)
k = **value from equation 1**
L1=0.1;
L2=0.6;
L3=0.6;
D= [0,0,exp(-k*L1),exp(-k*L2),0,0; exp(-k*L1),1,exp(-k*L1),exp(-k*L2),0,0; -k*exp(-k*L1),k,k*exp(-k*L1),-k*exp(-k*L2),0,0;0,0,exp(-k*(L1+L2)),k,-exp(-k*(L1+L2)),-exp(-k*L3);0,0,-k*exp(-k*(L1+L2)),1,k*exp(-k*(L1+L2)),k*exp(-k*L3);0,0,exp(-k*(L1+L2)),1,0,0]
An example of how the matrix looks using the 2nd equation is in the picture below:

採用された回答

Star Strider
Star Strider 2015 年 8 月 22 日
It’s probably easiest to just set up a second loop (since ( don’t want to go through and subscript all the ‘k’-values in ‘D’:
for f = 1:5; % Range of Frequencies (Hz)
f;
w = 2.*pi.*f; % Angular Frequency (Hz)
p = 8050;% Density of Mild Steel(kg/m^3)
v = 0.30; % Poissons Ratio of Mild Steel
R = 0.02; % Radius of Pipe (m)
E = 210*10^9; % Youngs Modulus of Mild Steel (pa)
a = (w.^2).*p;
b = (p.*(1-(v.^2)).*(R.^2).*(w.^2)-E);
c = (p.*(R.^2).*(w.^2)-E).*E;
kv(f) = sqrt((a.*b)/c); % k = Wave Number
end
for f = 1:length(kv)
L1=0.1;
L2=0.6;
L3=0.6;
k = kv(f);
D(:,:,f) = [0,0,exp(-k*L1),exp(-k*L2),0,0; exp(-k*L1),1,exp(-k*L1),exp(-k*L2),0,0; -k*exp(-k*L1),k,k*exp(-k*L1),-k*exp(-k*L2),0,0;0,0,exp(-k*(L1+L2)),k,-exp(-k*(L1+L2)),-exp(-k*L3);0,0,-k*exp(-k*(L1+L2)),1,k*exp(-k*(L1+L2)),k*exp(-k*L3);0,0,exp(-k*(L1+L2)),1,0,0]
end
NOTE: I renamed ‘k’ in the first loop as ‘kv’, and used the renamed vector in the second loop.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePhysics についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by