CFDGSF

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

#include <stdio.

h>
#include <math.h>

int main(void) {

int i,j,c,n,m,k,temp;
float a,b,l,h,x,y;
printf("type the temperature for three equal sides");
scanf("%f",&a);
printf("type the temperature for the other side");
scanf("%f",&b);
printf("type the length and width of the area");
scanf("%f%f",&l,&h);
printf("type the length scale size for length and width");
scanf("%f%f",&x,&y);
n=l/x;
m=h/y;
c=x/y;
float sum=1,e,temps,t[n+1][m+1],d[n+1][m+1];
FILE *mal;

for(i=0;i<(n+1);i++)
{
for(j=0;j<(m+1);j++)
{
if(j==0)
{t[i][j]=b;}
else
{t[i][j]=0;}
}
}

while(sum>=e)
{
sum=0;
for(i=1;i<n;i++)
{
for(j=1;j<m;j++)
{
d[i][j]=t[i][j];
t[i][j]=(t[i-1][j]+t[i+1][j]+(pow(c,2)*(t[i][j-1]+t[i][j+1])))/
(2*(1+pow(c,2)));
temp=fabs(t[i][j]-d[i][j]);
sum=sum+temp;
//printf("%f",sum);
}
}
}

mal=fopen("mat1.dat","w");
fprintf(mal,"Variables x,y,T\n");
for(i=0;i<(n+1);i++)
{
for(j=0;j<(m+1);j++)
{
fprintf(mal,"%d %d %.lf\n",i,j,t[i][j]);
}
}
fclose(mal);

for(i=0;i<(n+1);i++)
{
printf("\n");
for(j=0;j<(m+1);j++)
{
printf("%.lf\t",t[i][j]);
}
}

return 0;
}

You might also like