Heat Equation using Neumann boundary condition

Joined
2/3/13
Messages
245
Points
138
Hi Guys,

I am trying to solve the heat equation using the Neumann boundry condition in Matlab. I dont know if my code is correct in term of solving the equation. If anyone can help me out I will really appreciate it. There are two methods that our teacher asks. I am including the first method. Attached you will find the copy of the assignment. Its question 2 that I have trouble with. Thanks a lot guys.

Heres my code so far

T=0.01;
N_time=1000;
N_space=1001;
delta_t=T/N_time; %step in time variable
delta_x=1/N_space; %step in space variable
%**********************************************************
rho=delta_t/delta_x^2;
phi=zeros(N_space,1);
phi
%**********************************************************
%initial condition
for i=0:N_space-1
xi=i*delta_x;
phi(i+1)=initial_condition(xi);
end;
phi
A=zeros(N_space-1,N_space-1);
A(1,1)=1-2*rho;
A(1,2)=rho;
for i=2:N_space-1
A(i,i-1)=rho;
A(i,i)=1-2*rho;
A(i,i+1)=rho;
end;
A(N_space,N_space)=1-2*rho;
A(N_space,N_space-1)=rho;
A

solution=zeros(N_space,1);
solution=A*phi;
solution
-Abhishek.
 

Attachments

Hi Guys,

I am trying to solve the heat equation using the Neumann boundry condition in Matlab. I dont know if my code is correct in term of solving the equation. If anyone can help me out I will really appreciate it. There are two methods that our teacher asks. I am including the first method. Attached you will find the copy of the assignment. Its question 2 that I have trouble with. Thanks a lot guys.

Heres my code so far

T=0.01;
N_time=1000;
N_space=1001;
delta_t=T/N_time; %step in time variable
delta_x=1/N_space; %step in space variable
%**********************************************************
rho=delta_t/delta_x^2;
phi=zeros(N_space,1);
phi
%**********************************************************
%initial condition
for i=0:N_space-1
xi=i*delta_x;
phi(i+1)=initial_condition(xi);
end;
phi
A=zeros(N_space-1,N_space-1);
A(1,1)=1-2*rho;
A(1,2)=rho;
for i=2:N_space-1
A(i,i-1)=rho;
A(i,i)=1-2*rho;
A(i,i+1)=rho;
end;
A(N_space,N_space)=1-2*rho;
A(N_space,N_space-1)=rho;
A

solution=zeros(N_space,1);
solution=A*phi;
solution
-Abhishek.

Instead of asking people to debug your code for you a better idea is to first mathematically formulate the PDE problem and its numerical approximation.
 
Back
Top