How to convert script from fortran90 to matlab language

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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by