- #1
logix88
- 12
- 0
I have to write a FD expilicit method, for temp dist on 2D plane.
I am trying to mod the 1D solver to 2D solver, the code below is a 1D solver. Any possible suggestions how it can be done? I initially, derived u(i,j+1) for 2D
for in that derivation i,j corresponds to x,y... where as in 1D i,j is x,t
I don't know how I can factor time in, and if I can actually use the 1D code. If anyone could point me in the right direction, give me a sample code or something it would be great. thanks!
btw, the guy who teaches this SUCKS! all he gave was this stupid code, and literally nothing else.
I am trying to mod the 1D solver to 2D solver, the code below is a 1D solver. Any possible suggestions how it can be done? I initially, derived u(i,j+1) for 2D
for in that derivation i,j corresponds to x,y... where as in 1D i,j is x,t
I don't know how I can factor time in, and if I can actually use the 1D code. If anyone could point me in the right direction, give me a sample code or something it would be great. thanks!
btw, the guy who teaches this SUCKS! all he gave was this stupid code, and literally nothing else.
Code:
f: funtion handle
g1,g2, left right hand BC
L: length of rod
T= length of simulation
n=no. of subintervals of x
m=no. of subintervals of t
c: thermal diffusivity const.
function [y0,y,yL,g1k,u',g2k] = Heat(f,g1,g2,L, T, n, m, c)
h= L/n;
x=h:h:(n-1)*h;
k=T/m;
r=c*k/n;
rr=1-2*r;
t=k:k:m*k;
y0=feval(f,0);
y=feval(f,x);
yL=feval(f,L);
g1k=feval(g1,t);
g2k=feval(g2,t);
% for internal points, have
% u_new(j) = u_old(j) + r*(u_old(j+1)-2*u_old(j)+u_old(j-1))
% for the two end-points, have
% u_new(1) = u_old(1) + r*(u_old(2)-2*u_old(1)+u_old(N-1))
% u_new(N) = u_old(N) + r*(u_old(2)-2*u_old(N)+u_old(N-1))
% clearly the endpoints are redundant: u(1)= u(N) at all times. I just
% kept them around for plotting convenience.
u(1,1)= r*y0+rr*y(1)+r*y(2);
u(2:n-2,1)=r*y(1:n-3)'+rr*y(2:n-2)'+r*y(3:n-1);
u(n-1,1)= r*y(n-2)+rr*y(n-1)+r*yL;
for j=1:m
u(1,j) = r*g1k(j-1)+rr*u(1,j-1)+r*u(2,j-1);
u(2:n-2,j)=r*u(1:n-3,j-1)'+rr*u(2:n-2,j-1)'+r*u(3:n-1,j-1);
u(n-1,j)= r*u(n-2,j-1)+rr*u(n-1,j-1)+r*g2k(j-1);
end