MATLAB Create a column vector x with 17 equally spaced elements where the first
ID: 2074630 • Letter: M
Question
MATLAB
Create a column vector x with 17 equally spaced elements where the first element is 0 and the last element is 2pi. Create a second column vector y which is the same size as x and its elements are the sine of the elements of x. Display only the value of the 9th elements of both x and y. Solve this problem in the command window and copy and paste your solution from the command window to your hardcopy.
Using the colon operator, create a row vectors A = [4 7 10 13] and a column vector B = [14 12 10 8 6]’. Then only using the name of the vectors (A and B), create the following: a) A row vector C that is made from the elements of B followed by the elements of A. b) A column vector D that is made from the elements of A followed by the elements of B.
Explanation / Answer
w=linspace(0,2*pi,17);
%result comes out as row vector, so make it column vector
x=transpose(w)
y=sin(x);
%printing the value of nineth column
fprintf('x is %f ',x(9))
fprintf('y is %f',y(9))
%creating a row vector
A=[4 7 10 13];
%creating a column vector
B=[14;12;10;8];
%be sure to make the vectors look same before including those to another
%vector
C=[A transpose(B)]
D=[transpose(A);B]
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.