matlab - matlab中subs()在mathematica中的等效函数

标签 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]);

最佳答案

等效的 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/

相关文章:

matlab - 在 matlab 中对 pcolor 进行着色和 mask

syntax - 如何定义/@-like 操作符

matlab - 如何在 MATLAB 中按特定顺序将行转置为列?

file - 在 Matlab 中读取和处理大文本文件

c++ - 为什么此代码(在 Matlab 的 MEX 文件中使用 OpenMP)给出不同的结果?

wolfram-mathematica - 在 Mathematica 中读取 UTF-8 编码的文本文件

Mathematica 不计算具有实系数的复数的绝对值

wolfram-mathematica - Mathematica 中的连接点

wolfram-mathematica - Mathematica 中的函数和

matlab - 为什么 Matlab 和 Mathematica 之间存在显着的 double 差异?