All these to be done in MATLAB:
1.1)Define a column vector, called “b” in MATLAB that stored floating point numbers between 0.6 to 2.5 in increment of 0.2.
1.2)What is the size of vector b? How is the size of ‘b’ stored? Define number of rows of ‘b’ in variable ’row’ and number of columns of “b” in variable “col”.
1.3)Define matrix “A” as a 10 by 10 matrix of all “1”s.
1.4)Update matrix “A” as following: set all the elements of column 1 as 0.5, column 3 as -1, column 6 as (sin(b/2))^2, column 7 as b+log10(b), row8 as pi+cos(b), leave the rest as is.
1.5)Define matrix “B” as B=A’. How are “A” and “B” related?
1.6)Compute matrix product of A and B and store it in D.
1.7)Define variable “f” such that it stores all values in 5th row of matrix “D”, between columns 3 and10.
1.8)What is the array product of column 6 of A by vector b?
1.9)Define a 5*5 identity matrix using eye function in MATLAB. What happens if eye(5,3) is executed?
1.10)Define a 5*5 and 5*4 matrix using zeros function in MATLAB.
Ans
code:-
%1.1)
b=[0.6:0.2:2.5]'
%1.2
[row,col]=size(b)
%1.3
A=ones(10)
%1.4
A(:,1)=0.5;
A(:,3)=-1;
A(:,6)=sin(b./2).^2;
A(:,7)=b+log10(b);
A(8,:)=pi+cos(b);
A
%1.5
B=A'
%B is transpose of A
%1.6
D=A*B
%1.7
f=D(5,3:10);
%1.8
A(:,6).*b
%1.9
%creates 5x5 identity matrix
eye(5)
eye(5,3)%create first 3 column of 5x5 identity matrix
%1.10
zeros(5)
zeros(5,4)
output:-
b=
0.6000
0.8000
1.0000
1.2000
1.4000
1.6000
1.8000
2.0000
2.2000
2.4000
row =
10
col =
1
A =
Columns 1 through 6
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
Columns 7 through 10
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
A =
Columns 1 through 3
0.5000 1.0000 -1.0000
0.5000 1.0000 -1.0000
0.5000 1.0000 -1.0000
0.5000 1.0000 -1.0000
0.5000 1.0000 -1.0000
0.5000 1.0000 -1.0000
0.5000 1.0000 -1.0000
3.9669 3.8383 3.6819
0.5000 1.0000 -1.0000
0.5000 1.0000 -1.0000
Columns 4 through 6
1.0000 1.0000 0.0873
1.0000 1.0000 0.1516
1.0000 1.0000 0.2298
1.0000 1.0000 0.3188
1.0000 1.0000 0.4150
1.0000 1.0000 0.5146
1.0000 1.0000 0.6136
3.5040 3.3116 3.1124
1.0000 1.0000 0.7943
1.0000 1.0000 0.8687
Columns 7 through 9
0.3782 1.0000 1.0000
0.7031 1.0000 1.0000
1.0000 1.0000 1.0000
1.2792 1.0000 1.0000
1.5461 1.0000 1.0000
1.8041 1.0000 1.0000
2.0553 1.0000 1.0000
2.9144 2.7254 2.5531
2.5424 1.0000 1.0000
2.7802 1.0000 1.0000
Column 10
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
2.4042
1.0000
1.0000
B =
Columns 1 through 3
0.5000 0.5000 0.5000
1.0000 1.0000 1.0000
-1.0000 -1.0000 -1.0000
1.0000 1.0000 1.0000
1.0000 1.0000 1.0000
0.0873 0.1516 0.2298
0.3782 0.7031 1.0000
1.0000 1.0000 1.0000
1.0000 1.0000 1.0000
1.0000 1.0000 1.0000
Columns 4 through 6
0.5000 0.5000 0.5000
1.0000 1.0000 1.0000
-1.0000 -1.0000 -1.0000
1.0000 1.0000 1.0000
1.0000 1.0000 1.0000
0.3188 0.4150 0.5146
1.2792 1.5461 1.8041
1.0000 1.0000 1.0000
1.0000 1.0000 1.0000
1.0000 1.0000 1.0000
Columns 7 through 9
0.5000 3.9669 0.5000
1.0000 3.8383 1.0000
-1.0000 3.6819 -1.0000
1.0000 3.5040 1.0000
1.0000 3.3116 1.0000
0.6136 3.1124 0.7943
2.0553 2.9144 2.5424
1.0000 2.7254 1.0000
1.0000 2.5531 1.0000
1.0000 2.4042 1.0000
Column 10
0.5000
1.0000
-1.0000
1.0000
1.0000
0.8687
2.7802
1.0000
1.0000
1.0000
D =
Columns 1 through 3
7.4006 7.5291 7.6482
7.5291 7.7673 7.9879
7.6482 7.9879 8.3028
7.7616 8.1977 8.6025
7.8709 8.4000 8.8915
7.9772 8.5965 9.1724
8.0808 8.7881 9.4463
18.0120 19.1592 20.2679
8.2808 9.1580 9.9750
8.3772 9.3365 10.2299
Columns 4 through 6
7.7616 7.8709 7.9772
8.1977 8.4000 8.5965
8.6025 8.8915 9.1724
8.9880 9.3601 9.7219
9.3601 9.8128 10.2530
9.7219 10.2530 10.7697
10.0747 10.6824 11.2737
21.3584 22.4358 23.4977
10.7554 11.5105 12.2456
11.0834 11.9091 12.7129
Columns 7 through 9
8.0808 18.0120 8.2808
8.7881 19.1592 9.1580
9.4463 20.2679 9.9750
10.0747 21.3584 10.7554
10.6824 22.4358 11.5105
11.2737 23.4977 12.2456
11.8507 24.5377 12.9627
24.5377 105.1767 26.5197
12.9627 26.5197 14.3447
13.4971 27.4445 15.0084
Column 10
8.3772
9.3365
10.2299
11.0834
11.9091
12.7129
13.4971
27.4445
15.0084
15.7342
ans =
0.0524
0.1213
0.2298
0.3826
0.5810
0.8234
1.1045
6.2248
1.7474
2.0849
ans =
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
ans =
1 0 0
0 1 0
0 0 1
0 0 0
0 0 0
ans =
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
ans =
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
If any doubt ask in the comments.
Get Answers For Free
Most questions answered within 1 hours.