Time for action - comparing with analytical solution
1. First we type in the physical constants given by the problem. Let us use Q = 10 kiloWatts per meter cubed (kW m-3), k = 319 Watts per Kelvin per meter (W K-1 m-1), L = 0.5 meter and T0 = 273 Kelvin:
octave:8> Q=10000; k = 319; L=0.5; T_0=273;
2. We then need to specify the number of grid points (including the boundary grid points):
octave:9>N_grids = 20;
octave:10> delta = L/(N_grid-1);
3. From this, we can set the source term and boundary values:
octave:11> b = -Q/k*delta^2*ones(N_grids,1); octave:12> b(1)=b(N_grids)=T_0;
4. Next, we need the coefficient matrix which we obtain from
cmat_1d:
octave:13> A=cmat_1d(ngrids);
5. We have now specified everything that we need in order to calculate the temperature profile: the vector
b
and the matrixA
. The temperature profile is then found by solving the linear equation system. In Octave, we use the left division operator:
octave;14> T=A\b;
That...