# Why Octave don't perform Cross product of vectors?

Octave don’t perform ‘Cross’ product function of these two vectors.

``````>> pkg load symbolic
>> cross ([0 cos(u) sin(u)], [0 -v*sin(u) v*cos(u)])
error: 'u' undefined near line 1, column 16
>> % Define the limits of u and v
>> 0< u <2*pi;
error: 'u' undefined near line 1, column 4
>> 0 < u <2*pi;
error: 'u' undefined near line 1, column 5
>> 0 < u;
error: 'u' undefined near line 1, column 5
>> u = 0:2*pi;
>> v = 0:1;
>> cross ([0 cos(u) sin(u)], [0 -v*sin(u) v*cos(u)])
error: operator *: nonconformant arguments (op1 is 1x2, op2 is 1x7)
``````

How is that?What is wrong?

Check the sizes of `u` and `v`, or look at the values in these vectors.
You’ll probably see the reason for the error.

Octave is a numerical computation software primarily. You seem to be using it like it would be a symbolic computation software.

Now, I got the correct answer.

``````>> v=1;
>> cross ([0 cos(u) sin(u)], [0 -v*sin(u) v*cos(u)])
error: cross: must have at least one dimension with 3 elements
error: called from
cross at line 73 column 8
>> cross ([0,cos(u),sin(u)],[0,-v*sin(u),v*cos(u)])
error: cross: must have at least one dimension with 3 elements
error: called from
cross at line 73 column 8
>> cross ([0,cos(0),sin(0)],[0,-v*sin(0),v*cos(0)])
ans =

1   0   0

>> cross ([0,cos(2*pi),sin(2*pi)],[0,-v*sin(2*pi),v*cos(2*pi)])
ans =

1   0   0

``````

How is that?

Your last example only does scalar multiplication. For vector multiplication (like in your initial example), the dimensions of the vectors must match.

You didn’t declare u & v as symbolic variables. Insert this line after the pkg load:
“syms u v”

This is what I got for output:

>> syms u v
Symbolic pkg v3.0.0: Python communication link active, SymPy v1.10.1.
>> cross([0, cos(u), sin(u)], [0, cos(v), sin(v)])
ans = (sym) [-sin(u)*cos(v) + sin(v)*cos(u) 0 0] (1x3 matrix)

try

syms u v

cross ([0 cos(u) sin(u)], [0 -vsin(u) vcos(u)])
ans = (sym 1×3 matrix)

⎡ 2 2 ⎤
⎣v⋅sin (u) + v⋅cos (u) 0 0⎦

1 Like