필터 지우기
필터 지우기

Conversion of a Fortran Equation to Matlab

조회 수: 2 (최근 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)

추가 답변 (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