Question

given a row vector x create each of the following row vectors as indicated y is...

given a row vector x create each of the following row vectors as indicated
y is two copies of x, one after another (a vector twice as large as x, containing two copies)
z is a vector containing the elements of x with odd indices
w is identical to x, except it contains the number 0 inserted before the first element of x, a 7 inserted after the fourth element of x, and 12 inserted after the last element of x(thus, w is 3 elements larger than x)
how would i find the vecotors for these

x = randi([-9,9],1,8)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

It is inferred from the last line of question that this is asked in MATLAB

For making a new vector with two copies Use the following command

y=[x x]

we write our new elements inside [] to create a new vector.

For elements of x with odd indices use

z=x(1:2:end)

(for even do this x(2:2:end) )

Understand this notation x(a:b:c) this will return vector with elements of x indices from a to c with the step of b. Means if b=2 we will get every 2nd element if b=3 we will get every third element. If we don't specify anything like x(a:c) it will be like b=1 and will return all elements from indices a to c. end is used to specify to go till the last element.

w=[0 x(1:4) 7 x(5:end) 12]

A similar concept that was used to create y and z is used to create w. First, we started with element 0 and then added element of x from 1 to 4 than inserted 7. than added all remaining element of x using x(5:end) and finally 12 at the end.

MATLAB code:

x = randi([-9,9],1,8)
y=[x x]
z=x(1:2:end)
w=[0 x(1:4) 7 x(5:end) 12]

Add a comment
Know the answer?
Add Answer to:
given a row vector x create each of the following row vectors as indicated y is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT