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 Center および File ExchangeMatrix Indexing についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by