Conversion of a Fortran Equation to Matlab

1 回表示 (過去 30 日間)
Eric Cheatwood
Eric Cheatwood 2020 年 7 月 18 日
コメント済み: Eric Cheatwood 2020 年 7 月 18 日
Hello,
I need some help converting a relatively simple equation from Fortran to Matlab. I'm fairly fluent in Matlab but I haven't really had a chance to mess with Fortran. The code is designed to convert heat flux into a temperature value. From what I can tell, the equation works iteratively in a loop going number by number. Am I right in saying 'DO 4' creates an array called TCALC that are just filled with the first number from the array TEXP. Then, 'DO 5' works backwards by -1 increments from 200 (TIMEF = 200) to 1 and each time the loop repeats, N and J decrease by 1 until they get to 1. Within this loop, all the numbers gointo the ELSE equation until it gets to the first number in the array and it goes to the THEN equation. It seems like there is a better way to write this with sum perhaps. For reference, in the original document this is equation 6 and the Fortran code is included at the bottom of the document. https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19940031900.pdf
DO 4 N = 1, TIMEF
TCALC(N) = TEXP(1)
DO5 J=N, 1,-1
IF (J.EQ.1) THEN
TCALC(N) = TCALC(N) - 2.*SQRT(ALPHA)/K/SQRT(PI)*QEXP(J) + *(SQRT(((N-.5)-(J-.5))*.02)-SQRT((N-.5)*.02))
ELSE
TCALC(N) = TCALC(N) -2.*SQRT(ALPHA)/K/SQRT(PI)*QEXP(J) + *(SQRT(((N-.5)-(J-.5))*.02)-SQRT(((N-.5)-(J- 1.5))*.02))
ENDIF

採用された回答

Alan Stevens
Alan Stevens 2020 年 7 月 18 日
This is the correponding MATLAB structure:
for N = 1:TIMEF
TCALC(N) = TEXP(1);
for J = N:-1:1
if J==1
TCALC(N) = TCALC(N) - ...;
else
TCALC(N) = TCALC(N) - ...;
end
end % of for J = N:-1:1 loop (FORTRAN line labelled 5)
fprintf(...)
end % of for N = 1:TIMEF loop (FORTRAN line labelled 4)
  1 件のコメント
Eric Cheatwood
Eric Cheatwood 2020 年 7 月 18 日
Thank you so much.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFortran with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by