Could anyone give an idea to write code to solve below problem

조회 수: 6 (최근 30일)
Tc(1)=?
for i=1:N
Tc(i+1)=(mc*cpc*Tc(i)*1000-q(i))/(1000*mc*cpc);
end
%%%%mc, cpc are constant, q(i) is variable.
I need to find out the temperature of Tc(1) to get the temperature Tc(N)=15C.

채택된 답변

James Tursa
James Tursa 2017년 4월 11일
편집: James Tursa 2017년 4월 11일
You could create a function file and put your loop code inside that file which takes a guess as an input (for Tc(1)) and returns the value Tc(N)-15 as an output, then use fzero on that function. Start it with a guess. E.g., the file myFunction.m would look something like
function result = myFunction(Tc1,mc,cpc,q,N)
Tc(1) = Tc1;
for i=1:N
Tc(i+1)=(mc*cpc*Tc(i)*1000-q(i))/(1000*mc*cpc);
end
result = Tc(N) - 15; % Did you really need N or N+1 here???
end
And the function you would pass to fzero could be
f = @(Tc1) myFunction(Tc1,mc,cpc,q,N)
  댓글 수: 1
Mohammad Sohel Rana
Mohammad Sohel Rana 2017년 4월 11일
I need at Tc(N+1)=15C. Thank you James Tursa. Should I need to define Tc1?

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 4월 11일
The solution is
TC(1) = 15 + sum(q(2:N)) / (1000*mc*cpc)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by