kindly help in the conversion of fortran code to matlab

1 Ansicht (letzte 30 Tage)
  5 Kommentare
Walter Roberson
Walter Roberson am 10 Apr. 2020
snul = 0.0;
snur = 0.0;
for j = 0:m
rnul = (th(0,j) - th(1,j)) * n;
rnur = (th(n-1,j) - th(n,j)) * n;
snul = snul + rnul;
snur = snur + rnur;
fprintf('%g %g %g\n' j/m, rnul, rnur);
end
avnl = snul / m;
avnr = snur / m;
fprintf('%g %g %g\n', ra, avnl, avnr);
I do not see any 100 x 100 matrices, not unless you are saying that th is a matrix. In fortran it is possible but not all that common to declare arrays to start from index 0, or any other index. I would want to see the statements that defined th, such as
REAL*8 th(100,100)
but it could not be exactly like that if th is a matrix being indexed at 0.
Oluwaseyi Aliu
Oluwaseyi Aliu am 10 Apr. 2020
sir, here is the initialisation;

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 10 Apr. 2020
n = 100; m = 100;
c8 = length(0:8);
f = zeros(c8, n+1, m+1);
feq = zeros(c8, n+1, m+1);
rho = zeros(c8, n+1, m+1);
w = zeros(1, c8);
cx = zeros(1, c8);
cy = zeros(1, c8);
u = zeros(n+1, m+1);
v = zeros(n+1, m+1);
g = zeros(c8, n+1, m+1);
geq = zeros(c8, n+1, m+1);
th = zeros(n+1, m+1);
i = 0;
%then some code to read the data.
%then
snul = 0.0;
snur = 0.0;
for j = 0:m
rnul = (th(1+0,1+j) - th(1+1,1+j)) * n;
rnur = (th(1+n-1,1+j) - th(1+n,1+j)) * n;
snul = snul + rnul;
snur = snur + rnur;
fprintf('%g %g %g\n' j/m, rnul, rnur);
end
avnl = snul / m;
avnr = snur / m;
fprintf('%g %g %g\n', ra, avnl, avnr);

Weitere Antworten (0)

Kategorien

Mehr zu Fortran with MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by