|

楼主 |
发表于 2020-3-23 11:22:59
|
显示全部楼层
我希望用Python实现以下功能 但是我刚接触编程 感觉很困难
#include<stdio.h>
#include<math.h>
void main()
{
FILE *fp;
fp=fopen("xs.txt","w");
int j,k;
float r,u[51][201];
float h=0.1,t=0.005;
r=t/pow(h,2);
for(k=0;k<51;k++)
{
u[k][0]=exp(k*h);
}
for(j=0;j<201;j++)
{
u[0][j]=exp(j*t);
u[50][j]=exp(1+j*t);
}
for(j=1;j<201;j++)
{
for(k=1;k<50;k++)
{
u[k][j]=(1-2*r)*u[k][j-1]+r*(u[k+1][j-1]+u[k-1][j-1]);
}
}
for(j=0;j<201;j++)
{
for(k=0;k<51;k++)
{
fprintf(fp,"%f %f %f\n", j*t, k*h,u[k][j]);
}
}
} |
|