#include
using namespace std;
int main()
{
int i,j,choose,n,m,DL,n2,thickness;
float length,wide,x=0,cha,wucha;
cout<<"选择边界条件:1为等温,2为对流换热"<<'\n';
cin>>choose;
cout<<"输入墙的长度"<<'\n';
cin>>length;
cout<<"墙的宽度"<<'\n';
cin>>wide;
cout<<"输入步长:"<<'\n';
cin>>DL;
cout<<"输入墙的厚度:"<<'\n';
cin>>thickness;
cout<<"输入计算误差:"<<'\n';
cin>>wucha;
n2=thickness/DL;
n=(int)length/(2*DL);
m=(int)wide/(2*DL);
float **T0=new float *[m+1];
for(i=0;i
for(i=0;i
}
float **T=new float *[m+1];
for(i=0;i
for(i=0;i
}
if(choose==1)
{
float t1,t2;
cout<<"外壁面温度:"<<'\n';
cin>>t1;
cout<<"内壁面温度:"<<'\n';
cin>>t2;
for(i=0;i<=n;i++)
T[0][i]=t1;
for(i=0;i<=m;i++)
T[i][0]=t1;
for(i=n2;i<=m;i++)
T[i][n2]=t2;
for(i=n2;i<=n;i++)
T[n2][i]=t2;
do
for(choose=0;choose<=10;choose++)
{
for(i=1;i
for(j=1;j
}
for(i=1;i
for(j=n2;j
}
for(i=1;i
for(i=1;i
x=(T0[1][1]-T[1][1])/T0[1][1];
for(i=1;i
{
if(T0[i][j]>=T[i][j])
cha=(T0[i][j]-T[i][j])/T0[i][j];
else
cha=(T[i][j]-T0[i][j])/T0[i][j];
if(cha>x)
x=cha;
T0[i][j]=T[i][j];
}
}
for(i=n2;i<=m;i++)
{
for(j=1;j
if(T0[i][j]>=T[i][j])
cha=(T0[i][j]-T[i][j])/T0[i][j];
else
cha=(T[i][j]-T0[i][j])/T0[i][j];
if(cha>x)
x=cha;
T0[i][j]=T[i][j];
}
}
}while(x>=wucha);
for(i=0;i<=n2;i++)
{
for(j=0;j<+n;j++)
cout<
}
for(i=n2+1;i<=m;i++)
{
for(j=0;j<=n2;j++)
cout<
}
{
for(j=0;j<=m;j++)
{
cha=(T0[i][j]-T[i][j])/T0[i][j];
if(T0[i][j]>T[i][j])
{
if(cha>x)
x=(T0[i][j]-T[i][j])/T0[i][j];
}
if(T0[i][j]<=T[i][j])
{
cha=-cha;
if(cha>x)
x=(T[i][j]-T0[i][j])/T0[i][j];
}
}
}
}
delete []T;
delete []T0;
return 0;
}