You'll have to specify them in the first time step, then change them according to the evolution of your program. That means modifying them after each step is calculated. Let [itex]u^i[/itex] be the vector of [itex]B_j^i[/itex] entries (j=1,...n), then
Code:
r = 0:h:r*
u = ones(n+1,1) % Initial condition
% Begin time steps
for i=1:m
u(1,1) = u(1,1) - (a*k/h)*(u(2,1)-u(1,1)); % Left boundary condition
u(2:n,1) = Matrix*u(2:n,1); % Matrix form of the PDE
u(n+1,1) = u(n,1); % Right boundary condition
v(:,i) = u(:,1); % This will create a matrix with the value of u^i in each column
end
I wrote some code this afternoon.but i think there is some thing wrong
r is the longitudinal coordinates, t is the x-coordinate:
dr = 0.01; %each depth step
Nr = 100; % Choose the number of depth steps
Nt = 40; % Choose the number of time steps
dt = (10*365*24*60*60)/Nt; %Length of each time step in seconds
T = zeros(Nr+1,Nt+1); %Create temperature matrix with Nz+1 rows, and Nt+1 columns
time = [0:120/Nt:120]; %120 months in 10 years
T(:,1) = 1; %Set initial condition
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
T(1,i)=(1+dt/dr)*T(1,i-1)-(dt/dr)*T(2,i-1);
thank u so mush!but I think my difference method is implicit difference that is:
[tex]B_j^i = \frac{\sigma_j k}{h} B_{j-1}^{i+1} + \left(1-\frac{2 \sigma_j k}{h^2}-\frac{\mu_j k}{h}-r_j\right)B_j^{i+1} + \left(\frac{\sigma_j k}{h^2}+\frac{\mu_j k}{h}\right)B_{j+1}^{i+1},[/tex]
I did sort of the same thing for my undergraduate thesis, but my pde was nonlinear, so I had to use the Crank-Nicholson scheme (basically the same thing you did), that's why I was able to help :).