n=5;
m=4
m =
4
xValues=linspace(0,1,n)
xValues =
0 0.2500 0.5000 0.7500 1.0000
yValues=linspace(0,1,m)
yValues =
0 0.3333 0.6667 1.0000
[xGrid yGrid]=meshgrid(xValues,yValues)
xGrid =
0 0.2500 0.5000 0.7500 1.0000
0 0.2500 0.5000 0.7500 1.0000
0 0.2500 0.5000 0.7500 1.0000
0 0.2500 0.5000 0.7500 1.0000
yGrid =
0 0 0 0 0
0.3333 0.3333 0.3333 0.3333 0.3333
0.6667 0.6667 0.6667 0.6667 0.6667
1.0000 1.0000 1.0000 1.0000 1.0000
plot(xGrid,yGrid)
plot(xGrid,yGrid,'ok')
help simplePoisson
simplePoisson not found.
Use the Help browser search field to search the documentation, or
type "help help" for help command options, such as help for methods.
help simplePoisson
simplePoisson not found.
Use the Help browser search field to search the documentation, or
type "help help" for help command options, such as help for methods.
help simplePoisson.m
Copyright (C) 2017 Leon van Dommelen. This software is
made available under the GNU Public License version 3.
Function that finds the solution to the two-dimensional
Poisson equation on a rectangular grid when the
interior "forcing" and solution on the boundaries is
given.
Input:
xGrid: an m x n array containing the values of the
first independent variable at the m x n grid
points. All xGrid(:,j) values in the same
column j must be the same. And the xGrid(:,j)
values must increase with increasing column
number j.
yGrid: an m x n array containing the values of the
second independent variable at the m x n grid
points. All yGrid(i,:) values in the same row
i must be the same. And the yGrid(i,:) values
must increase with increasing row number i.
data: an m x n array that contains data about the
desired solution. The value of data(i,j) at
any interior point of the grid should be the
"forcing" at that point (i.e. whatever it is at
the point that wants to make the solution
nontrivial). The value of data(i,j) at any
boundary point, (i=1, i=m, j=1, or j=n), should
be the desired value of the solution at that
point.
Output:
sol: an m x n array containing the values of the
approximate solution at the m x n points.
Hint: arrays xGrid and yGrid must be in the form that
you would get from
[xGrid yGrid] = meshgrid(xValues,yValues)
where xValues is a one-dimensional array of n
increasing x-values, and yValues is a one-dimensional
array of m increasing y-values.
Warning: You would not want to use this function for
very large values of m x n. Its simple algorithm
wastes lots of storage and computer time for big m x n.
But at the time of writing, you can probably make m x n
quite big, like say 100 x 100, without much trouble.
forcing=2;
heightBoundary=1;
test1
n =
5
m =
4
xValues =
0 0.2500 0.5000 0.7500 1.0000
yValues =
0 0.3333 0.6667 1.0000
xGrid =
0 0.2500 0.5000 0.7500 1.0000
0 0.2500 0.5000 0.7500 1.0000
0 0.2500 0.5000 0.7500 1.0000
0 0.2500 0.5000 0.7500 1.0000
yGrid =
0 0 0 0 0
0.3333 0.3333 0.3333 0.3333 0.3333
0.6667 0.6667 0.6667 0.6667 0.6667
1.0000 1.0000 1.0000 1.0000 1.0000
data =
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
test1
n =
5
m =
4
xValues =
0 0.2500 0.5000 0.7500 1.0000
yValues =
0 0.3333 0.6667 1.0000
xGrid =
0 0.2500 0.5000 0.7500 1.0000
0 0.2500 0.5000 0.7500 1.0000
0 0.2500 0.5000 0.7500 1.0000
0 0.2500 0.5000 0.7500 1.0000
yGrid =
0 0 0 0 0
0.3333 0.3333 0.3333 0.3333 0.3333
0.6667 0.6667 0.6667 0.6667 0.6667
1.0000 1.0000 1.0000 1.0000 1.0000
data =
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
data
data =
1 1 1 1 1
1 2 2 2 1
1 2 2 2 1
1 1 1 1 1
test1
n =
5
m =
4
xValues =
0 0.2500 0.5000 0.7500 1.0000
yValues =
0 0.3333 0.6667 1.0000
xGrid =
0 0.2500 0.5000 0.7500 1.0000
0 0.2500 0.5000 0.7500 1.0000
0 0.2500 0.5000 0.7500 1.0000
0 0.2500 0.5000 0.7500 1.0000
yGrid =
0 0 0 0 0
0.3333 0.3333 0.3333 0.3333 0.3333
0.6667 0.6667 0.6667 0.6667 0.6667
1.0000 1.0000 1.0000 1.0000 1.0000
m =
4
n =
5
N =
20
relErrorMatlab =
2.3583e-14
height
height =
1.0000 1.0000 1.0000 1.0000 1.0000
1.0000 0.9025 0.8751 0.9025 1.0000
1.0000 0.9025 0.8751 0.9025 1.0000
1.0000 1.0000 1.0000 1.0000 1.0000
stem3(xGrid,yGrid,height)
test1
n =
20
m =
20
xValues =
Columns 1 through 5
0 0.0526 0.1053 0.1579 0.2105
Columns 6 through 10
0.2632 0.3158 0.3684 0.4211 0.4737
Columns 11 through 15
0.5263 0.5789 0.6316 0.6842 0.7368
Columns 16 through 20
0.7895 0.8421 0.8947 0.9474 1.0000
yValues =
Columns 1 through 5
0 0.0526 0.1053 0.1579 0.2105
Columns 6 through 10
0.2632 0.3158 0.3684 0.4211 0.4737
Columns 11 through 15
0.5263 0.5789 0.6316 0.6842 0.7368
Columns 16 through 20
0.7895 0.8421 0.8947 0.9474 1.0000
xGrid =
Columns 1 through 5
0 0.0526 0.1053 0.1579 0.2105
0 0.0526 0.1053 0.1579 0.2105
0 0.0526 0.1053 0.1579 0.2105
0 0.0526 0.1053 0.1579 0.2105
0 0.0526 0.1053 0.1579 0.2105
0 0.0526 0.1053 0.1579 0.2105
0 0.0526 0.1053 0.1579 0.2105
0 0.0526 0.1053 0.1579 0.2105
0 0.0526 0.1053 0.1579 0.2105
0 0.0526 0.1053 0.1579 0.2105
0 0.0526 0.1053 0.1579 0.2105
0 0.0526 0.1053 0.1579 0.2105
0 0.0526 0.1053 0.1579 0.2105
0 0.0526 0.1053 0.1579 0.2105
0 0.0526 0.1053 0.1579 0.2105
0 0.0526 0.1053 0.1579 0.2105
0 0.0526 0.1053 0.1579 0.2105
0 0.0526 0.1053 0.1579 0.2105
0 0.0526 0.1053 0.1579 0.2105
0 0.0526 0.1053 0.1579 0.2105
Columns 6 through 10
0.2632 0.3158 0.3684 0.4211 0.4737
0.2632 0.3158 0.3684 0.4211 0.4737
0.2632 0.3158 0.3684 0.4211 0.4737
0.2632 0.3158 0.3684 0.4211 0.4737
0.2632 0.3158 0.3684 0.4211 0.4737
0.2632 0.3158 0.3684 0.4211 0.4737
0.2632 0.3158 0.3684 0.4211 0.4737
0.2632 0.3158 0.3684 0.4211 0.4737
0.2632 0.3158 0.3684 0.4211 0.4737
0.2632 0.3158 0.3684 0.4211 0.4737
0.2632 0.3158 0.3684 0.4211 0.4737
0.2632 0.3158 0.3684 0.4211 0.4737
0.2632 0.3158 0.3684 0.4211 0.4737
0.2632 0.3158 0.3684 0.4211 0.4737
0.2632 0.3158 0.3684 0.4211 0.4737
0.2632 0.3158 0.3684 0.4211 0.4737
0.2632 0.3158 0.3684 0.4211 0.4737
0.2632 0.3158 0.3684 0.4211 0.4737
0.2632 0.3158 0.3684 0.4211 0.4737
0.2632 0.3158 0.3684 0.4211 0.4737
Columns 11 through 15
0.5263 0.5789 0.6316 0.6842 0.7368
0.5263 0.5789 0.6316 0.6842 0.7368
0.5263 0.5789 0.6316 0.6842 0.7368
0.5263 0.5789 0.6316 0.6842 0.7368
0.5263 0.5789 0.6316 0.6842 0.7368
0.5263 0.5789 0.6316 0.6842 0.7368
0.5263 0.5789 0.6316 0.6842 0.7368
0.5263 0.5789 0.6316 0.6842 0.7368
0.5263 0.5789 0.6316 0.6842 0.7368
0.5263 0.5789 0.6316 0.6842 0.7368
0.5263 0.5789 0.6316 0.6842 0.7368
0.5263 0.5789 0.6316 0.6842 0.7368
0.5263 0.5789 0.6316 0.6842 0.7368
0.5263 0.5789 0.6316 0.6842 0.7368
0.5263 0.5789 0.6316 0.6842 0.7368
0.5263 0.5789 0.6316 0.6842 0.7368
0.5263 0.5789 0.6316 0.6842 0.7368
0.5263 0.5789 0.6316 0.6842 0.7368
0.5263 0.5789 0.6316 0.6842 0.7368
0.5263 0.5789 0.6316 0.6842 0.7368
Columns 16 through 20
0.7895 0.8421 0.8947 0.9474 1.0000
0.7895 0.8421 0.8947 0.9474 1.0000
0.7895 0.8421 0.8947 0.9474 1.0000
0.7895 0.8421 0.8947 0.9474 1.0000
0.7895 0.8421 0.8947 0.9474 1.0000
0.7895 0.8421 0.8947 0.9474 1.0000
0.7895 0.8421 0.8947 0.9474 1.0000
0.7895 0.8421 0.8947 0.9474 1.0000
0.7895 0.8421 0.8947 0.9474 1.0000
0.7895 0.8421 0.8947 0.9474 1.0000
0.7895 0.8421 0.8947 0.9474 1.0000
0.7895 0.8421 0.8947 0.9474 1.0000
0.7895 0.8421 0.8947 0.9474 1.0000
0.7895 0.8421 0.8947 0.9474 1.0000
0.7895 0.8421 0.8947 0.9474 1.0000
0.7895 0.8421 0.8947 0.9474 1.0000
0.7895 0.8421 0.8947 0.9474 1.0000
0.7895 0.8421 0.8947 0.9474 1.0000
0.7895 0.8421 0.8947 0.9474 1.0000
0.7895 0.8421 0.8947 0.9474 1.0000
yGrid =
Columns 1 through 5
0 0 0 0 0
0.0526 0.0526 0.0526 0.0526 0.0526
0.1053 0.1053 0.1053 0.1053 0.1053
0.1579 0.1579 0.1579 0.1579 0.1579
0.2105 0.2105 0.2105 0.2105 0.2105
0.2632 0.2632 0.2632 0.2632 0.2632
0.3158 0.3158 0.3158 0.3158 0.3158
0.3684 0.3684 0.3684 0.3684 0.3684
0.4211 0.4211 0.4211 0.4211 0.4211
0.4737 0.4737 0.4737 0.4737 0.4737
0.5263 0.5263 0.5263 0.5263 0.5263
0.5789 0.5789 0.5789 0.5789 0.5789
0.6316 0.6316 0.6316 0.6316 0.6316
0.6842 0.6842 0.6842 0.6842 0.6842
0.7368 0.7368 0.7368 0.7368 0.7368
0.7895 0.7895 0.7895 0.7895 0.7895
0.8421 0.8421 0.8421 0.8421 0.8421
0.8947 0.8947 0.8947 0.8947 0.8947
0.9474 0.9474 0.9474 0.9474 0.9474
1.0000 1.0000 1.0000 1.0000 1.0000
Columns 6 through 10
0 0 0 0 0
0.0526 0.0526 0.0526 0.0526 0.0526
0.1053 0.1053 0.1053 0.1053 0.1053
0.1579 0.1579 0.1579 0.1579 0.1579
0.2105 0.2105 0.2105 0.2105 0.2105
0.2632 0.2632 0.2632 0.2632 0.2632
0.3158 0.3158 0.3158 0.3158 0.3158
0.3684 0.3684 0.3684 0.3684 0.3684
0.4211 0.4211 0.4211 0.4211 0.4211
0.4737 0.4737 0.4737 0.4737 0.4737
0.5263 0.5263 0.5263 0.5263 0.5263
0.5789 0.5789 0.5789 0.5789 0.5789
0.6316 0.6316 0.6316 0.6316 0.6316
0.6842 0.6842 0.6842 0.6842 0.6842
0.7368 0.7368 0.7368 0.7368 0.7368
0.7895 0.7895 0.7895 0.7895 0.7895
0.8421 0.8421 0.8421 0.8421 0.8421
0.8947 0.8947 0.8947 0.8947 0.8947
0.9474 0.9474 0.9474 0.9474 0.9474
1.0000 1.0000 1.0000 1.0000 1.0000
Columns 11 through 15
0 0 0 0 0
0.0526 0.0526 0.0526 0.0526 0.0526
0.1053 0.1053 0.1053 0.1053 0.1053
0.1579 0.1579 0.1579 0.1579 0.1579
0.2105 0.2105 0.2105 0.2105 0.2105
0.2632 0.2632 0.2632 0.2632 0.2632
0.3158 0.3158 0.3158 0.3158 0.3158
0.3684 0.3684 0.3684 0.3684 0.3684
0.4211 0.4211 0.4211 0.4211 0.4211
0.4737 0.4737 0.4737 0.4737 0.4737
0.5263 0.5263 0.5263 0.5263 0.5263
0.5789 0.5789 0.5789 0.5789 0.5789
0.6316 0.6316 0.6316 0.6316 0.6316
0.6842 0.6842 0.6842 0.6842 0.6842
0.7368 0.7368 0.7368 0.7368 0.7368
0.7895 0.7895 0.7895 0.7895 0.7895
0.8421 0.8421 0.8421 0.8421 0.8421
0.8947 0.8947 0.8947 0.8947 0.8947
0.9474 0.9474 0.9474 0.9474 0.9474
1.0000 1.0000 1.0000 1.0000 1.0000
Columns 16 through 20
0 0 0 0 0
0.0526 0.0526 0.0526 0.0526 0.0526
0.1053 0.1053 0.1053 0.1053 0.1053
0.1579 0.1579 0.1579 0.1579 0.1579
0.2105 0.2105 0.2105 0.2105 0.2105
0.2632 0.2632 0.2632 0.2632 0.2632
0.3158 0.3158 0.3158 0.3158 0.3158
0.3684 0.3684 0.3684 0.3684 0.3684
0.4211 0.4211 0.4211 0.4211 0.4211
0.4737 0.4737 0.4737 0.4737 0.4737
0.5263 0.5263 0.5263 0.5263 0.5263
0.5789 0.5789 0.5789 0.5789 0.5789
0.6316 0.6316 0.6316 0.6316 0.6316
0.6842 0.6842 0.6842 0.6842 0.6842
0.7368 0.7368 0.7368 0.7368 0.7368
0.7895 0.7895 0.7895 0.7895 0.7895
0.8421 0.8421 0.8421 0.8421 0.8421
0.8947 0.8947 0.8947 0.8947 0.8947
0.9474 0.9474 0.9474 0.9474 0.9474
1.0000 1.0000 1.0000 1.0000 1.0000
m =
20
n =
20
N =
400
relErrorMatlab =
1.5594e-12
mesh(xGrid,yGrid,height)
axis([0 1 0 1 0 1],'square')
contour(xGrid,yGrid,height)
axis('square')
rValues=linspace(0,2*pi,40)
rValues =
Columns 1 through 5
0 0.1611 0.3222 0.4833 0.6444
Columns 6 through 10
0.8055 0.9666 1.1278 1.2889 1.4500
Columns 11 through 15
1.6111 1.7722 1.9333 2.0944 2.2555
Columns 16 through 20
2.4166 2.5777 2.7388 2.8999 3.0610
Columns 21 through 25
3.2221 3.3833 3.5444 3.7055 3.8666
Columns 26 through 30
4.0277 4.1888 4.3499 4.5110 4.6721
Columns 31 through 35
4.8332 4.9943 5.1554 5.3165 5.4776
Columns 36 through 40
5.6388 5.7999 5.9610 6.1221 6.2832
rValues=linspace(0,2*pi,40);
thetaValues=linspace(0,2*pi,40);
[r theta]=meshgrid(rValues,thetaValues);
f=sin(r)./r;
[x y] =pol2cart(theta,r);
mesh(x,y,f)
axis([-2*pi 2*pi -2*pi 2*pi -Inf Inf],'square')
exit