0% found this document useful (0 votes)
3 views

F.Y.B.cs Lab Course on 24CsMatU2201

The document provides an introduction to Scilab, a free open-source software for scientific computing, highlighting its capabilities in numerical problem-solving and its applications in education and industry. It includes a comprehensive list of commands for matrix operations, polynomial definitions, and function definitions, along with practical exercises for students. The document serves as a lab course guide for F.Y.B.Sc. Computer Science students at Modern College of Arts, Science and Commerce.
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)
3 views

F.Y.B.cs Lab Course on 24CsMatU2201

The document provides an introduction to Scilab, a free open-source software for scientific computing, highlighting its capabilities in numerical problem-solving and its applications in education and industry. It includes a comprehensive list of commands for matrix operations, polynomial definitions, and function definitions, along with practical exercises for students. The document serves as a lab course guide for F.Y.B.Sc. Computer Science students at Modern College of Arts, Science and Commerce.
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/ 18

Progressive Education Society’s

Modern College of Arts, Science and Commerce (Autonomous),

Shivajinagar, Pune - 5

F.Y.B.Sc.(Computer Science)(NEP 24)

Mathematics Department

Lab course on 24CsMatU2201

Practical 1:Indroduction to Scilab

INTRODUCTION

Scilab is a high level free open source software package for scientific computing. It is an enjoyable way to solve problems

numerically. It has a number of general purpose and specialized functions for numerical computation. The computational

problems can be solved much more quickly using Scilab than with the standard programming languages such as C, java,

ETC. Scilab is one of the alternatives to commercial packages for dynamical system modeling simulation packages such

as MATLAB / simulink / MATRIX X / system build etc. Scilab has strong Toolboxes. The Toolboxes contain functions

that are used in the areas such as simulation, optimization, system and control, signal processing etc. Scilab is widely used

in Universities and engineering schools. It is also gaining ground in industrial environments. Scilab is continuously being

developed since 2004.

Scilab includes a full users manual. One can go through it by clicking Help Browser Menu at consol. Scilab is available

on main platforms like Unix/Linux workstations and windows. It is easy to general some results , draw graphs and then

explore the problem further using Scilab. By minimizing human time, it is particularly used in the initial investigation of

real problems. In Scilab algorithms are available for the numerical solution of differential equations, optimization problems,

interpolation and quadrature. Scilab also provides two and three dimensional graphs which can be readily incorporated

into reports and publications. So because of all this attributes Scilab can be used as a basic package for computational

purposes. In fact, simple user interfaces can be built using Scilab. So the best way to use this booklet is to sit down at

the computer and type in commands as they are described. Look at Scilabs response and check the answers as what you

expect.

LIST OF COMMANDS IN SCILAB

Starting Scilab: One can download the latest version of Scilab from the site: http://www.scilab.org. After downloading

Scilab, by double clicking the icon of Scilab start. Scilab provides an environment which uses matrices as its basic data

type. Following is the list of basic commands in Linear Algebra and Numerical Analysis:

1. A = [1065; −41] defines a matrix A of order 3 × 2

2. A0 : displays the transpose of matrix A

3. A\b: computes the matrix A−1 ∗ b.

1
4. inv(A): gives inverse of a matrix A.

5. det(A) : gives determinant of a matrix A.

6. diag(A) : displays diagonal of a matrix A.

7. trace(A) : displays addition of diagonal elements of a matrix A.

8. [A, B] : displays an augmented matrix A|B.

9. size(A) : displays the number of rows and columns of matrix A.

10. length(A) : displays total number of elements of matrix A.

11. rref (A) : displays the reduced row echelon form of matrix A.

12. spec(A) : displays eigenvalues of a square matrix A.

13. linsolve(A, b) : gives the solution of the system of linear equations AX + b = 0

14. [P, D] = spec(A) : displays eigenvalues (D) and eigenvectors (P) of a matrix A

15. [L, U ]= lu(A) produces two matrices L and U such that A = L ∗ U with U upper triangular and L a general matrix

without any particular structure.

16. A(i, j) : displays (i,j)th element of matrix A.

17. A(i, :): displays ith row of matrix A.

18. A(:,j) : displays the jth column of matrix A.

19. size(A,1) : displays number of rows of matrix A.

20. size(A,2) : displays number of columns of matrix A.

21. A + B, A − B, A ∗ B are the usual operations on matrices A and B.

