Function A= secDIM2% This program can realize the real-time dynamic simulation of convection-diffusion under two optional boundary conditions % using the power format % initial temperature field is 10, the speed is optional % time difference using the fully implicit format CLC DT =0.001; BC =input(' 1- type 1, 2- type 2: '); q=0; DDT =input(' number of iterations: '); L1 = 0.02; r=1000; K = 0.017; sp=0; L2 = 0.01; U =input(' horizontal velocity: '); if bc==2 v=0; Else v=input(' vertical velocity: '); end n=100; m=100; dx=L1/n; dy=L2/m; F1=r*u*dy; F2=r*v*dx; ap0=r*dx*dy/dt; D1=k*dy/dx; pe1=F1/D1; D2=k*dx/dy; pe2=F2/D2; tp0=10*ones(n*m,1); % Initial temperature TW =10; te=10; % Margin condition A=sparse(n*m); b=ap0*tp0; % 2 d effect coefficient use ae = D1 * Max power format (0, 1-0.1 * (abs (pe1 ^ 5))) + Max (F1, 0); Aw = D1 * Max (0, 1-0.1 * (abs (pe1 ^ 5))) + Max (0, F1); As = D2 * Max (0, 1-0.1 * (abs (pe2 ^ 5))) + Max (0, F2); The an = D2 * Max (0, 1-0.1 * (abs (pe2 ^ 5))) + Max (0, F2); ap=aw+ae+as+an+ap0-sp; spw=-1*2*k*dy/dx; spe=-1*2*k*dy/dx; If BC ==2 q=input(' heat flow is: '); spn=0; sps=0; tn=0; ts=0; te=0; spe=0; Else tn=input(' NTN: '); Ts =input(' input '); spn=-1*2*k*dx/dy; sps=-1*2*k*dx/dy; end sun=zeros(n,1); sus=zeros(n,1); sun(5:64)=2*k*tn*dx/dy+q*dx; sus(5:64)=2*k*ts*dx/dy+q*dx; suw=2*k*tw*dy/dx; sue=2*k*te*dy/dx; If (I <n&&i>1) A(I, I)=ae+an+ AW +ap0-sps; if(I <n&&i>1) A(I, I)=ae+an+ AW +ap0-sps; A(i,i+1)=-ae; A(i,i-1)=-aw; A(i,i+n)=-an; b(i)=b(i)+sus(i); % node within the inner assignment else if (I > n && rem (I, n) ~ = 1 && rem (I, n) ~ = 0 & & I < n * (m - 1) + 1) A (I, I) = ap; A(i,i+n)=-an; A(i,i-n)=-as; A(i,i+1)=-ae; A(i,i-1)=-aw; Else if n % north boundary point assignment (I m - > n * n + 1 & & I < n * m) A (I, I) = ae + as aw + + ap0 - SPN; A(i,i+1)=-ae; A(i,i-1)=-aw; A(i,i-n)=-as; b(i)=b(i)+sun(i-n*m+n); W % west boundary point assignment else if (I > n & & I < n * m - n + 1 && rem (I, n) = = 1) A (I, I) = + + as an ae + ap0 - SPW; A(i,i+n)=-an; A(i,i-n)=-as; A(i,i+1)=-ae; b(i)=b(i)+suw; % e east boundary point assignment else if (I > n & & I < n * m && rem (I, n) = A (I, I) = = 0) aw + + as an + ap0 - spe; A(i,i+n)=-an; A(i,i-n)=-as; A(i,i-1)=-aw; b(i)=b(i)+sue; Else end end end % A(1,1)=1; % A(n,n)=1; % A(n*m-n+1,n*m-n+1)=1; % A(n*m-n+1,n*m-n+1)=1; % A(n*m,n*m)=1; % endCopy the code

 ​

Complete code added QQ1575304183