下面这个mathematica程序 哪位高手能改成 matlab 程序

2024-12-04 21:43:42
推荐回答(1个)
回答1:

mathematica程序有问题,运行结果狗屁不是.现在还不大看的懂
帮你纠正几个错误:
Clear[a, b, x, n, f];
a = Input["a="]
b = Input["b="]
f = 3/20*Exp[-9 (# - 170)^2/800]/Sqrt[2 Pi] &
eps = 0.0000001;
h = b - a;
t1 = (f[a] + f[b])*(b - a)/2;
h = h/2;
t2 = t1/2 + h*f[a + h];
er = t2 - t1 // N;

While[Abs[er] > eps, Print["n=", 2^n, "定积分值为", N[t2, 10]];
Print["误差=", er];
h = h/2;
t1 = t2;
n++;
t2 = t1/2 + h*Sum[f[a + k*h], {k, 1, 2^n, 2}];
er = t2 - t1 // N];

Print["n=", 2^n, "定积分值为", N[t2, 10]];
Print["误差=", er]