写的一个代码求求大神帮忙看一下哪里有问题把,救救孩子吧。
import mathh=0.1
r=0.05
m=r/(h*h)
x=0
t=0
u=[]
print('x数值'.ljust(8),'t数值'.ljust(8),'u数值'.ljust(8))
for a in range(101):
u.append([])
for b in range(201):
u.append(0)
while (x==0 and x<101):
u=math.exp(x*h)
x=x+1
while (t==0 and t<201):
u=math.exp(t*r)
u=math.exp(t*r+1)
t=t+1
while (x==1 and x<101):
x=x+1
while (t==1 and t<201):
u=(1-2*m)*u+m*(u+u)
t=t+1
while (x==0 and x<101):
x=x+1
while (t==0 and t<201):
t=t+1
print("%.8f" % x,"%.8f" % t ,"%.8f" % u) 问题呢?? x数值 t数值 u数值
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-19-28d82d7126c7> in <module>
21 x=x+1
22 while (t==1 and t<201):
---> 23 u=(1-2*m)*u+m*(u+u)
24 t=t+1
25 while (x==0 and x<101):
TypeError: can't multiply sequence by non-int of type 'float'
这是他的反馈 wp231957 发表于 2020-3-23 10:34
问题呢??
x数值 t数值 u数值
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-19-28d82d7126c7> in <module>
21 x=x+1
22 while (t==1 and t<201):
---> 23 u=(1-2*m)*u+m*(u+u)
24 t=t+1
25 while (x==0 and x<101):
TypeError: can't multiply sequence by non-int of type 'float'
这是它的反馈 头铁学习 发表于 2020-3-23 10:38
x数值 t数值 u数值
---------------------------------------------------------------- ...
你想实现啥呢
对于你的代码,无法理解,x==0同时x还要<???
那不就是x=0吗?那为啥还要用循环呢 wp231957 发表于 2020-3-23 11:04
你想实现啥呢
对于你的代码,无法理解,x==0同时x还要
我希望用Python实现以下功能 但是我刚接触编程 感觉很困难
#include<stdio.h>
#include<math.h>
void main()
{
FILE *fp;
fp=fopen("xs.txt","w");
int j,k;
float r,u;
float h=0.1,t=0.005;
r=t/pow(h,2);
for(k=0;k<51;k++)
{
u=exp(k*h);
}
for(j=0;j<201;j++)
{
u=exp(j*t);
u=exp(1+j*t);
}
for(j=1;j<201;j++)
{
for(k=1;k<50;k++)
{
u=(1-2*r)*u+r*(u+u);
}
}
for(j=0;j<201;j++)
{
for(k=0;k<51;k++)
{
fprintf(fp,"%f %f %f\n", j*t, k*h,u);
}
}
} 头铁学习 发表于 2020-3-23 11:22
我希望用Python实现以下功能 但是我刚接触编程 感觉很困难
#include
#include
啥功能你倒是说啊,你拿一坨代码干嘛 wp231957 发表于 2020-3-23 11:25
啥功能你倒是说啊,你拿一坨代码干嘛
嗯就是当(x<=10)时u(x,o)=e^x
(t<=10)时u(0,t)=e^t,u(10,t)=e^(1+t)
其余项u=(1-2*m)*u+m*(u+u)
然后打印出使用u的值 头铁学习 发表于 2020-3-23 11:34
嗯就是当(x
大神 这是我们微分方程课程的一个作业 但是之前没有接触过编程所以实在有点头疼
页:
[1]