Rob*_*ist 2 matlab wolfram-mathematica
我有一个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]);
Run Code Online (Sandbox Code Playgroud)
使用ReplaceAll可以写成如下的函数来实现等效的Mathematica操作.
Integrate[Sin[x], x] /. x -> 3
(*Out: -Cos[3] *)
Run Code Online (Sandbox Code Playgroud)
如果要替换多个值,可以实现:
Integrate[Sin[x], x] /. x -> # & /@ { 7, 5, 8, 11, 13}
(* Out: {-Cos[7], -Cos[5], -Cos[8], -Cos[11], -Cos[13]} *)
Run Code Online (Sandbox Code Playgroud)
或者像Mr.Wizard建议的更紧凑和有效的方法:
Integrate[Sin[x], x] /. x -> {7, 5, 8, 11, 13}
Run Code Online (Sandbox Code Playgroud)