Hello everyone;
I try to use this loop;
R = 8.914;
PCO = 0;
for i = [1:250]
T(i) = i+0.1;
deltaG = -287500 + 22.75*T;
while PCO<100;
PCO = PCO + 0.01;
deltaGnew = R * T .* log(PCO);
end
end
But in my workspace I saw that T has only 2 values ([1.1,2.1])
The problem is that : I have T and PCO values. T varies between 1 - 250 and PCO starts 0 to 100. I want to calculate deltaG values of each temperature and deltaGnew values of each temp and PCO. And after that if deltaG = deltaGnew, I want to stop my loops.
Thank you!
Kindest regards,
S.A

댓글 수: 2

madhan ravi
madhan ravi 2020년 6월 28일
a?
Semih Ates
Semih Ates 2020년 6월 28일
Sorry for that, I edit my code.

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

 채택된 답변

madhan ravi
madhan ravi 2020년 6월 28일

0 개 추천

R = 8.914; % I don't understand why you need a loop though?
PCO = linspace(0, 1e2);
T = linspace(1, 250);
deltaG = -287500 + 22.75*T;
deltaGnew = R * T .* log(PCO);

댓글 수: 3

Semih Ates
Semih Ates 2020년 6월 28일
OK thank you, but is there any chance to use for - while loop at same for this ? or any example for that?
R = 8.914;
PCO = linspace(0, 1e2);
T = linspace(1, 250);
[deltaG, deltaGnew] = deal(zeros(numel(T), 1));
for k = 1:numel(T)
deltaG(k) = -287500 + 22.75*T(k);
deltaGnew(k) = R * T(k) .* log(PCO(k));
end
Semih Ates
Semih Ates 2020년 6월 28일
it works thank you.

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

추가 답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 6월 28일

0 개 추천

R = 8.914;
T=linspace(1.1,0.1,250);
deltaG = -287500 + 22.75.*T;
a= %?? % Define it
PCO=linspace(a,0.01,100);
deltaGnew=R*T(1:length(PCO)).*log(PCO);

댓글 수: 3

Semih Ates
Semih Ates 2020년 6월 28일
Thank you, it solve my problem. But I want to use for & while loop :/
KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 6월 28일
편집: KALYAN ACHARJYA 2020년 6월 28일
R = 8.914;
T=linspace(1.1,0.1,250);
deltaG = -287500 + 22.75.*T;
PCO=linspace(0:0.01,100);
PCO=linspace(0,0.01,100);
for i=1:length(PCO)
deltaGnew(i)=R*T(i)*log(PCO(i));
end
Semih Ates
Semih Ates 2020년 6월 28일
thank you

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

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

질문:

2020년 6월 28일

댓글:

2020년 6월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by