the value i am calling for from a matrix isnt changing although index is changing

조회 수: 2 (최근 30일)
so i am trying to call different values of T and p everytime I get one value of c that satisfies my requirements. As you can see although i,j changes to 1,4 here ( i tried debugging step by step to identify exactly why my conc matrix returns all the same values) the values of q and r dont change. i used q and r just as a reference to check whether my values of T and p were actually changing. So, how is it j=4 but when i call r=p(j) r returns 10 and not 40. I did the same code using for loop and i got my answers exactly but dont understand this. A clarification would be extremely helpful to remove my confusions regarding while loops.
  댓글 수: 4
Tanveer Islam
Tanveer Islam 2023년 8월 5일
clc
close
clear
f=@(T,C,p) (T/273.15)*(3.805*(C^2)+42.527*C+0.434)-p
df=@(t,c) (t/273.15)*(3.805*2*c+42.527)
a=3;
e=1;
conc=zeros(5,5);
T=[30,40,50,60,70];
p=[10,20,30,40,50];
for i=1:5
for j=1:5
while e>0.001
q=T(i);
r=p(j);
x=a-(f(T(i),a,p(j))/df(T(i),a));
e=abs(a-x);
a=x;
end
conc(i,j)=x;
continue
end
continue
end
conc
Tanveer Islam
Tanveer Islam 2023년 8월 5일
Sorry I thought showing the workspace would be useful to pinpoint the problem I was facing

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

채택된 답변

Torsten
Torsten 2023년 8월 5일
이동: Torsten 2023년 8월 5일
You forgot to reset e to 1 after the while-loop.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by