The solution of wave equation represents the displacement function u(x, t) defined for the value of x form 0 to l and for t from 0 to ∞ which satisfies the initial and boundary conditions. The wave equation arises from the convective type of problems in vibration, wave mechanics and gas dynamics. It’s solution is not as simple as the solution of ordinary differential equation.
The Wave Equation is the simplest example of hyperbolic differential equation which is defined by following equation:
δ2u/δt2 = c2 * δ2u/δt2
The C program for solution of wave equation presented here uses the following boundary conditions to solve the problems:
u1 (x,0) = φ(x)
u(0, t) = ψ1(t)
u(1,t) = ψ2(t)
When the program for Wave Equation in C language is executed, it solves the wave equation by following the steps listed below:
- First of all, the program asks for the value of square of c.
- Then, the user has to input value of initial and boundary conditions i.e, u(0,t) and u(5,t). In this program, u(0,t) and u(5,t) are initial and boundary conditions respectively. They can be changed depending upon the nature of problem and given criteria for solution.
- After inputting these parameters, the program displays the output on screen.
Source Code for Solution of Wave Equation in C:
Here, the function defined is f(x) = x2 (5-x). X and T are macros whose values are assigned to be 5.
f(x) = x2 (5-x)
#define X 5
#define T 5
float fun(int x)
float u[X+1][T+1],square_of_c, ut, ue;
printf("\n Enter the square of c: ");
printf(" Enter the value of u[t]:");
printf(" Enter the value of u[%d][t]:",X);
printf(" The values of u[i][j] are: \n");
Seeking the solution of wave equation via. manual calculation involves a high probability of occurrence of error, and it requires special techniques of numerical methods leading to lengthy calculations. This C program is simply a programming approach to find solution of wave equation. If you have any question, bring them up from the comments.