|
mikrom (Programmer) |
30 Jan 10 13:21 |
I don't understand the purpose of the program, but IMHO your original code with goto and repeat-until loop CODEBhigh:= 1.5E+11; Blow := 1.5E+2; 100: B := (Bhigh + Blow)/2.0; w[1] := Ts; {Surface Temperature} w[2] := (Ts-T0)/(d1*d2) + L; {Surface Temperature Slope} y := 0.0; repeat If w[1] > 1.0 then begin Blow := B; goto 100; end; If w[2] < 0.0 then begin Bhigh := B; goto 100; end; Runge( Equations0, 2, 0.01, y, w ); {writeln(B:25:20,y:10:5);} until Bhigh-Blow < 0.00000005; could be approximately transformated into this code with only one while-loop (which could you then recode in Matlab) CODEBhigh:= 1.5E+11; Blow := 1.5E+2; {* before the loop:} {* reset values *} B := (Bhigh + Blow)/2.0; w[1] := Ts; {Surface Temperature} w[2] := (Ts-T0)/(d1*d2) + L; {Surface Temperature Slope} y := 0.0; {****************} while Bhigh-Blow >= 0.00000005 begin if (w[1] > 1.0) or (w[2] < 0.0) then begin If w[1] > 1.0 then Blow := B; {adjust new interval to <B, Bhigh>} If w[2] < 0.0 then Bhigh := B; {adjust new to <Blow, B>} {* reset values *} B := (Bhigh + Blow)/2.0; w[1] := Ts; {Surface Temperature} w[2] := (Ts-T0)/(d1*d2) + L; {Surface Temperature Slope} y := 0.0; {****************} end; Runge( Equations0, 2, 0.01, y, w ); end {while} But note, that the repeat-until loop checks the condition at end, but the while-loop checks the condition at the beginning of the loop. So the repeat-loop in your original code will surely be executed minimal one time, but the while-loop in the transformed code will be executed minimal one time only if the condition Bhigh-Blow >= 0.00000005 is fullfilled before the first iteration - in your case it's true. |
|