Time for action - solving a two-dimensional Laplace equation
1. We start by specifying the temperature at the edges of the plate, the number of grid points, and the spatial coordinate (recall that the package only supports square domains such that y = x):
octave:16> T_0 = 300; N_grids = 50; L = 0.1; x = linspace(0, L, N_grids);
2. The source term is zero:
octave:17> B = zeros(N_grids, N_grids);
3. The boundary conditions can be specified as:
octave:18> B(:,1) = sin(pi*x/L) + T0; B(1,:) = T0; (N_grids,:)=T0; B(:,N_grids)=T0;
4. To convert
B
into the appropriate vector format, we use thevecmat_convert
function(Code Listing 6.3):
octave:19> b = vecmat_convert(B);
5. The coefficient matrix is generated via the command:
Octave:20> A = cmat_2d(N_grids);
6. The solution is therefore:
octave:21> t = A\b;
7. Now
t
is a vector and contains the numerical solution to the problem. This is not really what we want to end up with since the problem is two-dimensional. We callvecmat_convert...