Could anyone give an idea to write code to solve below problem
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mohammad Sohel Rana
el 11 de Abr. de 2017
Respondida: Walter Roberson
el 11 de Abr. de 2017
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.
0 comentarios
Respuesta aceptada
James Tursa
el 11 de Abr. de 2017
Editada: James Tursa
el 11 de Abr. de 2017
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)
Más respuestas (1)
Walter Roberson
el 11 de Abr. de 2017
The solution is
TC(1) = 15 + sum(q(2:N)) / (1000*mc*cpc)
0 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!