218k views
3 votes
Construct a row array plotPoints with 5 values that are spaced linearly from lowValue to highValue. Hint: Use the linspace function.

2 Answers

5 votes

Answer:

plotPoints = linspace(lowValue, highValue, 5);

Step-by-step explanation:

linspace evenly distributes the values for you, so as long as you specify the starting point (lowValue), the ending point (highValue), and the number of entries including the starting and ending number (5), it will do the work for you.

Final answer is plotPoints = linspace(lowValue, highValue, 5);

(This is much simpler than what the last user answered, and your MATLAB homework will accept this answer.)

User Pagliuca
by
7.5k points
3 votes

Answer:

linspace(lowValue, highValue, (highValue-lowValue)/4).

Step-by-step explanation:

The linspace command is a MATLAB command to create a row array.

For example:

linspace(-2,2,1) creates the following row vector:

{-2,-1,0,1,2}

The first argument is the lowValue, the second argument is the highValue, and the third argument is the distance between each element of the vector.

linspace(0,30,5) creates the following row vector.

{0,5,10,15,20,25,30}

If a want a vector of 5 values in this interval, we do

linspace(0,30,(30-0)/4) creates the following row vector. The vector is

{0,7.5,15,22.5,30}

For n values between lowValue and highValue, we use

linspace(lowValue, highValue, (highValue-lowValue)/(n-1))

In this problem, we have that

5 values that are spaced linearly from lowValue to highValue. So

linspace(lowValue, highValue, (highValue-lowValue)/4).

User Nicholas Siegmundt
by
6.9k points