03 March 2013 8 6K Report

I am newer of Matlab and currently working on matlab codes of heat equation. However, problem occured as below:

??? Error using ==> plot

Vectors must be the same lengths.

Could any one do me a favour?

The following is the code

%%% Initialize variables

dz =.001; %each depth step is 0.001 meter

Nz = 5; % Choose the number of depth steps (should go to at least 0.005 m)

Nt = 160; % Choose the number of time steps

dt = (8*60*60)/Nt; %Length of each time step in seconds (~ 6.3*10^3 seconds, or ~105 minutes)

K = 1.32*10^-7; % "canonical" K is 10e-7 m^2/s

T = 20*ones(Nz+1,Nt+1); %Create temperature matrix with Nz+1 rows, and Nt+1 columns

% Initial guess is that T is 20 everywhere.

time = [8:18/Nt:18];

T(1,:) = 20; %Set surface temperature

maxiter = 500

for iter = 1:maxiter

Tlast = T; %Save the last guess

T(:,1) = Tlast(:,end); %Initialize the temp at t=0 to the last temp

for i=2:Nt+1,

depth_2D = (T(1:end-2,i-1)-2*T(2:end-1,i-1)+T(3:end,i-1))/dz^2;

time_1D = K*depth_2D;

T(2:end-1,i) = time_1D*dt + T(2:end-1,i-1);

T(end,i) = T(end-1,i); % Enforce bottom BC

end

err(iter) = max(abs(T(:)-Tlast(:))); %Find difference between last two solutions

if err(iter)

Similar questions and discussions