Hello friends, I am new for numerical methods and programming. i have been trying to devolop a program in 2D poisson heat equation in cylinder (r,angle) by finite difference method(adsbygoogle = window.adsbygoogle || []).push({});

∂^{2}u/∂r^{2}+ 1/r * ∂u/∂r + 1/r^{2}* ∂^{2}u/∂θ^{2}= Q(u,θ)

discritized equation :-

u_{i+1,j }− 2u_{ij }+ u_{i−1,j}/(∆r)^{2}+ 1/r_{i }* u_{i+1,j}− u_{i−1,j}/2∆r +1/r^{2}_{i}* u_{i,j+1}−2u_{ij }+u_{i,j−1}/(∆θ)^{2}= Q(u,θ)

i have been trying to develop this program, can anybody help me in making it to run faster for n = 400;

clear all

close all

clc

tic

n = 5; % mesh size

s = n-2;

r = linspace(1,5,n)-1;

angle =((1:1:n)-1)/(n)*2*pi;

m = (s*n); %number of nodes

dr = r(3)-r(2); % distance between radius

dangle = angle(3)- angle(2); % change of angle between radius

Q = 20*dr^2; % heat sourse

% right hand side Matrix

rhs = zeros(m+1,1);

rhs( : ) = Q;

bou = ones(m+1,1);

% boundary values

bou( : ) = 0;

tic

for i = n-1:n-2:m+1

rhs(i,1) = rhs(i,1) + bou(i);

end

toc

% evaluating the co effitiants of tridiagonal sparse matrix

tic

for i = 2:n-1

a(i) = 2*(1 + ((dr^2)/(r(i)*dangle)^2));

b(i) = 1+(1/(2*r(i)));

c(i) = 1-(1/(2*r(i)));

d(i) = dr^2/(r(i)^2*dangle^2);

end

toc

% building up the matrix for A.x = B

f = c(2);

I = speye(n);

a = (a(2:end))';

b = [0;b(2:n-2)'];

p = [c(3:end)';0];

% d = (d(2:end))';

T = spdiags([p -1*a b],[-1 0 1],n-2,n-2);

oops = full(T);

FirstM = kron(I,T);

% z = full(FirstM);

d = (d(2:end));

e = repmat(d,1,n-1);

tic

for i = 1: (m-s)

FirstM(i,(i+s)) = e(i);

FirstM((i+s),i) = e(i);

end

toc

tic

for i = 1: s

FirstM((m-s+i),i) = e(i);

FirstM(i,(m-s+i)) = e(i);

end

toc

% z = full(FirstM);

FirstM(1,m+1) = 0;

FirstM(m+1,1) = 0;

tic

for i = 1:n-2:m+1

FirstM(i,m+1) = f;

FirstM(m+1,i) = 1;

end

toc

FirstM(m+1,m+1) = -4;

z = full(FirstM);

% solving A*x = B for solution

Tsol = abs(mldivide(FirstM,rhs));

toc

T1soln = Tsol(1:m,1);

Tsoln = reshape(Tsol,n-1,n-1);

% Tsoln = Tsoln';

% Tsoln = reshape(T1soln,n,s);

% angle = angle(1,2:n);

% r = r(1,2:n);

[x,y] = meshgrid(r,angle);

[xs,ys] = pol2cart(x,y);

surf(xs,ys,Tsoln,'EdgeColor','none')

.

**Physics Forums - The Fusion of Science and Community**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# 2D cylindrical heat equation

Loading...

Similar Threads - cylindrical heat equation | Date |
---|---|

Heat Equation with cylindrical rod | Apr 29, 2013 |

Cylindrical Wall Heat Equation | Dec 4, 2011 |

Transient heat transfer 2-D cylindrical | May 16, 2011 |

Hom. heat equation in cylindrical coordinates using Fourier & Laplace transforms | Jul 16, 2010 |

Heat equation (cylindrical) | Mar 14, 2010 |

**Physics Forums - The Fusion of Science and Community**