Project

two dimensional unsteady heat conduction

clear all 
close all
clc


% input 
nx = 100;
ny = 100;
dx = 1/nx;
dy = 1/ny;
dt = 0.01;

T = ones(nx,ny);
To = T;
% Tp = ones(nx,1);
Tpn(1:ny,1)=400;
Tpn(1:ny,nx)=800;
Tpn(1,1:nx)=900;
Tpn(ny,1:nx)=600;
alpha = 1.64e-4;

s =0;
m = 1;
while s==0;
    t=0;
    k= 1;
    C1 = alpha*dt/dx^2;
    C2 = alpha*dt/dy^2;
    A = zeros(ny,nx);
    while t==0
        for i = 2:nx-1
            for j = 2:ny-1
               Tpn(i,j) = T(i,j)+C1*(T(i+1,j)-2*T(i,j)+T(i-1,j))+C2*(T(i,j+1)-2*T(i,j)+T(i,j-1));
            end
        end
        error1 = abs((norm(Tpn)-norm(T))/norm(Tpn));
        if error1<1e-4
            t=1;
        end
        k=k+1;
        T = Tpn;
        ITR = [m,k]
    end
    error2 = abs((norm(Tpn)-norm(To))/norm(Tpn));
    if error2<1e-4
        s=1;
    end
    m = m+1;
    To =Tpn;
    dt = dt+0.0001;
    contourf(1:ny,1:nx,Tpn);
    pause(0.5);
   
end

                        
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.