これは、期待どおりに実行されていないコードのセクションです。エラーの場所を特定するために、古いスタイルの「一時停止」ステートメントを含める必要がありました。
iteration_index = 1
y_refined = y_current + (0.5d0*dx*(dydx_predictor + dydx_refined_corrector)) ! Solution corresponds to i = 2, i.e., the refined Heun's method.
relative_percent_error = 100.d0*(abs((y_refined - y_next)/y_refined)) ! Calculation of relative percentage error. This is NOT true error.
if (relative_percent_error > heun_percent_tolerance) then
iteration_index = iteration_index + 1
print*, 'first loop enter', x_next, relative_percent_error, iteration_index
pause
if (iteration_index < max_heun_number) then
y_next = y_refined
call dydx(x_next, y_next, dydx_refined_corrector)
y_refined = y_current + (0.5d0*dx*(dydx_predictor + dydx_refined_corrector))
relative_percent_error = 100.d0*(abs((y_refined - y_next)/y_refined))
print*, 'second loop enter', x_next, relative_percent_error, iteration_index
pause
end if
end if
出力は次のようになります。
first loop enter 1.0000000000000000 6.7763423346068707 2
PAUSE
To resume execution, type go. Other input will terminate the job.
go
RESUMED
second loop enter 1.0000000000000000 1.6658644147581094 2
PAUSE
To resume execution, type go. Other input will terminate the job.
go
RESUMED
first loop enter 2.0000000000000000 6.6615482639252761 2
PAUSE
To resume execution, type go. Other input will terminate the job.
の値heun_percent_tolerance
は 0.01 で、max_heun_number
15 です。最大制限の 15 に達するまで、実行が 2 番目の if ループに入り、さらに反復することを期待していますが、コードは次のx_next
値 2 にジャンプするようです。
私は2つの条件を として組み合わせようとしましたがIf (cond1 .and. cond2)
、それもうまくいきませんでした。