Hello All,
My assignment is to do this. However I am unfamiliar with plotting in 3D. This is the scenario.
Create a matlab code to add arbitrary number of 3 dimensional vectors. The input must be the following:
1. n: the number of vectors which must be added
2. For each input vector, the code should accept the following:
a. Length of the vector
b. Three angles which the vector makes with x, y, and z axes
The output:
Output: The result should be the magnitude and the angles which the resultant vector makes with the x, y, and z axes. Plot the resultant vector.
This is my code so far:
x = 0;
n = input('Please input the number of vectors that want to be added: ');
x1 = [];
y1 = [];
z1 = [];
magnitude = [];
while (x < n)
x2 = input('Please put the xcoordinate of the vector: ');
y2 = input('Please put the ycoordinate of the vector: ');
z2 = input('Please put the zcoordinate of the vector: ');
magnitude1 = sqrt(x2^2+y2^2+z2^2)
magnitude = [magnitude magnitude1]
x1 = [x1 x2];
y1 = [y1 y2];
z1 = [z1 z2];
x = x + 1;
end
sprintf('The magnitude(s) of the resultant vector is/are: %3.3f', magnitude)
plot3(x1,y1,z1)
axis([5,5,5,5,5,5])
hold on
grid on
xlabel('xaxis')
ylabel('yaxis')
zlabel('zaxis')
When I plot in matlab, I only get one line, which I am not sure why if, for example, I put in two vectors.
