0% found this document useful (0 votes)
65 views1 page

Osr PDF

This document contains Matlab code to iteratively solve a partial differential equation on a grid using an explicit finite difference scheme. The code initializes parameters, sets boundary conditions, iterates the solution until convergence within a tolerance, and outputs the results.

Uploaded by

Mahmoud Gaballa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views1 page

Osr PDF

This document contains Matlab code to iteratively solve a partial differential equation on a grid using an explicit finite difference scheme. The code initializes parameters, sets boundary conditions, iterates the solution until convergence within a tolerance, and outputs the results.

Uploaded by

Mahmoud Gaballa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

4/30/23 7:58 PM G:\Matlab\bin\projets\Untitled.

m 1 of 1

clc
clear all
a=0.2;b=0.8;h=0.2;tol=0.5;
ud=1;ul=1;x=[a:h:b];y=[a:h:b];
uold=zeros(4,4); k=1;ug=zeros(4,4);LAM=1.2;
while (k>0)
for j=1:4
for i=1:4
if j==1
us=ud;
else us=ug(i,j-1);
end
if i==4
ue=exp(2*y(i));
else ue=ug(i+1,j);
end
if i==1
uw=ul;
else uw=ug(i-1,j);
end

if j==4
un=exp(x(i));
else un=ug(i,j+1);
end
unew(i,j)=(us+ue+un+uw)/4;
unew(i,j)=LAM*unew(i,j)+(1-LAM)*ug(i,j);
ug(i,j)=unew(i,j);
end
end
k=0;
for j=1:4
for i=1:4
error(i,j)=abs( (unew(i,j)-uold(i,j))/ unew(i,j));
if error(i,j)>tol
k=k+1
uold=unew;
end
end
end
end
table (unew, error)

You might also like