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

1 次查看(过去 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

请先登录,再进行评论。

采纳的回答

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