Symbolic toolbox mpower unexpected behaviour
7 次查看(过去 30 天)
显示 更早的评论
I am trying to run a symbolic calculation which produces an error, and I think I have nailed down the cause to some behaviour of mpower in combination with following operations, which I just don't understand (being fairly new to matlab, so maybe I have made a basic mistake here). The following is a minimal working example
clear
syms A B C N;
assume(N, 'integer')
T = [A B; B C];
TN = mpower(T, N);
tr = trace(TN);
prob = diff(tr, B, 2)
It produces the error
Error using symengine
An arithmetical expression is expected.
which is not the error I am getting on my real code (Not a square matrix by symengine) but the problem should be analogous (I hope). After running mpower(T,N) the returned object is
TN = matrix([[A, B], [B, C]])^N
which is not a matrix (why I call this unexpected on my end), but some kind of scalar since the trace has no effect on it:
tr = matrix([[A, B], [B, C]])^N
So I have been trying to solve this for quite some time now, but I really don't know what I am doing wrong, except of trying to do a non-trivial calculation (I realize that taking general powers is not the easiest thing to handle). Any helping input would be appreciated.
0 个评论
采纳的回答
Stefan Wehmeier
2017-7-3
You can use symbolic N but not in connection with mpower. As T^N = exp(N*log(T)), write
TN = expm(N*logm(T))
and proceed as in your example. You may want to apply simplify in the end:
simplify(prob)
更多回答(2 个)
Richard Marveldoss
2017-6-30
According to the expression used in the given example I assume that A,B,C are not matrices. Since the result of mpower operation is going to vary based on the value of N , the expression cannot be simplified beyond what is the result obtained which makes it improbable for the trace function to be applied on it. A possible workaround would be to a give a value to N and an expression would be obtained(TN) where N would be a fixed value rather than a variable. Below is an example code :
clear
syms A B C ;
%assume(N, 'integer')
N=4;
T = [A B; B C];
TN = mpower(T, N);
tr = trace(TN);
prob = diff(tr, B, 2)
Walter Roberson
2017-7-3
trace is not defined for symbolic expressions https://www.mathworks.com/help/symbolic/functionlist.html
The generic trace() function is seeing that it is being passed what looks like a scalar object to it, and the diagonal of a scalar is the scalar itself, so the result is the same as the input.
diag is defined symbolically so you could use sum(diag(TN))
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Number Theory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!