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

2 visualizaciones (últimos 30 días)
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 comentarios
Tanveer Islam
Tanveer Islam el 5 de Ag. de 2023
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 el 5 de Ag. de 2023
Sorry I thought showing the workspace would be useful to pinpoint the problem I was facing

Iniciar sesión para comentar.

Respuesta aceptada

Torsten
Torsten el 5 de Ag. de 2023
Movida: Torsten el 5 de Ag. de 2023
You forgot to reset e to 1 after the while-loop.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by