MATLAB OUTPUT QUESTION a In the command window type xpi2 xpi
MATLAB OUTPUT QUESTION
a) In the command window, type “x=pi^2”, “x=pi*2” and “x=pi*2;”. What do the symbols “^”, “*“ and “;” do?
b) (10 pts) In the command window , type “A=[1 2 3 40]”, “B=[1;2;3;40]” and “C=[1,2,3,40]”. Which of these are the same and what is the difference with the other one? Also type “D=ones(4)” , “B*A”, “D.*(B*A)” and “D./(B*A)”. Explain the operations “.*” and “./” and the function “ones()”
c)(10 pts) In the command window, type “A=[-7:0.5:11]”, “B=[-7:1:11]”, ”C=[-7:11]”. Explain the effect of “:” and the values ”0.5” and “1”. Also, type and explain the functions “C(8)”, “sum(C)”, “length(C)”
Solution
> A=[1 2 3 40]
A =
1 2 3 40
> C=[1 2 3 40]
C =
1 2 3 40
B=[1;2;3;40]
B =
1
 2
 3
 40
A and C are same that is vector notaion or arry, When constructing an array, use a comma to separate elements that belong in the same row:
B is 3 cross 1 matrix. \";\" here semicolom use for change row
D=ones(4)
D =
1 1 1 1
 1 1 1 1
 1 1 1 1
 1 1 1 1
B*A
ans =
1 2 3 40
 2 4 6 80
 3 6 9 120
 40 80 120 1600
D.*(B*A)
ans =
1 2 3 40
 2 4 6 80
 3 6 9 120
 40 80 120 1600
D./(B*A)
ans =
1.0000 0.5000 0.3333 0.0250
 0.5000 0.2500 0.1667 0.0125
 0.3333 0.1667 0.1111 0.0083
 0.0250 0.0125 0.0083 0.0006
.* is Array multiplication operator.. .^ is Array exponentiation operator
ones(n) returns an n-by-n matrix of ones.
A=[-7:0.5:11]
A =
Columns 1 through 15
-7.0000 -6.5000 -6.0000 -5.5000 -5.0000 -4.5000 -4.0000 -3.5000 -3.0000 -2.5000 -2.0000 -1.5000 -1.0000 -0.5000 0
Columns 16 through 30
0.5000 1.0000 1.5000 2.0000 2.5000 3.0000 3.5000 4.0000 4.5000 5.0000 5.5000 6.0000 6.5000 7.0000 7.5000
Columns 31 through 37
8.0000 8.5000 9.0000 9.5000 10.0000 10.5000 11.0000
B=[-7:1:11]
B =
-7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11
C=[-7:11]
C =
-7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11
-7:0.5:11 means the length is 0.5 between -7 and nex numnber that means the difference is 0.5
-7:1:11 means length is 1 between -7 and next number that means the difference is 1
C(8)
ans =
0
>> sum(C)
ans =
38
>> length(C)
ans =
19
| : | Colon; is generates regularly spaced elements and represents an entire row or column. | 



