how to run a recursive solution

2 次查看(过去 30 天)
load 'gastemperature.m'
Tgbv=gastemperature(i)
load 'gastemperaturetestcell.m'
Tgtc=gastemperaturetestcell(i)
Tgbv1=gastemperature(i+1)
Tgtc1=gastemperaturetestcell(i+1)
load 'watertemperature.m'
Tw=watertemperature(i)
h=input('enter h value')
P=1.5922
[Ta,P]=hworkf( Ta,P,h,Tgbv,Tgtc,Tw,Tgbv1,Tgtc1 )
while P<1.66 &Ta<330.15
return
end
Please help with the following issues:
  1. how do i write the code such that it runs recursively until the condition 'P<1.66 &Ta<330.15' is met?
  2. Tgbv,Tgtc,Tw,Tgbv1& Tgtc1 are each from an array of data. How do I write the code such that a new value is picked from these arrays upon every solution
  3. how do I write the code such that the Ta and P from each solution is taken into the next solution
  4. how do i save the outputs(Ta and P) from each iteration as arrays? thanks.

采纳的回答

David Sanchez
David Sanchez 2014-2-7
1.- % make sure you have defined a value for ( Ta,P,h,Tgbv,Tgtc,Tw,Tgbv1,Tgtc1 ). In your code above Ta is missing
load 'gastemperature.m'
Tgbv=gastemperature(i)
load 'gastemperaturetestcell.m'
Tgtc=gastemperaturetestcell(i)
Tgbv1=gastemperature(i+1)
Tgtc1=gastemperaturetestcell(i+1)
load 'watertemperature.m'
Tw=watertemperature(i)
h=input('enter h value')
P=1.5922
[Ta,P]=hworkf( Ta,P,h,Tgbv,Tgtc,Tw,Tgbv1,Tgtc1 )
solutions(1,:) = [Ta,P];
i = 2;
while (P<1.66 & Ta<330.15)
Tgbv=gastemperature(i);
Tgtc=gastemperaturetestcell(i);
Tgbv1=gastemperature(i+1);
Tgtc1=gastemperaturetestcell(i+1);
Tw=watertemperature(i);
[Ta,P]=hworkf( Ta,P,h,Tgbv,Tgtc,Tw,Tgbv1,Tgtc1 );
solutions(i,:) = [Ta,P];
i = i +1;
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by