kindly help in the conversion of fortran code to matlab

1 vue (au cours des 30 derniers jours)
Oluwaseyi Aliu
Oluwaseyi Aliu le 10 Avr 2020
Commenté : Oluwaseyi Aliu le 10 Avr 2020
  5 commentaires
Walter Roberson
Walter Roberson le 10 Avr 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 le 10 Avr 2020
sir, here is the initialisation;

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 10 Avr 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);

Plus de réponses (0)

Catégories

En savoir plus sur Fortran with MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by