Question about transcendentals on symmatrix objects
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I'm curious why the following line executes OK:
tan(symmatrix('A',[10 10]))
but this line produces an error:
tanh(symmatrix('A',[10 10]))
Incorrect number or types of inputs or outputs for function tanh.
0 Commenti
Risposte (1)
John D'Errico
il 4 Feb 2024
Modificato: John D'Errico
il 4 Feb 2024
A = symmatrix('A',[2,2])
That produces a matrix of the desired size, which is specifically symmetric, but see that it creates a specific class, not just a general symbolic matrix.
whos A
tanA = tan(A)
tanA(1,2)
tanA(2,1)
We see that tan does apply element-wise to the elements of the symmetric matrix A. TMW has defined the tan function to apply to that specific class of matrix, so tan does not generate an error.
You can see both tan and tanh do operate element-wise on a general symbolic matrix. That is, they are not doing something like expm, which is completely different from how exp works, when applied to a matrix. It is a simple element-wise operation.
B = sym('B',[2,2])
tan(B)
tanh(B)
However, it appears they never extended tanh to recognize a symmetric matrix class as an input. Not a bug, just an oversight. You could certainly provide your own tanh function that would work here, overloading tanh when it is passed a symmatrix class.
If it bothers you and you feel you desperately need that capability, send in a feature request to include tanh in the set of functions that work on that class.
(Hmm. Just woolgathering here, but could you write a matrix sine, cosine, tan, or even tanh that would operate like the matrix exponential? Well, yes. I see no reason why those functions would not also be possible to write. But I see no benefit to that offhand, as I see no useful reason to do so in mathematics. Hey, Cleve, are there also 19 dubious ways to compute the matrix sine? Very likely yes. But would anyone care?)
0 Commenti
Vedere anche
Categorie
Scopri di più su Calculus in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!