Multiple if condition inside multiple for loops

1 Ansicht (letzte 30 Tage)
chhatra pal
chhatra pal am 1 Dez. 2019
Beantwortet: chhatra pal am 2 Dez. 2019
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 Kommentar
Vladimir Sovkov
Vladimir Sovkov am 1 Dez. 2019
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

chhatra pal
chhatra pal am 2 Dez. 2019
Thanks Prof. Vladimir Sovkov

Kategorien

Mehr zu Variables finden Sie in Help Center und File Exchange

Produkte


Version

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by