22. Special types of matrices :

eye(m,m) : identity matrix of order m × m.

zeros(m,n) : zero matrix of order m × n.

ones(m,n) : matrix with all entries 1 of order m × n.

rand(m,n) : random matrix of order m × n with entries between 0 and 1.

int(k*rand(m,n)) : random matrix of order m × n with integer entries between 0 and k

23. Special symbols :%pi, %e, %i.

24. Logical operators : : Negation,| : Disjunction,& : conjuction.

25. Relational operators :

2
26. General commands:

pwd : print current directory of Scilab

getcwd : get the current directory of Scilab.

clc : clear command window.

help : online help.

clean : cleans the matrix entries which are (approximately) very near to zero.

diary(f) : diary(’c : \temp\test.sci’)

opens a Scilab file (*.sci) to store console commands.

diary(0) : closes the file f *sci.

27. Commands to define function:

deff(’[s1, s2, ] = newfunction(e1, e2, ..) ’,text[,opt])

e.g deff (’z = f (x, y)0 ,0 z = x + 3y − 2’)

28. poly([a],’variablename’,’flag’) : defines a polynomial with row matrix [a] whose elements are coefficients or roots of

polynomial.

e.g a) poly([1 2 -1],’x’,’coeff’) gives 1 + 2x − x2 as the output.

b) poly([-2 -3],’y’,’roots’) or poly([- 2 -3],’y’) gives 6 + 5y + y 2 as the output.

c) poly(A,’name’) : displays characteristic polynomial of matrix A.name is the variable of the polynomial.

29. roots(p) : displays all roots of the polynomial p.

30. Input output commands:

disp(’ ’) : To display.

printf(’ ’) :prints the content on the screen

printf(’value of function at %.4f is %.4f ’,x, y)

input(’ ’): x=input(’Enter the values of x as :’)

3
Progressive Education Society’s

Modern College of Arts, Science and Commerce (Autonomous),

Shivajinagar, Pune - 5

F.Y.B.Sc.(Computer Science)(NEP 24)

Mathematics Department

Lab course on 24CsMatU2201

Practical 2:Learning of Scilab commands

1. Declare the following matrices.


   
  e 1 π 1 log 3 1 −3 −1 3
  4 3 3     
   
 −1 0    1 0 1 1  1 2  1 3
sin 30 1.5   6  4 −4.5 

   
, 0 , , , ,

 2 1
  
2 3    0 1 0 0  7 1 8 −1   −3  5 2 −3 0
  
4 2 −1    
1 1 0 0 1 −4 3 6 0

2. Compute
 A2 , B 2 , AB,
 BA 
 1 6 0   1 0 −2 
   
A= 3 7 2 ,B =  0
  4 3 

   
9 −5 1 0 0 1

3. Generate random matrix, zero matrix, matrix with all entries 1, random matrix with integer entries between 0 to 9

of order 2 × 3, 4 × 3

4. Generate identity matrix of order 3 × 3,4 × 4.

5. Declare
 the following matrices
 
 −2 1 8   0 3 0 
   
A=  3 0 2  ,B =  −5
 1 1 

   
4 −6 3 7 6 2

(a) 2(A + 5B)

(b) 7B − 3A

(c) trace of (A − B)

(d) diagonal of A ∗ B

(e) (AB)T

6. Define the following polynomials using scilab

(a) 5x2 + 2x − 3

(b) 2 + 3x − x2

(c) Whose roots are 1, 2, 3

4
√ √
(d) Whose roots are 1 + i 2, 1 − i 2
1 1
(e) Whose roots are , , −1
2 3

7. Find roots of following polynomials using Scilab

(a) 2x2 − 2x + 3
1 3
(b) x + x2 − 1
2

8. Using command ’deff’ define following function

(a) y = e2x + x5

(b) y = sin x − 2.5 cos 3x

(c) y = log x + cos x


1 3
(d) y = t + t2 − 1
2
(e) f (x, y) = x3 + cos y

(f) f (x, y) = −x + y − 2xy 2

(g) f (x, y) = e−1.5x + sin 3y

9. Define following functions in

(a) f (x) = x4 + 3x − 5

(b) Z = x3 + y 2

(c) Z = sin(x2 + y 2 )

(d) Z = exp(x2 + 4y), 0 ≤ x ≤ 1, 0 ≤ y ≤ 1

