Conversion of a Fortran Equation to Matlab

2 次查看(过去 30 天)
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)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Fortran with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by