フィルターのクリア

For loop with three variables

10 ビュー (過去 30 日間)
Jacqueline Rigatto
Jacqueline Rigatto 2020 年 10 月 31 日
コメント済み: Jacqueline Rigatto 2020 年 11 月 1 日
u= [1.192 1.194 1.120]; % u_* [ms-1]
z=[0.0021 0.0029 0.0033]; % z_0 [m]
T=2:1:16;
f=1./T;
sigma= 2*pi*f; %[s-1]
g=9.8;
K=sigma.^2./g; % [m-1]
k=0.4;
i_teta=1:36;
teta_i=10.*i_teta;
for i=1:length(sigma)
for ii=1:length(K)
for j=1:length(teta_i)
mi(i,j)=(((g*z(1,1).*(K(ii).^2))./sigma.^2).*exp((k*sigma)./(K(ii).*u(1,1)).*cos(teta_i)))
end
end
end
The loop I want to make is from the equation below, where: u and z are fixed; sigma and k they are in two lines one below the other, both with 15 elements; and theta_i in column with 36 elements.
I am unable to loop for two rows and a column varying. How can I do (my code is above)?
I thank you for your help

採用された回答

Alan Stevens
Alan Stevens 2020 年 10 月 31 日
編集済み: Alan Stevens 2020 年 10 月 31 日
1.You could have m as a function of, i, j and ii. Your loop then might look like
for i=1:length(sigma)
s = sigma(i);
for ii=1:length(k)
K = k(ii);
for j=1:length(teta_i)
theta = teta_i(j);
mi(i,j,ii)=(g*z(1,1).*K.^2./s.^2).*exp(K*s./(K.*u(1,1)).*cos(theta));
end
end
end
However, this doesn't look right compared with your mathematical equation because you have confused Kappa and k:
I suspect they are not the same.
  3 件のコメント
Alan Stevens
Alan Stevens 2020 年 10 月 31 日
Since sigma and K go hand in hand the following should produce mi in the form you want
u= [1.192 1.194 1.120]; % u_* [ms-1]
z=[0.0021 0.0029 0.0033]; % z_0 [m]
T=2:1:16;
f=1./T;
sigma= 2*pi*f; %[s-1]
g=9.8;
K=sigma.^2./g; % [m-1]
k=0.4;
i_teta=1:36;
teta_i=10.*i_teta;
mi = zeros(numel(teta_i),numel(sigma));
for i=1:length(sigma)
for j=1:length(teta_i)
mi(j,i)=(((g*z(1,1).*(K(i).^2))./sigma(i).^2).*exp((k*sigma(i))./(K(i).*u(1,1)).*cos(teta_i(j))));
end
end
Jacqueline Rigatto
Jacqueline Rigatto 2020 年 11 月 1 日
Thank you very much Alan Stevens, it helped a lot

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by