我有这样的错误:
坐标..不是浮点数
并无法正确修复它。
该程序适用于函数1 - t *y
,但不适用于y*y*Exp[t] - 2*y
。
如果你告诉我为什么以及如何解决这个问题,我将非常高兴。
ABM[a0_, b0_, \[Alpha]_, m0_] :=
Module[{a = a0, b = b0, F, j, k, m = m0, p},
h = (b - a)/m; T = Table[a, {m + 1}];
Y = Table[\[Alpha], {m + 1}];
For[j = 1, j <= 3, j++, Subscript[k, 1] = h*f[T[[j]], Y[[j]]];
Subscript[k, 2] = h*f[T[[j]] + h/2, Y[[j]] + Subscript[k, 1]/2];
Subscript[k, 3] = h*f[T[[j]] + h/2, Y[[j]] + Subscript[k, 2]/2];
Subscript[k, 4] = h*f[T[[j]] + h, Y[[j]] + Subscript[k, 3]];
Y[[j + 1]] = Y[[j]] + (1/6)*(Subscript[k, 1] + 2*Subscript[k, 2] +
2*Subscript[k, 3] + Subscript[k, 4]);
T[[j + 1]] = a + h*j; ];
Subscript[F, 0] = f[T[[1]], Y[[1]]]; Subscript[F, 1] =
f[T[[2]], Y[[2]]]; Subscript[F, 2] = f[T[[3]], Y[[3]]];
Subscript[F, 3] = f[T[[4]], Y[[4]]]; For[j = 4, j <= m, j++,
p = Y[[j]] + (h/24)*(-9*Subscript[F, 0] + 37*Subscript[F, 1] -
59*Subscript[F, 2] + 55*Subscript[F, 3]);
T[[j + 1]] = a + h*j;
p = Y[[j]] + (h/24)*(Subscript[F, 1] -
5*Subscript[F, 2] + 19*Subscript[F, 3] +
9*f[T[[j + 1]], p]);
Y[[j + 1]] = p; Subscript[F, 0] = Subscript[F, 1];
Subscript[F, 1] = Subscript[F, 2]; Subscript[F, 2] =
Subscript[F, 3];
Subscript[F, 3] = f[T[[j + 1]], Y[[j + 1]]]; ];
Return[Transpose[{T, Y}]]];
f[t_, y_] = y*y*Exp[t] - 2*y;
Print["Find numerical solutions to the D.E."];
Print["y' = ", f[t, y]];
n = 25;
pts1 = ABM[0, 8, 2., n];
Y1 = Y;
Needs["Graphics`Colors`"];
graph1 = ListPlot[pts1, PlotJoined -> True, PlotStyle -> Green,
PlotRange -> {{0, 10}, {0, 10}}];
Print["The Adams-Bashforth-Moulton solution for y' = ", f[t, y]];
Print["Using n = ", n + 1, " points."];
Print[pts1];
Print[""];
Print["The final value is y(5) = ", Subscript[y, n + 1], " = ",
Y[[n + 1]]];