mtaylor MuPAD-Matlab [英] mtaylor MuPAD - Matlab
问题描述
我正在尝试从MatLab的MuPAD引擎运行函数mtaylor
,该引擎提供函数的多变量泰勒展开.但是,它总是告诉我我正在尝试扩展无效点.这是我尝试过的最小工作示例:
I am trying to run the function mtaylor
from the MuPAD engine in MatLab, which provides a multivariate Taylor expansion of a function. However, it keeps telling me I am trying to expand around an invalid point. Here is a minimal working example of what I tried:
syms x y;
feval(symengine,'mtaylor',exp(x^2 - y), [x, y], 4)
Error message:
vError using mupadengine/feval (line 157)
MuPAD error: Error: Invalid expansion point. [mtaylor]
为什么这行不通?
推荐答案
与MuPAD的 mtaylor
The reason this works with MuPAD's mtaylor
syms x y;
feval(symengine,'mtaylor',exp(x^2 - y), x, 4) % [x] is fine too
这不是
syms x y;
feval(symengine,'mtaylor',exp(x^2 - y), [x, y], 4)
是[x, y]
自变量被视为单个符号向量自变量/变量,而不是用于扩展的变量列表.您的表达式exp(x^2 - y)
并不是矢量变量,而是简单的标量x
和y
.
is that the [x, y]
argument is seen as a single symbolic vector argument/variable rather than a list of variables for the expansion. Your expression, exp(x^2 - y)
, is not in terms of vector variables, but simple scalars, x
and y
.
解决方法是将列表作为字符串传递:
The workaround is to pass the list as a string:
syms x y;
feval(symengine,'mtaylor',exp(x^2 - y), '[x, y]', 4)
或
syms x y;
feval(symengine,'mtaylor',exp(x^2 - y), ['[' char(x) ',' char(y) ']'], 4)
或使用 evalin
将MuPAD命令写为单个字符串,如下所示: @Daniel在评论中建议:
or use evalin
to write the MuPAD command a single string as suggested by @Daniel in the comments:
syms x y;
evalin(symengine,'mtaylor(exp(x^2 - y), [x, y], 4)')
MuPAD中的数组和矩阵与列表
为了进一步说明,Matlab中的符号变量数组对应于MuPAD array
类型,可以通过feval(symengine,'array','1..1','1..2','[x,y]')
创建.更具体地说,它们的类型为 Dom::Matrix()
,通过V=feval(symengine,'Dom::Matrix()','[x,y]')
或仅通过syms x y;
V=[x,y]
创建.
Arrays and Matrices vs. Lists in MuPAD
For further clarification, arrays of symbolic variables in Matlab correspond to the MuPAD array
type, which can be created via feval(symengine,'array','1..1','1..2','[x,y]')
. More specifically, they are of type Dom::Matrix()
, which can be created via V=feval(symengine,'Dom::Matrix()','[x,y]')
or just syms x y;
V=[x,y]
.
mtaylor
函数需要一个列表输入,可以通过L=evalin(symengine,'[x,y]')
创建.因此
The mtaylor
function requires a list input, which can be created via L=evalin(symengine,'[x,y]')
. Thus
syms x y;
feval(symengine,'mtaylor',exp(x^2 - y), V, 4)
将产生与您的问题相同的错误,但是
will produce the same error as in your question, but
syms x y;
feval(symengine,'mtaylor',exp(x^2 - y), L, 4)
将正常工作.不幸的是,L
和V
在Matlab中看起来是相同的,但是您可以使用MuPAD的 domtype
函数来区分它们:
will work correctly. Unfortunately, L
and V
appear identical from within Matlab, but you can use MuPAD's domtype
function to differentiate them:
feval(symengine,'domtype',V)
feval(symengine,'domtype',L)
返回Dom::Matrix()
和DOM_LIST
.
这篇关于mtaylor MuPAD-Matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!