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 the vecmat_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 ...

Get GNU Octave now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.