C Program for Solution of Heat Equation

0
7661

A number of partial differential equations arise during the study and research of applied mathematics and engineering. Some frequently used partial differential equations in engineering and applied mathematics are heat equation, equation of boundary layer flow, equation of electromagnetic theory, poison’s equation etc..

But only few of them can be solved analytically which is more laborious and time consuming. Here, is a C program for solution of heat equation with source code and sample output. It can be used to solve one dimensional heat equation by using Bendre-Schmidt method.

The working principle of solution of heat equation in C is based on a rectangular mesh in a x-t plane (i.e. space-time plane) with the spacing h along x direction and k along t direction or. Simply, a mesh point (x,t) is denoted as (ih,jk). The calculations are based on one dimensional heat equation which is given as:

δu/δt = c22u/δx2

where c2 = k/sρ is the diffusivity of a substance,
k= coefficient of conductivity of material,
ρ= density of the material, and
s= specific heat capacity

The C source code given here for solution of heat equation works as follows:

  • As the program is executed first of all it asks for value of square of c, value of u(0, t) and u(8, t) .
  • Using the input value the C program calculates the value of alpha.
  • Then, the iteration stats to calculate the value of u  at different space and time i.e. u(x,t) using following iteration formula:

Ui,j+1 = ½( ui-1, j + ui+1,j )

  • Finally the the program gives the result as console output as rectangular mess.

In this C program, the function defined is f(x) = 4x-x2/2 and ‘X’ and ‘T’ are macros whose values are 8 and 5 respectively.

f(x) = 4x-x2/2

Source Code for Solution of Heat Equation in C:

Input/Output:

C Program for Solution of Heat Equation Output
Also see,
Solution of Wave Equation in C
Numerical Methods Tutorial Compilation

The analytical solution of heat equation is quite complex. The C program for solution of heat equation is a programming approach to calculate head transferred through a plate in which heat at boundaries are know at a certain time. With help of this program the heat any point in the specimen at certain time can be calculated.

LEAVE A REPLY

Please enter your comment!
Please enter your name here