Symbolic toolbox mpower unexpected behaviour

19 ビュー (過去 30 日間)
Yannick Couzinié
Yannick Couzinié 2017 年 6 月 24 日
コメント済み: Yannick Couzinié 2017 年 7 月 4 日
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.

採用された回答

Stefan Wehmeier
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)
  1 件のコメント
Yannick Couzinié
Yannick Couzinié 2017 年 7 月 4 日
I guess this really is the base of the problem I was having. Once I get the calculations to run through I will accept this answer.

サインインしてコメントする。

その他の回答 (2 件)

Richard Marveldoss
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)
  1 件のコメント
Yannick Couzinié
Yannick Couzinié 2017 年 7 月 2 日
編集済み: Yannick Couzinié 2017 年 7 月 4 日
I should've written the assumptions for A, B, C. For all intents and purposes they are assumed to be reals.
I realize that this is not a simple arithmetic task. And I guess, inserting values for N and guessing the general result by induction would've been easier than trying to solve the general case.
But just out of interest, is it not still unexpected that the trace operator has no effect on a matrix object? Exponentiated matrices are still matrices, so at least giving an error like 'this is too complex' or 'Expected integer and not symbol as exponential' or something would be better, wouldn't it? It is that point that still bugs me.

サインインしてコメントする。


Walter Roberson
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))
  1 件のコメント
Yannick Couzinié
Yannick Couzinié 2017 年 7 月 3 日
編集済み: Yannick Couzinié 2017 年 7 月 4 日
I figured as much. And, I guess, I should've found the sum(diag(x)) way myself. Thank you very much (though sadly it turns out it doesn't solve my particular problem)!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeNumber Theory についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by