Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Plotting Separate Vectors with Coordinate Points

Subject: Plotting Separate Vectors with Coordinate Points

From: flip

Date: 8 Sep, 2013 02:00:07

Message: 1 of 4

Hello All,
My assignment is to do this. However I am unfamiliar with plotting in 3-D. 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 x-coordinate of the vector: ');
y2 = input('Please put the y-coordinate of the vector: ');
z2 = input('Please put the z-coordinate 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('x-axis')
ylabel('y-axis')
zlabel('z-axis')

When I plot in matlab, I only get one line, which I am not sure why if, for example, I put in two vectors.

Subject: Plotting Separate Vectors with Coordinate Points

From: Roger Stafford

Date: 8 Sep, 2013 08:21:07

Message: 2 of 4

"flip" wrote in message <l0gln7$c1s$1@newscl01ah.mathworks.com>...
> 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.
- - - - - - - - - - -
  I think you have misunderstood your assignment. You were asked to input only the length (magnitude) and angles with respect to the axes for each input vector, not their coordinates! One aim of the exercise appears to be to have you to calculate those coordinates from these inputs.

  Also you were asked to find the vector sum of these vectors, not to concatenate their lengths, and to calculate the length of this resultant vector and the three angles it makes with the axes, not to concatenate and plot all the separate vectors.

Roger Stafford

Subject: Plotting Separate Vectors with Coordinate Points

From: Roger Stafford

Date: 8 Sep, 2013 09:22:09

Message: 3 of 4

"flip" wrote in message <l0gln7$c1s$1@newscl01ah.mathworks.com>...
> 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
- - - - - - - -
  I should add to my previous remarks that whoever thought up this assignment played a trick on the students, whether intentionally or inadvertently. The three angles which are required for each vector are not independent of one another (assuming the three axes are orthogonal.) The sum of the squares of their respective cosines must always be equal to one. A proper set of three input angles will therefore take a little computation on the part of the user to make them valid.

Roger Stafford

Subject: Plotting Separate Vectors with Coordinate Points

From: flip

Date: 8 Sep, 2013 17:59:06

Message: 4 of 4

"Roger Stafford" wrote in message <l0hfk1$7a$1@newscl01ah.mathworks.com>...
> "flip" wrote in message <l0gln7$c1s$1@newscl01ah.mathworks.com>...
> > 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
> - - - - - - - -
> I should add to my previous remarks that whoever thought up this assignment played a trick on the students, whether intentionally or inadvertently. The three angles which are required for each vector are not independent of one another (assuming the three axes are orthogonal.) The sum of the squares of their respective cosines must always be equal to one. A proper set of three input angles will therefore take a little computation on the part of the user to make them valid.
>
> Roger Stafford

My teacher said that we can use coordinates. How do I go about doing this?

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us