0% found this document useful (0 votes)
10 views

Numerical Solution of Partial Differential Equations

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Numerical Solution of Partial Differential Equations

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Numerical Solution of Partial

Differential Equations (PDEs)

Name: Tushar
Roll Number: 01116412823
B.Tech 3rd Semester
Numerical Solution of the Heat
Equation (Parabolic PDE)

INTRODUCTION:

The aim of this project is to develop a numerical solution for the one-dimensional heat
equation:

This equation models the temperature distribution in a rod over time. The solution is obtained
using the Explicit Finite Difference Method, a common numerical approach for solving
parabolic partial differential equations.

PROBLEM DESCRIPTION:
The one-dimensional heat equation illustrates the diffusion of heat through a medium as time
progresses. The governing equation is:

Key Terms:

 u(x,t)u(x,t): Temperature at position xx and time tt.


 α\alpha: Thermal diffusivity, a material-specific constant.

Initial and Boundary Conditions:


 Initial condition: u(x,0)=f(x)u(x,0) = f(x), where f(x)f(x) represents the initial
temperature distribution.
 Boundary conditions: u(0,t)=u(L,t)=0u(0,t) = u(L,t) = 0, indicating a fixed
temperature at both ends of the rod.

NUMERICAL SOLUTION:
4.1 Method Used: Explicit Finite Difference Method

4.2 Stability Condition

To ensure stability, the following condition must be satisfied:

αΔt
λ= 2
≤ 0.5
Δx

IMPLEMENTATION IN C:
The user inputs the following in the prompt :

 Thermal diffusivity (α).


 Length of the rod (L).
 Total simulation time (T).
 Number of spatial grid points (nx).
 Number of time steps (nt).

CODE:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

#define PI 3.141592653589793

void solveHeatEquation(double alpha, double L, double T, int nx, int


nt) {
double dx = L / (nx - 1); // Spatial step
double dt = T / (nt - 1); // Time step
double lambda = alpha * dt / (dx * dx);

// Stability check
if (lambda > 0.5) {
printf("Unstable: Reduce time step or increase grid size.\n");
return;
}

// Allocate memory for the temperature arrays


double *u = (double *)malloc(nx * sizeof(double));
double *u_next = (double *)malloc(nx * sizeof(double));

// Initial conditions
for (int i = 0; i < nx; i++) {
double x = i * dx;
u[i] = sin(PI * x); // Example: Sine wave initial condition
}

// Boundary conditions
u[0] = u[nx - 1] = 0.0;

// Time stepping
printf("\nTemperature distribution over time:\n");
for (int n = 0; n < nt; n++) {
// Print current step
for (int i = 0; i < nx; i++) {
printf("%6.4f ", u[i]);
}
printf("\n");

// Compute next time step


for (int i = 1; i < nx - 1; i++) {
u_next[i] = u[i] + lambda * (u[i - 1] - 2 * u[i] + u[i +
1]);
}

// Apply boundary conditions


u_next[0] = u_next[nx - 1] = 0.0;

// Swap arrays for next step


for (int i = 0; i < nx; i++) {
u[i] = u_next[i];
}
}

// Free memory
free(u);
free(u_next);
}

int main() {
double alpha, L, T;
int nx, nt;

// Input parameters from the user


printf("Enter the thermal diffusivity (alpha): ");
scanf("%lf", &alpha);
printf("Enter the length of the rod (L): ");
scanf("%lf", &L);
printf("Enter the total simulation time (T): ");
scanf("%lf", &T);
printf("Enter the number of spatial grid points (nx): ");
scanf("%d", &nx);
printf("Enter the number of time steps (nt): ");
scanf("%d", &nt);

// Solve the heat equation


solveHeatEquation(alpha, L, T, nx, nt);

return 0;
}

OUTPUTS:

You might also like