Symbolic toolbox mpower unexpected behaviour
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Yannick Couzinié
le 24 Juin 2017
Commenté : Yannick Couzinié
le 4 Juil 2017
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 commentaires
Réponse acceptée
Stefan Wehmeier
le 3 Juil 2017
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)
Plus de réponses (2)
Richard Marveldoss
le 30 Juin 2017
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 commentaire
Walter Roberson
le 3 Juil 2017
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 commentaire
Voir également
Catégories
En savoir plus sur Symbolic Variables, Expressions, Functions, and Settings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!