我有一个 matlab m 文件,用于绘制积分,如下所示。我想在 mathematica 中重写这段代码,但我不知道 subs() 的任何等效函数!有人帮助我吗?
syms x y w;
fun = (-1/(4.*pi)).*log(x.^2+(y-w).^2);
integral = int(fun, w);
res_l = subs(integral, w, -0.5);
res_u = subs(integral, w, 0.5);
res = res_u - res_l;
ezsurf(res, [-1,1]);
最佳答案
等效的 Mathematica 操作是使用 ReplaceAll
函数实现的,可以编写如下。
Integrate[Sin[x], x] /. x -> 3
(*Out: -Cos[3] *)
如果你想替换多个值,可以这样实现:
Integrate[Sin[x], x] /. x -> # & /@ { 7, 5, 8, 11, 13}
(* Out: {-Cos[7], -Cos[5], -Cos[8], -Cos[11], -Cos[13]} *)
或者按照Mr.Wizard的建议,一种更紧凑、更高效的方法:
Integrate[Sin[x], x] /. x -> {7, 5, 8, 11, 13}
关于matlab - matlab中subs()在mathematica中的等效函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10594590/