0% found this document useful (0 votes)
29 views3 pages

Matlab Practice Set-1

This document provides examples of using MATLAB for: 1) Basic calculations, functions, vectors, matrices, and operations 2) Creating matrices using submatrices and applying commands like diag 3) Representing and solving systems of linear equations in matrix form

Uploaded by

Badri Tamang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views3 pages

Matlab Practice Set-1

This document provides examples of using MATLAB for: 1) Basic calculations, functions, vectors, matrices, and operations 2) Creating matrices using submatrices and applying commands like diag 3) Representing and solving systems of linear equations in matrix form

Uploaded by

Badri Tamang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

MATLAB Practice Set 1

MATLAB and Programming Environment


MPhil 2023
——————————————————————————————
1. Try the calculation operations and built-in-functions:

(a) Arithmetic Operations:


(i) 3+4 (b) 8/2 (c) 8\2 (e) 3∧ 3 (d) 1/2i
(b) Absolute value: abs(-0.5), abs(2+2*j)
Floor value: floor(4.5)
Ceiling value: ceil(4.4), ceil(4.7)
Square root: sqrt(2), sqrt(-2)
Real part: real(2+7j), real(2i)
Imaginary part: imag(5-4i), imag(4)
Signum function: sign(-3.2), sign(3.2), sign(0)
(c) The mathematical quantities ex , ln x and log x are calculated with exp(x),
log(x) and log 10(x) respectively.
Evaluate: e2 , ln eπ/5 , log(105 )

2. Trigonometry: The basic trigonometric functions are sin, cos, tan, cot, sec and
csc. The inverses e.g. arcsin, arctan etc are calculated with a sin, a tan etc. The
same is true for hyperbolic functions. The arguments of these functions must be
in radian. Calculate the following quantities.
π π π
(a) sin , cos , tan
6 4 2
2 π 2 π
(b) sin + cos (Typing sin2 (x) for sin2 x will produce an error. Correct form
6 6
is (sin(x))2 ).
(c) Use: sin( ); tan( ) for some input arguments.
(d) Try to understand the difference between sin( ) and sind( ) using some input
arguments.

3. Type vectors, and try to understand the output:

(a) Enter the vectors: A = [1 2 3 4 5 6 7]. Also enter the elements of A in column
form.

1
(b) Find length(A), max(A), min(A), norm(A), sort(A), std(A), sum(A), prod(A).

4. Create a vector t with 10 elements: 1, 2, · · · , 10. Now compute the following quan-
tities:
t−1 sin t2
x = t sin t, y = , z= 2
t+1 t
5. Type in matrices:

(a) Enter the matrix: A = [2 sqrt(2) 4; 0 1e − 1 3; −2.1 1.732 2]


(b) Find size(A), inv(A), det(A), norm(A)

6. Create a big matrix with submatrices: Enter the matrices.


" # " # " #
2 6 1 2 −5 5
A= ; B= ; C=
3 9 3 4 5 3

and then create a matrix G by putting matrices A, B and C given above, on its
diagonal. (You are not allowed to enter the non-zero numbers explicitly).
 
2 6 0 0 0 0
3 9 0 0 0 0
 
 
 
 0 0 1 2 0 0 
G= 

 0 0 3 4 0 0 

0 −5 5
 
 0 0 0 
0 0 0 0 5 3

7. Assume that array C is defined as shown, and determine the contents of the fol-
lowing sub-arrays:  
1 2 3 4
C= 0 −1 −3 7 
 

1.1 −2.1 5 0.1


(a) C(2, :) (b) C(:, end) (c) C(1:2, 2:end) (d) C(6) (e) C(4: end) (f) C(1:2, 2:4)
(g) C([1 3], 2) (h) C([2 2], [3 3]) (i) C([1 3], :) = C([3, 1], :)

8. Determine the contents of array a after the following statements are executed:

(a) >> a = [1 2 3;4 5 6;7 8 9]


>> a([3 1] , :) = a([1 3] , :)
(b) >> a = [1 2 3;4 5 6;7 8 9]
>> a([3 1] , :) = a([2 2] , :)

9. Determine the contents of array a after the following statements are executed.

2
(a) >> a = eye(3 , 3)
>> a(2 , :) = [ ]
(b) >> a = eye(3)
>> b = [4 5 6]
>> a(: , 3) = b0
(c) >> a = eye(3)
>> b = [7 8 9]
>> a(: , 3) = b([3 1 2])

10. Effects of diag command: Type the following commands


• >> B = [ones(3) zeros(3, 2); zeros(2, 3) 4 ∗ eye(2)]
•>> diag(B)0 , diag(B, 1), diag(B, −2)0

11. Application: Write the following system of linear equation 3x + y + z = 3; 2x −


3y −z = −3; x+2y +z = 4 in matrix form. Check whether the system is consistent
or not. If consistent then use MATLAB to find the solution of this system. [Helpful
built-in-functions: rank(A), and rank([A,b]) where A is the coefficient matrix and
[A,b] is the augmented matrix.]

——————————————————————————————————–

You might also like