Question

In: Physics

creat a Matlab simulation the solves the 2D heat equation.

creat a Matlab simulation the solves the 2D heat equation.

Solutions

Expert Solution

The solution has been give below :-

%--- Heat Equation in two dimensions-------------------------------------

%--- Solves Ut=alpha*(Uxx+Uyy)-------------------------------------------

clc;

close all;

clear all;

%--dimensions...........................................................

N = 51;

DX=0.1; % step size

DY=0.1;

Nx=5;

Ny=5;

X=0:DX:Nx;

Y=0:DY:Ny;

alpha=7; % random thermal diffusivity

%--boundary conditions----------------------------------------------------

U(1:N,1:N) = 0 ;

U(1,1:N) = 100;

U(N,1:N) = 0;

U(1:N,1) = 0;

U(1:N,N) = 0;

%--initial condition------------------------------------------------------

U(23:29,23:29)=1000; % a heated patch at the center

Umax=max(max(U));

%-------------------------------------------------------------------------

DT = DX^2/(2*alpha); % time step

M=2000; % maximum number of allowed iteration

%---finite difference scheme----------------------------------------------

fram=0;

Ncount=0;

loop=1;

while loop==1;

ERR=0;

U_old = U;

for i = 2:N-1

for j = 2:N-1

Residue=(DT*((U_old(i+1,j)-2*U_old(i,j)+U_old(i-1,j))/DX^2 ...

+ (U_old(i,j+1)-2*U_old(i,j)+U_old(i,j-1))/DY^2) ...

+ U_old(i,j))-U(i,j);

ERR=ERR+abs(Residue);

U(i,j)=U(i,j)+Residue;

end

end

if(ERR>=0.01*Umax) % allowed error limit is 1% of maximum temperature

Ncount=Ncount+1;

if (mod(Ncount,50)==0) % displays movie frame every 50 time steps

fram=fram+1;

surf(U);

axis([1 N 1 N ])

h=gca;

get(h,'FontSize')

set(h,'FontSize',12)

colorbar('location','eastoutside','fontsize',12);

xlabel('X','fontSize',12);

ylabel('Y','fontSize',12);

title('Heat Diffusion','fontsize',12);

fh = figure(1);

set(fh, 'color', 'white');

F=getframe;

end

%--if solution do not converge in 2000 time steps------------------------

if(Ncount>M)

loop=0;

disp(['solution do not reach steady state in ',num2str(M),...

'time steps'])

end

%--if solution converges within 2000 time steps..........................

else

loop=0;

disp(['solution reaches steady state in ',num2str(Ncount) ,'time steps'])

end

end

%------------------------------------------------------------------------

%--display a movie of heat diffusion------------------------------------

movie(F,fram,1)

%------END---------------------------------------------------------------


Related Solutions

i need matlab code of heat equation in 1D with convection ?
i need matlab code of heat equation in 1D with convection ?
Write a function to solve the two-dimensional in Matlab, unsteady heat conduction equation with no internal...
Write a function to solve the two-dimensional in Matlab, unsteady heat conduction equation with no internal heat generation on a square domain. The length of each side of the square is 1 m. The function will have the following 4 inputs: npts                     number of grid points in each coordinate direction nt                         number of time steps to take dt                         size of time step (s) alpha                   thermal diffusivity (m2/s) Use the following initial and boundary conditions: Initialize the body to T =...
Matlab Implement Fading Channel Simulation: Jakes Model with using Matlab
Matlab Implement Fading Channel Simulation: Jakes Model with using Matlab
I want the code for the 2D Ising model using Matlab
I want the code for the 2D Ising model using Matlab
Fix the bugs in this matlab program so that it solves. clear clf clc time =...
Fix the bugs in this matlab program so that it solves. clear clf clc time = linspace(0, 5, 100); m = 1; k = 100; c = 1; delta = 0.2; [period, response] = Exmp(m, k, c, delta, time); plot(time, response) grid %Exmp(m, k, c, delta, time) % %________________________________________ function [T, x] = Exmp(m, k, c, delta, t) omega = sqrt(k/m); cC = 2*m*omega; if c>= cC disp('Not an underdamped system') T = 0; x = 0; return; end %...
Use MATLAB to create a script which solves for problem 5.9 in the book (5.11 in...
Use MATLAB to create a script which solves for problem 5.9 in the book (5.11 in the 4th edition). Given are the equations for the moment, as a function of x, starting from the leftmost side of the beam with x=0 and ending at the other end of the beam with x=12. This piecewise function together makes up the moment equation for the beam given. 0 ≤ ? ≤ 3 ?(?) = 265? − 5.56?3 , 3 < ? ≤...
Can you provide a sample programming for 2D plane frame in MATLAB ?
Can you provide a sample programming for 2D plane frame in MATLAB ?
Write a full program that solves the following equation and displays the value for x and...
Write a full program that solves the following equation and displays the value for x and y: 3.4x+50.2y=44.5 2.1x+.55y=5.9
Create a hot and cold game in Matlab to find a point in an (X,Y) 2D...
Create a hot and cold game in Matlab to find a point in an (X,Y) 2D coordinate plane. The user answers two inputs: x=Input('x') y=Input('y'). THE INPUTS WILL ONLY BE INTEGERS FROM 0 TO 100. This means no negative numbers. You write the program so the computer plays the game. The computer must play the game (comparing distances only) and give the same point as the user inputs. To keep it simple the code will check distances until distance =...
write a program in matlab to produce a discrete event simulation of a switching element with...
write a program in matlab to produce a discrete event simulation of a switching element with 10 inputs and 3 outputs. Time is slotted on all inputs and outputs. Each input packet follows a Bernoulli process. In a given slot, the independent probability that a packet arrives in a slot is p and the probability that a slot is empty is (1– p). One packet fills one slot. For a switching element if 3 or less packets arrives to some...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT