kindly help in the conversion of fortran code to matlab

1 次查看(过去 30 天)
  5 个评论
Walter Roberson
Walter Roberson 2020-4-10
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.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2020-4-10
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);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Fortran with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by