A MATLAB simulation for observing heat flow and temperature distribution across a 2D conductive surface using the finite difference method with Gauss-Seidel iteration.
| Field | Details |
|---|---|
| Author | Anik Tahabilder |
| Institution | Western Carolina University, NC |
| Program | Master of Science |
| Date Submitted | November 27, 2018 |
This program simulates steady-state heat conduction on a 2D rectangular surface. The simulation models how heat distributes across a conductive material when temperature sources (probes) are applied at various positions.
- Define custom grid dimensions (3x3 to 100x100)
- Place temperature probes on all four edges (top, right, bottom, left)
- Add an optional center probe for internal heat sources
- Real-time animated visualization of heat propagation
- Automatic convergence detection using RMS error analysis
- Export simulation as MP4 video
The simulation solves the 2D steady-state heat conduction equation (Laplace equation):
∂²T/∂x² + ∂²T/∂y² = 0
Using the finite difference method, the temperature at each interior node is calculated as the average of its four neighboring nodes:
T(i,j) = [T(i-1,j) + T(i+1,j) + T(i,j-1) + T(i,j+1)] / 4
The program uses the Gauss-Seidel iterative method to solve the system:
- Initialize the grid with boundary conditions
- Update each interior point using the 4-point average formula
- Calculate RMS error between consecutive iterations
- Repeat until RMS error < accuracy threshold OR maximum iterations reached
RMS = sqrt( Σ(T_new - T_old)² / (rows × columns) )
The solution converges when RMS falls below the user-specified accuracy (0 to 1).
| Region | Condition |
|---|---|
| Probe locations | Fixed temperature (Dirichlet boundary) |
| Non-probe edges | Heat insulated (Neumann boundary - zero flux) |
| Center probe | Fixed temperature island (optional) |
The heat-insulated boundary condition is implemented by copying the temperature from the adjacent interior cell:
% Example: Top edge insulation (before probe)
Matrix(1, 1:probeStart-1) = Matrix(2, 1:probeStart-1)- MATLAB R2015a or later
- Image Processing Toolbox (for visualization)
- No additional dependencies required
- Clone or download this repository
- Open MATLAB
- Navigate to the project directory
- Run the main script:
>> ProjectEnter the number of rows (3 to 100): 60
Enter the number of columns (3 to 100): 50
For each edge (upper, right, bottom, left), you will specify:
- Start position: Where the probe begins
- End position: Where the probe ends
- Temperature: Temperature value in degrees Celsius
Enter start position for upper probe: 15
Enter end position for upper probe: 32
Enter temperature for upper probe: 500
Do you want to have a center probe? Enter Y for yes and N for No: Y
Enter center probe row start: 15
Enter center probe row end: 38
Enter center probe column start: 35
Enter center probe column end: 42
Enter temperature for center probe: 600
Insert the value of minimum accuracy: 0.01
The program will display:
- Real-time heat map animation
- Iteration count
- Final RMS error
- Execution time
*********************************************
Number of iterations = 287
RMS Error = 9.85e-03
Run Time = 12.45 seconds
*********************************************
- Live Figure: Color-coded temperature distribution (jet colormap)
- Color Scale: 0°C (blue) to 1000°C (red)
- Axes: Row and column indices
The simulation automatically generates TEMP.MP4 in the project directory:
- Format: MPEG-4
- Frame Rate: 20 fps
- Contains: Complete iteration history
Heat-Flow-Visualization/
│
├── Project.m # Main program file
├── figure1.m # Results display function
├── README.md # This file
│
├── Grid Input Functions/
│ ├── getRowMatrix.m # Row count input (3-100)
│ └── getColMatrix.m # Column count input (3-100)
│
├── Probe Position Functions/
│ ├── getupperProbStart.m # Upper probe start position
│ ├── getupperProbEnd.m # Upper probe end position
│ ├── getrightProbStart.m # Right probe start position
│ ├── getrightProbEnd.m # Right probe end position
│ ├── getbottomProbStart.m # Bottom probe start position
│ ├── getbottomProbEnd.m # Bottom probe end position
│ ├── getleftProbStart.m # Left probe start position
│ ├── getleftProbEnd.m # Left probe end position
│ ├── getcenterProbRowStart.m # Center probe row start
│ ├── getcenterProbRowEnd.m # Center probe row end
│ ├── getcenterProbColStart.m # Center probe column start
│ └── getcenterProbColEnd.m # Center probe column end
│
├── Temperature Input Functions/
│ ├── getTempUpper.m # Upper edge temperature
│ ├── getTempRight.m # Right edge temperature
│ ├── getTempBottom.m # Bottom edge temperature
│ ├── getTempLeft.m # Left edge temperature
│ └── getTempCenter.m # Center probe temperature
│
├── Simulation Parameters/
│ ├── getAccuracy.m # Convergence threshold (0-1)
│ └── getMaxIter.m # Maximum iterations
│
└── Output/
└── TEMP.MP4 # Generated video (after run)
Here is a sample configuration for testing:
| Parameter | Value |
|---|---|
| Grid Size | 60 rows × 50 columns |
| Upper Probe | Position 15-32, Temperature 500°C |
| Right Probe | Position 36-43, Temperature 1000°C |
| Bottom Probe | Position 17-25, Temperature 800°C |
| Left Probe | Position 22-38, Temperature 387°C |
| Center Probe | Rows 15-38, Cols 35-42, Temperature 600°C |
| Accuracy | 0.01 |
| Max Iterations | 300 |
┌─────────────────────────────────┐
│ Start Program │
└─────────────┬───────────────────┘
▼
┌─────────────────────────────────┐
│ Input Grid Dimensions │
│ (Rows: 3-100, Cols: 3-100) │
└─────────────┬───────────────────┘
▼
┌─────────────────────────────────┐
│ Configure Edge Probes │
│ (Position + Temperature) │
└─────────────┬───────────────────┘
▼
┌─────────────────────────────────┐
│ Optional: Add Center Probe │
└─────────────┬───────────────────┘
▼
┌─────────────────────────────────┐
│ Set Accuracy Threshold │
└─────────────┬───────────────────┘
▼
┌─────────────────────────────────┐
│ Initialize Zero Matrix │
│ Apply Boundary Conditions │
└─────────────┬───────────────────┘
▼
┌─────────────────────────────────┐
│ ┌───────────────────────────┐ │
│ │ Iteration Loop │ │
│ │ ──────────────────── │ │
│ │ 1. Update interior nodes │ │
│ │ 2. Apply insulation BC │ │
│ │ 3. Calculate RMS error │ │
│ │ 4. Update visualization │ │
│ │ 5. Capture video frame │ │
│ └───────────────────────────┘ │
│ │ │
│ ▼ │
│ RMS < Accuracy OR │
│ Iterations >= MaxIter? │
│ │ Yes │
└─────────┼───────────────────────┘
▼
┌─────────────────────────────────┐
│ Display Results │
│ Export Video (TEMP.MP4) │
└─────────────┬───────────────────┘
▼
┌─────────────────────────────────┐
│ Run Again? (Y/N) │
└─────────────────────────────────┘
This simulation can be used to study:
- Heat distribution in electronic components
- Thermal analysis of building materials
- Heat sink design optimization
- Understanding thermal equilibrium concepts
- Educational demonstrations of heat transfer principles
- 2D simulation only (no 3D heat flow)
- Assumes homogeneous material properties
- Fixed colormap range (0-1000°C)
- Maximum grid size limited to 100×100
- Add support for non-rectangular geometries
- Implement variable thermal conductivity
- Add 3D visualization option
- Include transient (time-dependent) heat analysis
- Export temperature data to CSV
Academic Project - Western Carolina University, 2018
This project was completed as part of the Master of Science program at Western Carolina University, Cullowhee, North Carolina.