Getachew

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

ADAMA SCIENCE AND TECHNOLOGY UNIVERSITY

SCHOOL OF APPLIED NATURAL SCIENCE

Department of Applied Mathematics Msc.Program

Assignment of Numerical Method Matlab Pratice

Name ID Number
Getachew Beyecha PGR/18421/11

Instructor name:- Dr.Tekle


Laplace Equation (DIRICHLET PROBLEM)

The Dirichlet problem in Figure below describes the steady-state temper-


ature distribution inside a rectangular plate of length 2 and width 1. Three
of the sides are kept at zero temperature, while the lower edge has a tem-
x
perature proile of sin(π ). Using a mesh size of h =0.5 construct a grid and
2
ind the approximate values of u at the interior mesh points.solve by using
matlab code.

solution:

The user-deined function DirichletPDE uses the difference-equation ap-


proach outlined above to numerically solve Poisson‘s equation or Laplace‘s
equation in a rectangular region with the values of the unknown solution
available on the boundary. The function returns the approximate solution
at the interior mesh points, as well as the values at the boundary points
in a pattern that resembles the gridded region. It also returns the three-
dimensional plot of the results.

Figure 2 discretization
function U =DirichletPDE(x,y,f,uleft,uright,ubottom,utop)
%
% DirichletPDE numerically solves an elliptic PDE with Dirichlet boundary
% conditions over a rectangular region.
%
% U =DirichletPDE(x,y,f,uleft,uright,ubottom,utop), where
%
% x is the 1-by-m vector of mesh points in the x direction,
% y is the 1-by-n vector of mesh points in the y direction,
% f is an anonymous function representing f(x,y),
% ubottom(x),utop(x),uright(y),uleft(y) are anonymous functions
% describing the boundary conditions,
%
% U is the solution at the interior mesh points.

1
%
y = y 0 ; m = size(x, 2); n = size(y, 1); N = (m − 2) ∗ (n − 2);
A = diag(−4 ∗ ones(N, 1));
A = A + diag(diag(A, n − 2) + 1, n − 2);
A = A + diag(diag(A, 2 − n) + 1, 2 − n);
v = ones(N − 1, 1); % Create vector of ones
v(n − 2 : n − 2 : end) = 0; % Insert zeros
A = A + diag(v, 1); % Add upper diagonal
A = A + diag(v, −1); % Add lower diagonal
[X, Y ] = meshgrid(x(2 : end − 1), y(end − 1 : −1 : 2)); % Create mesh
h = x(2) − x(1);
% Define boundary conditions
f ori = 2 : m − 1,
utop bound(i − 1) = utop(x(i));
ubottom bound(i − 1) = ubottom(x(i));
end
for i =1:n,
uleft bound(i) =uleft(y(n+1-i));
uright bound(i) =uright(y(n+1-i));
end
b =0; % Initialize vector b
for i =1:N,
b(i) = h2 ∗ f (X(i), Y (i));
end
b(1 : n − 2 : N ) = b(1 : n − 2 : N ) − utop bound;
b(n − 2 : n − 2 : N ) = b(n − 2 : n − 2 : N ) − ubottom bound;
b(1 : n − 2) = b(1 : n − 2) − ulef t bound(2 : n − 1);
b(N − (n − 3) : N ) = b(N − n + 3 : N ) − uright bound(2 : n − 1);
u = A \ b0 ; % Solve the system.
U =reshape(u, n-2, m-2);
U =[utop bound; U; ubottom bound];
U =[uleft bound’ U uright bound];
[X, Y ] = meshgrid(x, y(end : −1 : 1));
surf (X, Y, U ); % 3D plot of the numerical results.
xlabel(‘x0 ); ylabel(‘y 0 );

To confirm the numerical results in MATLAB, we execute the user-deined


function
DirichletPDE (solution laplace equation given above).

 x = 0 : 0.5 : 2; y = 0 : 0.5 : 1;

2
x
 f = @(x, y)(0); ubottom = @(x)(sin(π ∗ )); utop = @(x)(0);
2
 ulef t = @(y)(0); uright = @(y)(0);
 U = DirichletP DE(x, y, f, ulef t, uright, ubottom, utop)

U=

0 0 0 0 0
0 0.2735 0.3867 0.2735 0
0 0.7071 1.0000 0.7071 0

Figure 3 Steady-state temperature distribution, using h =0.1

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy