• C++ Programming for Financial Engineering
    Highly recommended by thousands of MFE students. Covers essential C++ topics with applications to financial engineering. Learn more Join!
    Python for Finance with Intro to Data Science
    Gain practical understanding of Python to read, understand, and write professional Python code for your first day on the job. Learn more Join!
    An Intuition-Based Options Primer for FE
    Ideal for entry level positions interviews and graduate studies, specializing in options trading arbitrage and options valuation models. Learn more Join!

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

  • assignment2.pdf
    113.7 KB · Views: 27
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