mtaylor MuPAD - Matlab

做~自己de王妃 提交于 2019-12-02 03:41:54

The reason this works with MuPAD's mtaylor

syms x y;
feval(symengine,'mtaylor',exp(x^2 - y), x, 4)  % [x] is fine too

and this doesn't

syms x y;
feval(symengine,'mtaylor',exp(x^2 - y), [x, y], 4)

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)

or

syms x y;
feval(symengine,'mtaylor',exp(x^2 - y), ['[' char(x) ',' char(y) ']'], 4)

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)')


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].

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)

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)

which returns Dom::Matrix() and DOM_LIST.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!