MATLAB Answers


How to code orthogonal unit vectors?

Asked by Jenny Andersen on 18 Nov 2019 at 16:36
Latest activity Commented on by Rena Berman on 12 Dec 2019 at 14:45
Hi, I have two vectors, u = (u1, u2, u3) and the vector v = (v1, v2, v3) with the lenght of 1. The two vectors are orthagonal to each other and the first coordinate is 0. I am trying to figure out how to write this in matlab. I have tried the following:
u=input('Please enter a vector u=[u1 u2 u3]: ');
v1 = [0 u(2) u(3)];
v1 = v1 / norm(v1);
u = cross(u,v);
disp(' ');
% Vectors are calculated
But it does not seem to be working so I guess some variable/variables are not correct. Can you see what is wrong?

  1 Comment

Rena Berman on 12 Dec 2019 at 14:45
(Answers Dev) Restored edit

Sign in to comment.


1 Answer

Answer by Steven Lord
on 18 Nov 2019 at 17:33
 Accepted Answer

Nowhere in your code did you define a variable named v, so line 4 of the code you posted should (and will) throw an error. Did you mean to use v1 there?
After getting past that line, again nowhere in your code is the variable w defined so the line "v1 = 1*w;" will throw an error. Maybe you meant to assign the output of cross to a variable named w?


Sign in to comment.