How to convert script from fortran90 to matlab language

조회 수: 2 (최근 30일)
m m
m m 2019년 10월 26일
댓글: m m 2019년 10월 28일
Can anyone help me to covert this script
Thank you
DIMENSION KB(10) KA(10)
KL=0
KS=1
DO 210 K=1,N0
K1=K+1
IF(A(K)*A(K1).LT.0.)THEN
KS=-KS
IF(KS.EQ.-1)THEN
KL=KL+1
KA(KL)=K1
ENDIF
IF(KS.EQ.1)THEN
KB(KL)=K
ENDIF
ENDIF
210 CONTINUE
IF(KL.GT.0)THEN
DO 230 KQ=1,KL
KAL=KA(KL)
KBL=KB(KL)
K0=KAL-1
K1=KBL+1
XA=H*FLOAT(K0)
XB=H*FLOAT(K1)
FA=A(K0)
FB=A(K1)
DO 220 K=KAL,KBL
XK=H*FLOAT(K)
A(K)=FA+(FB-FA)*(XK-XA)/(XB-XA)
220 CONTINUE
230 CONTINUE
ENDIF
  댓글 수: 1
Fabio Freschi
Fabio Freschi 2019년 10월 27일
this is not a complete Fortran script (and it doesn't use F90 syntax): some variable are missing, such as N0,

댓글을 달려면 로그인하십시오.

채택된 답변

Fabio Freschi
Fabio Freschi 2019년 10월 27일
Again, it is difficult to check if not all code is available, however I try
kB = zeros(10,1);
kA = zeros(10,1);
kL = 0;
kS = 1;
for k = 1:N0
k1 = k+1;
if A(k)*A(k1) < 0
kS = -kS;
if kS == -1
kL = kL+1;
kA(kL) = k1;
end
if kS == 1
kB(kL) = k;
end
end
end
if kL > 0
for kQ = 1:kL
kAL = kA(kL);
kBL = kB(kL);
k0 = kAL-1;
K1 = kBL+1;
xA = H*double(k0);
xB = H*double(k1);
FA = A(k0);
FB = A(k1);
for k = kAL:kBL
xK = H*double(k);
A(k) = FA+(FB-FA)*(xK-xA)/(xB-xA);
end
end
end
It goes without saying that this is an attempt to translate the code line-by-line, but it could not be the best matlab code.
  댓글 수: 3
Fabio Freschi
Fabio Freschi 2019년 10월 28일
They are declaration of variables.
The second is simple, just allocate the memory for a double array
b = zeros(N,1);
The first is similar. The only problem is that the variable is declared assuming 0-indexing. Matlab does not allow 0-indexing so you can write
a = zeros(n+1,1);
and scale the 1-indexing in the code
m m
m m 2019년 10월 28일
Thank you Sir,

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by