1. Write MatLab commands for solving the following equations:
» roots(v)
ans =
0
-0.2713 + 0.6112i
-0.2713 - 0.6112i
0.2713 + 0.6112i
0.2713 - 0.6112i
» roots(v)
ans =
-1.2145 + 0.4488i
-1.2145 - 0.4488i
-0.6291 + 1.1229i
-0.6291 - 1.1229i
0.2410 + 1.2511i
0.2410 - 1.2511i
0.9749 + 0.7999i
0.9749 - 0.7999i
1.2554
» b=[9;20;-2];
» A\b
ans =
2.2897
-1.8138
1.6000
» b=[5;11;39];
» A\b
ans =
-0.0833
5.9167
-0.7500
2. Write Matlab commands for evaluating the following expressions:
x =
0.9172
» y=abs(x)*sin(x+pi*i/5)
y =
0.8766 + 0.3739i
» z=exp(-x-i*y)-sqrt(x^2+y^4)
z =
-0.6183 - 0.8628i
» w=log10(x+y+z)
w =
0.1049 - 0.1712i
3. Doubly stochastic matrix is a matrix whose row and column sums are all one. Use Matlab to do the following.
M =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
» sum(M(1,:)) %magic sum
ans =
65
» P=M/65
P =
0.2615 0.3692 0.0154 0.1231 0.2308
0.3538 0.0769 0.1077 0.2154 0.2462
0.0615 0.0923 0.2000 0.3077 0.3385
0.1538 0.1846 0.2923 0.3231 0.0462
0.1692 0.2769 0.3846 0.0308 0.1385
» sum(P) %check the sum over elements in each column
ans =
1 1 1 1 1
» sum(P') %check the sum over elements in each row
ans =
1 1 1 1 1
» Q=P^8
Q =
0.2001 0.2000 0.2000 0.1999 0.2000
0.2000 0.2000 0.2000 0.2000 0.2000
0.1999 0.2000 0.2001 0.2000 0.1999
0.2000 0.2000 0.2000 0.2000 0.2000
0.2000 0.1999 0.2000 0.2000 0.2001
» sum(Q)
ans =
1.0000 1.0000 1.0000 1.0000 1.0000
» sum(Q')
ans =
1.0000 1.0000 1.0000 1.0000 1.0000
4. Construct the following matrix in Matlab
» M=[2:3:20;4:6:40;6:9:60;8:12:80;10:15:100]
M =
2 5 8 11 14 17 20
4 10 16 22 28 34 40
6 15 24 33 42 51 60
8 20 32 44 56 68 80
10 25 40 55 70 85 100