MATLAB function cross can be applied to symbolic object but Documentation does not explain?
Mostrar comentarios más antiguos
syms x y z
vec1=[x y z];
vec2=[x y z];
cross(vec1,vec2)
Respuestas (1)
Ameer Hamza
el 3 de Dic. de 2020
It works fine in R2020b, are you using an older release?
syms x y z
vec1 = [x y z];
vec2 = [x y z];
x = cross(vec1, vec2);
Result
>> x
x =
[0, 0, 0]
4 comentarios
Chuguang Pan
el 3 de Dic. de 2020
Ameer Hamza
el 3 de Dic. de 2020
Yes, you are right. Even in R2020b, the symbolic toolbox does not have separate documentation for cross-function. I think it is not officially supported; however, if you look at the implementation of cross()
edit cross
you can see that it just uses simple arithmetic operations, which are also supported for symbolic variables. So, maybe it "unintentionally" got support for symbolic variables too.
Walter Roberson
el 3 de Dic. de 2020
Especially back in those days, a lot of the numeric functions did not check specifically that their arguments were numeric. They just went ahead with the calculations, and if the calculations happened to involve an operation not possible on the variable type you were using, you would get an error in that particular operation.
Ameer Hamza
el 3 de Dic. de 2020
Also, inside cross.m file, it specifically mentions that it supports single and double classes. However, it works fine for other datatypes too
>> a = randi(10, 1, 3);
b = randi(10, 1, 3);
>> cross(a, b)
ans =
-14 37 -10
>> cross(int8(a), b)
ans =
1×3 int8 row vector
-14 37 -10
Categorías
Más información sobre Common Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!