How to plot a set of vectors dependent on a variable?

16 views (last 30 days)
Hi everyone, I´m still very new to Matlab (and programming in general) and searches in the internet haven´t been really helpful. I would be really grateful if someone could help me. How can I plot a whole set of vectors, that are dependent on a variable with certain values? For example: F=[x^2, 3x], with x [0, 100] (isn´t the one I need to work at). How could I plot these 100 functions without giving the command plot (x^2, 3x) a hundred times? Also, how would i be able to centre the whole thing around the point of origin, and make it a vector polygon?
I´m really sorry if someone else already posted this - I havn't found anything.

Answers (1)

KL
KL on 18 Nov 2017
Simply create a vector for x,
x = 1:100;
now calculate your result, say y,
y = [x.^2; 3*x];
in the above line, we are creating a matrix where first row calculates x² (x.^2 meaning, taking square of every element) and second row calculates 3x.
now plot it against x by simply saying,
plot(x,y)
now you can also add legends to identify two curves by,
legends('x^2','3*x')
  4 Comments
Sean Zettl
Sean Zettl on 18 Nov 2017
Well, I have been given a formula that describes a force in x and y components, in dependence on a degree between 1 and 360. After having calculated whether all of the forces cancel each other out, I am now supposed to plot for each degree the resulting force (so eg the force for 30 degrees), and plot all 360 of them from the point of origin.
I have summarised the whole system as a matrix which then gives me as a result whether the whole things is balanced or not. Can I use this to implement the different values of the force and plot them?
Also, thank you for trying to help me. I know that it is probably some really stupid question, and am very thankful for your help.
Here is the code (I hope I am implementing this correctly here)
a=(0:359);
Fx = (1 + 1)*cosd(a)-cosd((1 + 1)*a);
Fy = (1 + 1)*sind(a)-sind((1 + 1)*a);
A = [Fx; Fy];
S = sum(A,2);
a = 0:359;
y = [(1 + 1)*cosd(a)-cosd((1 + 1)*a); (1 + 1)*sind(a)-sind((1 + 1)*a)];
plot(a,y)
Steven Lord
Steven Lord on 18 Nov 2017
Based on your description the compass or quiver functions may be a better fit for your application than plot.

Sign in to comment.

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!