How to make a vector where each element=5 and 100 elements long?
Mostra commenti meno recenti
We have a given function: Y1 = 5 – (1/x).
Now (1) I have to use linspace to create an equidistant x-vector from 1 to 100 with 100 elements .
(2) Make a corresponding Y1 vector (use ‘./’ for element-wise division) using the x-vector and the formula for Y1.
(3) Make a corresponding Y2 vector (each element = 5 and 100 elements long ). [It was my main point of the question]
(4) In the same graph, plot Y1 and Y2 against x ! Make title, linecolors, axislabels, tics, grids etc to get a really nice figure. (To determine from the figure, approximately, from which x-value Y2 is a good approximation to Y1?)
Note: I solved them like this but I dont know if they are correct or not.
x=linspace(1,100,100);
y1=5-(1./x);
y2=linspace(1,5,100);
plot(x,y1);
hold on;
plot(x,y2);
hold off;
Risposta accettata
Più risposte (1)
Mahdi
il 30 Mag 2014
What you did produces a vector that starts at 1 and goes up by 5 till it reaches 100 elements. If that was your goal, then it's correct.
But if the question is asking to have a 100 elements which are all equal to 5:
y2=5.*ones((1,100)
Categorie
Scopri di più su Creating, Deleting, and Querying Graphics Objects in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!