Vous êtes sur la page 1sur 4

Nurlan Kazankapov ID: 201015984

Numerical Methods Assignment 3

Problem 1
clear all % Numerical Methods, SoE, Nazarbayev University % Laplace equation using Gauss-Seidel Method % This code is for 30 nodes % Initialize number of nodes (30) M=30; N=30; % Initialize function u=zeros(M,N); % Initialize boundary conditions u(M,:)=100; u(:,N)=100; % Calculate temperature distribution flag=1; while flag ==1 flag=0; uold=u; for i=2:M-1 for j=2:N-1 u(i,j)=(u(i-1,j)+ uold(i+1,j)+u(i,j-1)+uold(i,j+1))/4 % In order to adjust for Gauss-Seidel iteration change the uold to u. error=abs((u(i,j)-uold(i,j))/uold(i,j)); if error > 0.01 flag=1; end end end end %Plot temperature distribution [x,y]=meshgrid(0:1/(M-1):1,0:1/(N-1):1); surface(x,y,u) colorbar colorman blue title('Square Plate, Gauss-Seidel Method, 30 nodes') xlabel('x') ylabel('y')

Results

Figure 1: Temperature distribution along the plate, (Jacobi iteration)

Figure 2: Temperature distribution along the plate, (Gauss-Seidel iteration)

From the operation performed it can be learned, that with the Jacobi method, the values of obtained in the nth iteration remain unchanged until the entire (n + 1)th iteration has been calculated. With the Gauss-Seidel method, we use the new values as soon as they are known. For example, once we have computed from the first equation, its value is then used in the second equation to obtain the new and so on. Thus, Gauss-Seidel method help the calculations reach the steady-state solution faster than with the Jacobi iteration. Problem 2
clear close all % Initialize number of nodes and constants N=30; lambda=1; L=1; q=1; h=L/(N-1); dt=0.0005; %Initialize domain x=linspace(0,L,N); % Initialize and plot heat distribution at t=0 u=100*sin(pi*x); plot(x,u,'k') hold on % Calculate heat at specified times t=[0.01,0.05,0.2,0.5]; jmax=t/dt; k=1; u=100*sin(pi*x); % Initial temperature profile for j=1:jmax(length(t)) uold=u; for i=2:N-1 u(i)=uold(i)+lambda^2*dt/h^2*(uold(i-1)-2*uold(i)+uold(i+1))+q*dt; u(N)=(4*uold(N-1)-uold(N-2))/3; % Iteration scheme for insulated end end if j==jmax(k) plot(x,u) k=k+1; end end

Figure 3: Time-dependent Heat Equation vs Numerical

Vous aimerez peut-être aussi