Error calculating vector dot product when vector elements are variables

1 view (last 30 days)
Hi,
I'm (mostly) new to MATLAB, and am doing an assignment for my Engineering Diploma. It's due in 3.5 hours' time, and I'm stuck on one of the questions.
I am asked to calculate the scalar triple product of U . (V x W), where U=(a 0 0), V=(0 b 0), and W=(0 0 c).
Here is the code I am attempting to use:
%% Question 3: Compute the scalar triple product U . (V x W) of the vectors U = [a 0 0], V = [0 b 0], and W = [0 0 c]
%
fprintf ("\n\n\nQuestion 3: Compute the scalar triple product U . (V x W) of the vectors U = [a 0 0], V = [0 b 0], and W = [0 0 c]\n\n"); % displays the question
clear; % clears any previously used variables
syms a b c; % creates a, b, and c as variables
U = [a 0 0]; % sets U as a vector as given in the question
V = [0 b 0]; % sets V as a vector as given in the question
W = [0 0 c]; % sets W as a vector as given in the question
STP = dot (U,cross(V,W)) % calculates the scalar triple product of U dot (V x W)
fprintf ("The scalar triple product of U . (V x W) is %s",STP); % displays the result in an easy-to-read format
%
Unfortunately, the answer returned is not what I expected:
STP =
b*c*conj(a)
According to my manual calculations, U.(V x W) = abc, not
I have tried breaking the operation into its two steps by first calculating the cross product, then finding the dot product, but it returns the same final answer:
%% Question 3: Compute the scalar triple product U . (V x W) of the vectors U = [a 0 0], V = [0 b 0], and W = [0 0 c]
%
fprintf ("\n\n\nQuestion 3: Compute the scalar triple product U . (V x W) of the vectors U = [a 0 0], V = [0 b 0], and W = [0 0 c]\n\n"); % displays the question
clear; % clears any previously used variables
syms a b c; % creates a, b, and c as variables
U = [a 0 0]; % sets U as a vector as given in the question
V = [0 b 0]; % sets V as a vector as given in the question
W = [0 0 c]; % sets W as a vector as given in the question
crossvw = cross (V,W) % calculates the cross-product of V x W
STP = dot (U,crossvw) % calculates the scalar triple product of U dot (V x W)
fprintf ("The scalar triple product of U . (V x W) is %s",STP); % displays the result in an easy-to-read format
%
This returns:
Question 3: Compute the scalar triple product U . (V x W) of the vectors U = [a 0 0], V = [0 b 0], and W = [0 0 c]
crossvw =
[b*c, 0, 0]
STP =
b*c*conj(a)
The scalar triple product of U . (V x W) is b*c*conj(a)
In the above, crossvw is correct. However, it is still returning an incorrect result for the dot product.
I have also tried using other functions instead of dot, such as dotprod and vector_dot, however both of them returned:
Undefined function 'dotprod' for input arguments of type
'sym'.
Error in <redacted> (line
33)
STP = dotprod (U,cvw) % calculates the scalar triple product of U dot (V x W)
and
Undefined function 'vector_dot' for input arguments of type
'sym'.
Error in <redacted> (line
33)
STP = vector_dot (U,cvw) % calculates the scalar triple product of U dot (V x W)
respectively.
Can anyone help?
  1 Comment
Bruno Luong
Bruno Luong on 20 Nov 2022
According to my manual calculations U . (V x W) = abc.
It depends on the convention of dot product. In some book
dot(u,v) := sum conj(u(i))*v(i) % MATLAB convention
In other
dot(u,v) := sum u(i)*conj(v(i)) % Probably your manual
I'm not sure what is a proper definition of cross product for complex entries.
The triple product for real entries can be also defined as the determinant of
A = [ux uy uz;
vx vy vz;
wx wy wz];
T = det(A)
instead of
T = u . (v x w)
I'm not quite sure which one can be extended to complex numbers. To be tolally symmetric wrt the inputs I would say for complex the determinant formula hold and the second formula must be modified
T = u* . (v x w) % MATlAb dot product convention

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 20 Nov 2022
The Symbolic Math Toolbox makes the (usually appropriate) assumption that the variables are complex.
Force them to be real by declaring them as such:
syms a b c real
The the result is as expected —
syms a b c real % creates a, b, and c as variables
U = [a 0 0]; % sets U as a vector as given in the question
V = [0 b 0]; % sets V as a vector as given in the question
W = [0 0 c]; % sets W as a vector as given in the question
STP = dot (U,cross(V,W)) % calculates the scalar triple product of U dot (V x W)
STP = 
.
  2 Comments

Sign in to comment.

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!