7 9________________________________________________________
b) complete the Matlab command to replace the third column of the matrix 'B' with the values in
the vector [1; 0 ; -1; 0] .
>> B( _____:___, __3_________) =
121
450
7 8 -1
-1 -2 0___________________________
c) compute the following,
>> A = [ 7 8 9; 4 5 6; 1 2 3];
>> B = [ 6 , 6];
>> C = [ A(2:3,1:2) ; B]
C=
45
12
66
3. Compute the following,
>> A= eye(4,4);
>> B = zeros(4,4);
>> C = [ A , B ];
>> C( end , : )
ans =
______0 0 0 1 0 0 0 0 _______________________________
4. Write the values of v, w and x after entering the following sequence of Matlab commands.
>> v = [ 4 , 4 , 4 , 4];
>> w = cumsum(v)
____4 8 12 16________________________________
>> x = diff(w)
_______4 4 4_____________________________
5. Fill in the blanks to use the repmat function to create a row vector x of values [2 4 6 8 2 4 6
8 ...] (length(x) is 12, 4 sets of [2 4 6 8]).
>> x = repmat( ____2:2:8____________ , ___1______ , _____4______ ) '
0 0055
6. Below is a sequence of Matlab commands for creating the matrix K and then solving the
equation K * x = h where h = (1:5)'. In addition you will find the minimum value of the
solution (x).
Fill in the blanks with the appropriate statements and operators to create the above matrix
K:
>>a = 1:5;
>>b = 2:5;
Proceed to define the matrices:
>>C = diag(a,0);
>>D = diag(b,__1______);
>>E = diag(b,____-1____);
>>K = C _+___ D _+___ E;
Now solve the equation K * x = h
>> h = (1:5)' ;
>> x = ____K\h_____________________ ; (don't write the solution write the Matlab
expression that will give you the solution)
Check your solution,
>> K * x
ans =
___1.1277
-0.0638
-0.0426
0.8298
0.1702_________________________________________
>> find the minimum value of x and assign that value to a new variable minX using the min()
function;
minX= min(X); ( The Matlab expression that will give you the solution)
1 ;(the value of minX )
The matrix K you have just created is called a tri-diagonal matrix. Knowing how to use the 'diag'
function will be useful in your next lab and machine problem assignment.
1.3077
0.2692
-0.1538_____________________________________
8. Not all systems of linear equations have a solution. Try solving the system below using the
backslash operator:
- 2x + 3z = 6
- 2x + y + 3z =19
-3y + 6x - 9z = 6
What is the error message that Matlab displays?
_________Warning: Matrix is singular to working
precision._______________________________________________________________________
________________________________________________________
-K3-K2 K3
K3
0
0
H2 =
W2
-K4-K3 K4
H3 =
W3
K4
-K5-k4
K5
H4 =
W4
K5
-K5-K6 *
H5 =
W5-K6*HR
3. K = _____HF./d____________________________________________