/* Update the temperature based on the four point stencil. */ for ( i = 1; i <= n; i++ ) { h_new[i] = h[i] + ( time_delta * k / x_delta / x_delta ) * ( h[i-1] - 2.0 * h[i] + h[i+1] ) + time_delta * rhs ( x[i], time ); } /* Correct settings of first H in first interval, last H in last interval. */ if ( 0 == id ) h_new[1] = boundary_condition ( x[1], time_new ); if ( id == p - 1 ) h_new[n] = boundary_condition ( x[n], time_new ); /* Update time and temperature. */ time = time_new; for ( i = 1; i <= n; i++ ) h[i] = h_new[i]; /* End of time loop. */ }