(e) f (x) = x + 3, x > 2

= x, 0≤x≤2

= x − 5, x < 0

5
Progressive Education Society’s

Modern College of Arts, Science and Commerce (Autonomous),

Shivajinagar, Pune - 5

F.Y.B.Sc.(Computer Science)(NEP 24)

Mathematics Department

Lab course on 24CsMatU2201

Practical 3: Equivalence Relations

1. Let A = {1, 2, 3, 4}. Determine whether the relation is reflexive, symmetric or transitive

(a) R = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 3), (3, 4), (4, 3), (4, 4)}

(b) R = {(1, 3), (1, 1), (3, 1), (1, 2), (3, 3), (4, 4)}

(c) R = φ

(d) R = {(1, 2), (1, 3), (3, 1), (1, 1), (3, 3), (3, 2), (1, 4), (4, 2), (3, 4)}
 
0 1 0 1
 
 
 1 0 1 1 
(e) MR = 
 

 0 1 0 0 
 
 
1 1 0 0
 
1 1 0 0
 
 
 1 1 0 0 
(f) MR = 
 

 0 0 1 0 
 
 
0 0 0 1

2. Determine whether the relation R on the set A is reflexive, symmetric or transitive

(a) A = Z; aRb if and only if a < b + 1.

(b) A = Z; aRb if and only if |a − b| = 2


+
(c) A = Z ; aRb if and only if GCD(a, b) = 1
+ +
(d) A = Z , aRb iff a = bk for some k ∈ Z .

3. Define a relation on the set {a, b, c, d} that is

(a) reflexive and symmetric, but not transitive

(b) reflexive and transitive, but not symmetric

(c) symmetric but neither transitive nor reflexive

(d) transitive but neither reflexive nor symmetric

6
4. Determine whether the relation R on the set A is an equivalence relation.

