Cody

# Problem 635. Angle between Two Vectors

Solution 3587140

Submitted on 8 Nov 2020
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Fail
a = [1 0]; b = [0 1]; expected=pi/2; theta = solve_included_vector_angle(a,b) assert(0.99*expected-.001<=theta && theta<=expected*1.01+.001 ) % Is there a better way to allow tolerances?

Array indices must be positive integers or logical values. Error in solve_included_vector_angle>solve_length (line 7) for i = 1:length(arr) Error in solve_included_vector_angle (line 2) theta = acos(dot(a,b)/(solve_length(a)*solve_length(b))); Error in Test1 (line 4) theta = solve_included_vector_angle(a,b)

2   Fail
a = [1 1 0]; b = [1 1 2^0.5]; expected=pi/4; theta = solve_included_vector_angle(a,b) assert(0.99*expected-.001<=theta && theta<=expected*1.01+.001 )

Array indices must be positive integers or logical values. Error in solve_included_vector_angle>solve_length (line 7) for i = 1:length(arr) Error in solve_included_vector_angle (line 2) theta = acos(dot(a,b)/(solve_length(a)*solve_length(b))); Error in Test2 (line 4) theta = solve_included_vector_angle(a,b)

3   Fail
a = [2 2]; b = [0 1]; expected=pi/4; theta = solve_included_vector_angle(a,b) assert(0.99*expected-.001<=theta && theta<=expected*1.01+.001 )

Index exceeds the number of array elements (1). Error in solve_included_vector_angle>solve_length (line 7) for i = 1:length(arr) Error in solve_included_vector_angle (line 2) theta = acos(dot(a,b)/(solve_length(a)*solve_length(b))); Error in Test3 (line 4) theta = solve_included_vector_angle(a,b)

4   Fail
a = [-1 1]; b = [4 0]; expected=0.75*pi; theta = solve_included_vector_angle(a,b) assert(0.99*expected-.001<=theta && theta<=expected*1.01+.001 )

Array indices must be positive integers or logical values. Error in solve_included_vector_angle>solve_length (line 7) for i = 1:length(arr) Error in solve_included_vector_angle (line 2) theta = acos(dot(a,b)/(solve_length(a)*solve_length(b))); Error in Test4 (line 4) theta = solve_included_vector_angle(a,b)

5   Fail
a = [-1 2 3]; b = [1 2 4]; expected=0.161*pi; theta = solve_included_vector_angle(a,b) assert(0.99*expected-.001<=theta && theta<=expected*1.01+.001 )

Array indices must be positive integers or logical values. Error in solve_included_vector_angle>solve_length (line 7) for i = 1:length(arr) Error in solve_included_vector_angle (line 2) theta = acos(dot(a,b)/(solve_length(a)*solve_length(b))); Error in Test5 (line 4) theta = solve_included_vector_angle(a,b)

### Community Treasure Hunt

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

Start Hunting!