Filter löschen
Filter löschen

Question about transcendentals on symmatrix objects

1 Ansicht (letzte 30 Tage)
Jason Bakos
Jason Bakos am 4 Feb. 2024
Bearbeitet: John D'Errico am 4 Feb. 2024
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.

Antworten (1)

John D'Errico
John D'Errico am 4 Feb. 2024
Bearbeitet: John D'Errico am 4 Feb. 2024
A = symmatrix('A',[2,2])
A = 
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
Name Size Bytes Class Attributes A 2x2 8 symmatrix
tanA = tan(A)
tanA = 
tanA(1,2)
ans = 
tanA(2,1)
ans = 
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])
B = 
tan(B)
ans = 
tanh(B)
ans = 
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?)

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by