Multiple if condition inside multiple for loops

1 回表示 (過去 30 日間)
chhatra pal
chhatra pal 2019 年 12 月 1 日
回答済み: chhatra pal 2019 年 12 月 2 日
hi I am having some problems. I need to apply 3 conditions simultaneously. but I don't understand that it is correct or not. I am attaching the data files and matlab code which I wrote. Can anybody help please .Please check if statement. Actually I want to find indices 'k' and 'm' with the condition 'k<m' and then use these indices in computation of our main variable u_c.
%%%% Construction of U
u_c(1)=u(1); u_c(N+1)=u(N+1);
for i=2:N
for m=2:N
for k=2:N
if (((z(k-1)+z(k))/2)<((x(i-1)+x(i))/2)<((z(k+1)+z(k))/2))&&...
(((z(m-1)+z(m))/2)<((x(i+1)+x(i))/2)<((z(m+1)+z(m))/2))&&(k<m)
s_c=0;
for j=k+1:m-1
s_c=s_c+(hnold(j)*u(j));
end
s_c;
u_c(i)=(1/hn(i))*((((z(k+1)+z(k))/2-(x(i-1)+x(i))/2)*u(k))+...
(((-z(m-1)+z(k))/2+(x(i+1)+x(i))/2)*u(m))+s_c);
elseif (((z(m-1)+z(m))/2)<((x(i-1)+x(i))/2)<((z(m+1)+z(m))/2))&&...
(((z(m-1)+z(m))/2)<((x(i+1)+x(i))/2)<((z(m+1)+z(m))/2))
u_c(i)=u(m);
end
break
end
end
break
end
  1 件のコメント
Vladimir Sovkov
Vladimir Sovkov 2019 年 12 月 1 日
At the first glance, the "if" statements look correct (if only all the parenthesis are correctly paired). However, thanks to the "break" statements, your program will always deal with k=2 and n=2 alone, nothing else.

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

回答 (1 件)

chhatra pal
chhatra pal 2019 年 12 月 2 日
Thanks Prof. Vladimir Sovkov

カテゴリ

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

製品


リリース

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by