- Mathematica 常见指令汇编
常见指令
NDSolve 求解结果的保存
sol = NDSolve[{y'[x] == x^2, y[0] == 0, g'[x] == -y[x]^2,
g[0] == 1}, {y, g}, {x, 0, 1}];
numericSoly = sol[[1, 1, 2]];
numericSolg = sol[[1, 2, 2]];
data = Table[{x, numericSoly[x], numericSolg[x]}, {x, 0, 1, 0.01}];
dataset = Dataset[AssociationThread[{"x", "y", "g"}, #] & /@ data];
Export["C:\\Users\\LX\\Desktop\\data.csv", dataset]
Plot[{numericSoly[x], numericSolg[x]}, {x, 0, 1}]
FindMinimum 求解结果的保存
f[x_, y_] := x^2 + y^2;
constraint = {x + y >= 1, Abs[x - y] >= 0.5};
sol = FindMinimum[{f[x, y], constraint}, {{x, 0}, {y, 0}}]
minimizedVariables = sol[[2]];
minimumValue = sol[[1]];
data = {{"x", "y", "f(x, y)"}, {minimizedVariables[[1]][[2]],
minimizedVariables[[2]][[2]], minimumValue}};
Export["C:\\Users\\LX\\Desktop\\result.xlsx", data]
FindMinimum 不支持在整数规划以外的不等约束与域约束