(a) A = {1, 2, 3, 4, 5}, R = {(1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (3, 1), (2, 3), (3, 3), (4, 4), (3, 2), (5, 5)}

(b) Let A be the set of all straight lines in a plane. Let R be a relation defined on A such that for L1 , L2 ∈ A,

L1 RL2 if and only if L1 ||L2 .

(c) A = Z, R = {(a, b)| 2 divides a − b}

5. Let R be a relation on Z defined as 0 xRy if and only if 6x + 7y is divisible by 13’. Show that R is an equivalence
relation on Z.

6. Let A be the set of points in the plane. Let R be the relation on A such that (a, b) R (a1 , b1 ) if and only if

a2 + b2 = a21 + b21 . Show that R is an equivalence relation on A and describe equivalence classes geometrically.

7
Progressive Education Society’s

Modern College of Arts, Science and Commerce (Autonomous),

Shivajinagar, Pune - 5

F.Y.B.Sc.(Computer Science)(NEP 24)

Mathematics Department

Lab course on 24CsMatU2201

Practical 4: Warshall’s Algorithm

1. Using Warshall’s algorithm, obtain transitive closure of relation R = {(1, 2), (2, 2), (2, 4), (3, 2), (3, 4), (4, 1)} on the

set A = {1, 2, 3, 4}.

2. Let A = {a, b, c, d} be any set and R be a relation defined on A as, R = {(a, a), (a, c), (b, a), (b, b), (c, b), (c, c), (d, d), (d, c)}.

Obtain transitive closure of R using Warshall’s Algorithm.

3. Let A = {1, 2, 3, 4, 5} and R = {(1, 1), (1, 4), (2, 2), (3, 4), (3, 5), (4, 1), (5, 2), (5, 5)} be a relation on A. Find transitive

closure of R. Also find diagraph of transitive closure of R.

4. The diagraph of a relation R on {a, b, c, d} is given below. Find the transitive closure of R.

a b

d c

5. Let A = {1, 2, 3, 4}. For the relation R whose matrix is given, find the matrix of the transitive closure by using

Warshall’s
 algorithm. 
1 0 0 1
 
 
 0 1 1 0 
MR = 
 

 0 1 1 0 
 
 
1 0 0 1
Progressive Education Society’s

Modern College of Arts, Science and Commerce (Autonomous),

Shivajinagar, Pune - 5

F.Y.B.Sc.(Computer Science)(NEP 24)

Mathematics Department

Lab course on 24CsMatU2201

Practical 5: Partial order relations

1. Which of these relations on {0, 1, 2, 3} are partial ordering?

(a) {(0, 0), (1, 1), (2, 2), (3, 3)}

(b) {(0, 0), (1, 1), (2, 0), (2, 2), (2, 3), (3, 2), (3, 3)}

(c) {(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 2), (3, 3)}

2. Determine whether the relation R is a partial order on the A.

(a) A = Z and if and only if a = 2b.

(b) A = Z and if and only if b2 |a.


+
(c) A = Z and if and only if a = bk for some k ∈ Z .

(d) A = R and if and only if a < b.

3. Let X any set and A = P (X), a power set of X. For a, b ∈ A define a relation R as follows: aRb if and only if a ⊆ b.

Show that R is a partial ordering on A.

+
4. Let A = Z . For a, b ∈ A define a relation R as follows: aRb if and only if a|b. Show that R is a partial ordering on

A.

9
Progressive Education Society’s

Modern College of Arts, Science and Commerce (Autonomous),

Shivajinagar, Pune - 5

F.Y.B.Sc.(Computer Science)(NEP 24)

Mathematics Department

Lab course on 24CsMatU2201

Practical 6,7

Practical 6: Evaluation of determinants of matrices


 
4 −1 1 6
 
 
 0 0 −3 3 
1. Let A =  . Find
 
 4 1 0 14 
 
 
4 1 3 2

(a) M11 and C11

(b) M32 and C32

(c) M12 and C12

(d) M43 and C43

a b c
2. Evaluate the determinant, given that d e f = −6

g h i

d e f
(a) a b c

g h i

a b c
(b) d e f

−3g −3h −3i

−a −b −c
(c) 2d 2e 2f

5g 5h 5i

3g 3h 3i
(d) 2a + d 2b + e 2c + f

d e f

10
3. Evaluate the determinant of the following matrices by cofactor expansion method
 
 −2 0 5 
 
(a) A = 
 3 −4 2 

 
1 0 7
 
 3 1 0 
 
(b) B = 
 −2 −4 3 

 
5 4 −2
 
−1 −1 −1 −1
 
 
 0 2 −2 −2 
(c) C = 
 

 0 0 7 −3 
 
 
0 0 0 −4
 
2 2 1 0
 
 
 −1 0 3 0 
(d) D = 
 

 4 9 3 1 
 
 
0 −1 5 7

4. Decide whether the given matrix is invertible, and if so, use the adjoint method to find its inverse
 
 −2 4 3 
 
(a) A = 
 1 2 0 

 
2 −1 −2
 
 2 0 −3 
 
(b) A =  0 −3 2 


 
−1 0 2

5. Evaluate the determinant of the given matrix by using row reduction.


 
 0 1 5 
 
(a) A = 
 3 −6 9 

 
2 6 1
 
3 5 −2 6
 
 
 1 2 −1 1 
(b) B = 
 

 2 4 1 5 
 
 
3 7 5 3
 
0 1 1 1
 
 1 1 1 
 1 
(c) C =  22 2 2 

1 1 
 0 
 3 3 3
 
1 2

− 0 0
3 3

11
6. Use Cramer’s rule to solve

(a) 5x1 + 3x2 = −2

4x1 − x2 = −5

(b) x1 + + 2x3 = 6

−3x1 + 4x2 + 6x3 = 30

− x1 − 2x2 + 3x3 = 8

(c) x + 2y − 3z = −4

4x − y + 2z = 8

2x + 2y − 3z = −3

Practical 7: By Appling Scilab commands solve questions of practical 6

12
Progressive Education Society’s

Modern College of Arts, Science and Commerce (Autonomous),

Shivajinagar, Pune - 5

F.Y.B.Sc.(Computer Science)(NEP 24)

Mathematics Department

Lab course on 24CsMatU2201

Practical 8,9

Practical 8: Gaussian elimination method

1. Find a system of linear equations corresponding to the given augmented matrix.


 
 2 5 6 
 
(a) A =  0 1 2 


 
−1 0 0
 
 3 0 −2 5 
 
(b) B =  7 1
 4 −3  
 
0 −2 1 7
 
1 3 5 7
 
 
 −7 −5 −3 −1 
(c) C = 
 

 −5 6 −1 −1 
 
 
8 0 0 −2

2. Solve the following linear system by Gaussian elimination, Gaussian Jordan .

(a) x + y + 2z = 9

2x + 4y − 3z = 1

3x + 6y − 5z = 0

(b) x − y + 2z = 5

2x − 2y + 4z = 10

3x − 3y + 6z = 15

(c) x1 + 2x2 − 3x3 = 6

2x1 − x2 + 4x3 = 1

x1 − x2 + x3 = 3

(d) 2x1 + 2x2 + 2x3 = 4

−2x1 + 5x2 + 2x3 = 1

8x1 + x2 + 4x3 = 11

13
(e) 3x − y + z + 7w = 13

−2x + y − z − 3w = −9

−2x + y − 7w = −8

(f) − 2y + 3x = 3

3x + 6y − 3z = −2

6x + 6y + 3z = 4

(g) 2x + y + 4z = 0

3x + y + 6z = 0

4x + y + 9z = 0

(h) v − 2w + 2x = 0

2u − v + 4w − 3x = 0

4u − v + 6w − 4x = 0

−2u + 2v − 6w + 5x = 0

3. Determine the values of λ for which the system has no solutions, exactly one solution, or infinitely many solutions.

(a) x + 2y + z = 2

2x − 2y + 3z = 1

x + 2y − λz = λ

(b) x + 2y + z = 2

2x − 2y + 3z = 1

x + 2y − (λ2 − 3)z = λ

Practical 9: By Appling Scilab commands solve question 2 of practical 8

14
Progressive Education Society’s

Modern College of Arts, Science and Commerce (Autonomous),

Shivajinagar, Pune - 5

F.Y.B.Sc.(Computer Science)(NEP 24)

Mathematics Department

Lab course on 24CsMatU2201

Practical 10,11

Practical 10: Gauss-Jordan Elimination method

Solve question 2 of practical 8 using Gauss-jordan elimination method

Practical 11: By Appling Scilab commands solve practical 10

15
Progressive Education Society’s

Modern College of Arts, Science and Commerce (Autonomous),

Shivajinagar, Pune - 5

F.Y.B.Sc.(Computer Science)(NEP 24)

Mathematics Department

Lab course on 24CsMatU2201

Practical 12,13: LU decomposition method

Practical 12: LU decomposition method

1. Find the LU factorization of the matrices given below.


 
 2 5 
(a) A =  
−3 −4
 
 3 −6 3 
 
(b) B =  6 −7 2 


 
−1 7 0
 
1 4 −1 5
 
 
 3 7 −2 9 
(c) C = 
 

 −2 −3 1 −4 
 
 
−1 6 −1 7
 
2 4 −1 5 −2
 
 
 −4 −5 3 −8 1 
(d) D = 
 

 2 −5 −4 1 8 
 
 
−6 0 7 −3 1

2. Solve the equation AX = b by LU factorization.


   
 3 −7 −2   −7 
   
(a) A =  −3 5
 1 ,b =  5 
 

   
6 −4 0 2
   
1 −2 −4 −3 1
   
   
 2 −7 −7 −6   7 
(b) A =  ,b = 
   

 −2 2 6 4   0 
   
   
−4 −1 9 8 3
 
  −9
 3 −7 −2 2 
 
 
 5 
   
(c) A =  −3 5
 1 0 ,b = 
 
 7 
   
6 −4 0 −5  
11

16
Practical 13: By Appling Scilab commands solve practical 12

17
Progressive Education Society’s

Modern College of Arts, Science and Commerce (Autonomous),

Shivajinagar, Pune - 5

F.Y.B.Sc.(Computer Science)(NEP 24)

Mathematics Department

Lab course on 24CsMatU2201

Practical 14,15: Eigenvalues and eigenvectors

Practical 14: Eigenvalues and eigenvectors

1. Find the characteristic equations, eigenvalues and eigenvector of the following matrices:
 
2 −1
(a) 
 

10 −9
 
 5 1 3 
 
(b) 
 0 −1 0 

 
0 1 2
 
 0 0 −2 
 
(c)  1 2 1 


 
1 0 3
 
 0 6 12 
 
(d)  0 3 10 


 
0 0 −2
 
 −2 0 1 
 
(e)  −6 −2 0 


 
19 5 −4
 
 5 6 2 
 
(f)  0 −1 −8 


 
1 0 −2

Practical 15: By Appling Scilab commands solve practical 14

18

You might also like