필터 지우기
필터 지우기

here, i couldn't get the A,B,C values while using if, elseif conditions. how to get values while using conditional statement?

조회 수: 1 (최근 30일)
dx=0.05; dy=0.25; dt=0.2;
for j=1:n
if i==2:m
C(i)=V(i,j)*dt/4*dy-dt/2*(dy)^2;
elseif i==1:m-1
A(i)=-V(i,j)*dt/4*dy-dt/2*(dy)^2;
elseif i==1:m
B(i)=1+U(i,j)*dt/2*dx+dt/(dy)^2;
end
end
  댓글 수: 5
Dyuman Joshi
Dyuman Joshi 2022년 12월 13일
You still haven't answered - What is the value of i? Is there a value to i?
What exactly are you trying to achieve from this code?
Torsten
Torsten 2022년 12월 13일
@Gayathri comment moved here:
yes, m = 20; but im not comparing values i want find temperature profile like tridaigonal system

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2022년 12월 13일
편집: Jan 2022년 12월 13일
This cannot work:
if i==2:m
2:m is a vector. You can compare i with the vector, but the == operator works elementwise. The if command requires a scalar condition, such that Matlab inserts an all() implicitly here. But all(i == 2:m) is only true, if i is set to 2:m.
The same concerns the elseif conditions.
The values of A(i), B(i) and C(i) are overwritten in each iteration of the outer loop.
The explanation "i want find temperature profile like tridaigonal system" is not enough to explain clearly, what your code should do. Seeing a failing code does not allow to guess its intention also.
What is the desired output for A, B, C? Vectors or matrices? Maybe you want:
C(2:m, 1:n) = V(2:m, 1:n)*dt/4*dy-dt/2*(dy)^2;
without a loop and if command.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by