Professional Documents
Culture Documents
pdf
/* C Program: Solution of Parabolic Equation(Heat Equation).
Done by-Subhajit Bakshi
Roll No-100173320250028 */
#include<stdio.h>
#include<math.h>
#define XEND 8
#define TEND 5
float f(int x)
{
return 4*x-(x*x)/2.0;
}
main()
{
float u[XEND+1][TEND+1],h=1.0,k=0.125,alpha,r,ust,uet;
int i,j;
printf("Enter the value of alpha: ");
scanf("%f",&alpha);
r=(alpha*k)/(h*h);
printf("Enter the value of u[0][t] \n");
scanf("%f",&ust);
printf("Enter the value of u[%d][t] \n",XEND);
scanf("%f",&uet);
for(j=0;j<=TEND;j++)
u[0][j]=u[XEND][j]=ust;
for(i=1;i<=XEND-1;i++)
u[i][0]=f(i);
for(j=0;j<=TEND-1;j++)
for(i=1;i<=XEND-1;i++)
u[i][j+1]=r*u[i-1][j]+(1-2*r)*u[i][j]+r*u[i+1][j];
printf("The value of r is %4.2f \n",r);
printf("The value of u[i][j] are: \n");
for(j=0;j<=TEND;j++)
{
for(i=0;i<=XEND;i++)
printf("%7.4f",u[i][j]);
printf("\n");
}
}
*********OUTPUT RESULT*********
Page 1