我已經編寫了MATLAB代碼,用於保守污染物的一維對流擴散,如下所示。MATLAB中'fprintf'命令的語法
% Analysis of 1D conservative contaminant migration through porous media.
% For t=25 days.
% Parameters:
dt = 1;
dx = 10;
% Coeffecients
m = (dt/dx^2)- (dt/dx);
n = -2*dt/(dx^2);
p = dt/(dx^2)+ dt/dx;
%Initialization
for i = 1:11
c(i)= 0.0;
h(i)= 0.0;
end
%Initial condition
c(6)= 500.0;
%Boundary condition
for i=1:11
c(1)=0.0;
c(11)= 0.0;
h(1)= 0.0;
h(11)= 0.0;
end
for k=1:25
for i=2:10
h(i)= c(i+1)*m + c(i)*n +c(i-1)*p;
end
for i=1:11
c(i)=h(i);
end
end
% Writing the results to file newfile.txt
fid= fopen('newfile.txt', 'wt');
fprintf(fid,%3.3f %3.3f %3.3f %3.3f %3.3f %3.3f %3.3f %3.3f %3.3f %3.3f
%3.3f %3.3f %3.3f %3.3f %3.3f %3.3f %3.3f %3.3f %3.3f\n,h);
fclose (fid);
contour(c);
但我卡在fprintf命令語法。在執行它時,它顯示一些括號丟失。