kindly help in the conversion of fortran code to matlab

1 view (last 30 days)
  5 Comments
Walter Roberson
Walter Roberson on 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.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 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);

More Answers (0)

Categories

Find more on Fortran with MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!