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 Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by