Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 22

Shri Vaishnav Vidyapeeth Vishwavidyalaya

Shri Vaishnav Institute of Information Technology

Lab File
IT Workshop -Scilab/MATLAB (BTCS 608)

Submitted to: Submitted by:


Prof. Richa Jain Piyush Mali
(19100BTIT06588)
IT Workshop -Scilab/MATLAB (BTCS 608) Piyush Mali (19100BTIT06588)

INDEX
S/N OBJECTIVE PAGE Remarks/Sign
NO.
01 Addition, subtraction and multiplication of 4
two matrices.
02 Verify whether the given matrix is singular 5
or non-singular and compute its inverse if
applicable.
03 Sorting of 1-D array and searching of an 6-7
array/matrix. Also, list the set of numbers
that obey a common condition in an
array/matrix using find( ).
04 Solve simultaneous equations (maximum 8-9
of three) using Cramer ‘s rule.
[Simultaneous equations may be obtained
by applying KCL or KVL for a circuit and
they can be solved for voltages or currents,
respectively]
05 a) Show that log10(A*B) =log10 A+ log10 B 9-10
and log10(A/B) =log10 A-log10 B

b) Plot the voltage across capacitor during


charging Vc=V0[1-e-(t/RC)]
06 Plot a straight line for the given slope and 11
intercept using different plot attributes.
07 Plot y1=A*sin(2πf1t), y2=B*cos(2πf2t) and 13-15
y3=A*sin(2πf1t)+B*cos(2πf2t), in time and
frequency (after computing DFT or FFT)
domains as subplots and infer the results.
08 Integrate and differentiate sin(x) and 16
display the results on the same plot in
different colors. Also display sin(x) on the
same plot.

pg. 2
IT Workshop -Scilab/MATLAB (BTCS 608) Piyush Mali (19100BTIT06588)

09 Compute mean, median, standard deviation 17


and variance of a set of data using built-in
functions.
10 Find all the even and prime numbers 18
between two numbers (range).
11 Demonstrate (a) reading and display 19-21
image, (b) converting color image to gray
and black-and-white and plotting their
histograms, and (c) conversion of image
file formats.
12 Write a program to compute roots of a 22
quadratic equation ax +bx+c=0 given a, b
2

and c.

pg. 3
IT Workshop -Scilab/MATLAB (BTCS 608) Piyush Mali (19100BTIT06588)

Experiment No. 01
Aim: Addition, subtraction and multiplication of two matrices.
You can add or subtract or multiplication matrices by using (+, -, *) operator. The operand
matrices must have the same number of rows and columns.

pg. 4
IT Workshop -Scilab/MATLAB (BTCS 608) Piyush Mali (19100BTIT06588)

Experiment No. 02
Aim: Verify whether the given matrix is singular or non-singular and compute its inverse if
applicable.
A matrix is said to be singular if the determinant of the matrix is 0 otherwise it is non-
singular. A singular matrix does not have an inverse. A matrix X is invertible if there exists a
matrix Y of the same size such that XY=YX=In, where in is the n-by-n identity matrix. The
matrix Y is called the inverse of X.
Syntax:
 d = det(A) returns the determinant of square matrix A.
 Y = inv(X) computes the inverse of square matrix X.
X^(-1) is equivalent to inv(X).
x = A\b is computed differently than x = inv(A)*b and is recommended for solving
systems of linear equations.

pg. 5
IT Workshop -Scilab/MATLAB (BTCS 608) Piyush Mali (19100BTIT06588)

Experiment No. 03
Aim: Sorting of 1-D array and searching of an array/matrix. Also, list the set of numbers
that obey a common condition in an array/matrix using find( ).
Create a row vector and sort its elements in ascending order. And if you want to search any
element of array/matrix then, you can use the “find” function to return the positions
corresponding to an array element value.
For list the set of numbers that obey a common condition in an array/matrix using find( ).
Some problems require information about the locations of the array elements that meet a
condition rather than their actual values. In this example, you can use the find function to
locate all of the elements in A less than 9.

pg. 6
IT Workshop -Scilab/MATLAB (BTCS 608) Piyush Mali (19100BTIT06588)

Experiment No. 04
pg. 7
IT Workshop -Scilab/MATLAB (BTCS 608) Piyush Mali (19100BTIT06588)

Aim: Solve simultaneous equations (maximum of three) using Cramer ‘s rule.


[Simultaneous equations may be obtained by applying KCL or KVL for a circuit and they
can be solved for voltages or currents, respectively].
Cramer’s Rule will give us the unique solution to a system of equations, if it exists. However,
if the system has no solution or an infinite number of solutions, this will be indicated by a
determinant of zero. To find out if the system is inconsistent or dependent, another
method, such as elimination, will have to be used.

To understand Cramer’s Rule, let’s look closely at how we solve systems of linear equations
using basic row operations. Consider a system of two equations in three variables.

2x + y + z = 3
x–y–z=0
x + 2y + z = 0

pg. 8
IT Workshop -Scilab/MATLAB (BTCS 608) Piyush Mali (19100BTIT06588)

pg. 9
IT Workshop -Scilab/MATLAB (BTCS 608) Piyush Mali (19100BTIT06588)

Experiment No. 05
a) Show that log10(A*B) =log10 A+ log10 B and log10(A/B) =log10 A-log10 B
Syntax:
Y = log(X)
Y = log(X) returns the natural logarithm ln(x) of each element in array X.
The log function’s domain includes negative and complex numbers, which can lead to
unexpected results if used unintentionally. For negative and complex numbers z = u + i*w,
the complex logarithm log(z) returns
log(abs(z)) + 1i*angle(z)
For given logarithmic identities: log10(A*B) =log10 A+ log10 B

For given logarithmic identities: log10(A/B) =log10 A-log10 B

pg. 10
IT Workshop -Scilab/MATLAB (BTCS 608) Piyush Mali (19100BTIT06588)

b) Plot the voltage across capacitor during charging Vc=V0[1-e-(t/RC)]


The following examples illustrate the use of MATLAB for solving problems related to RC
circuits. Assume that for the charging RC circuit above Vs = 10 volts and C = 10 microfarads.
Plot the voltage across the capacitor if R equals 5k ohm, 10k ohms and 20k ohms. This just
means that we are going to explore three-time constants.

From the resulting plot of our transient analysis, we see that if the time constant is small, it
takes a shorter time for the capacitor to charge up (the smaller the time constant the faster
the circuit response). We also can see that when the time constant is reached by each
response, we have obtained more or less the 63% of the total voltage to be taken (that’s
why the RC value is called the time constant).

pg. 11
IT Workshop -Scilab/MATLAB (BTCS 608) Piyush Mali (19100BTIT06588)

Experiment No. 06
Aim: Plot a straight line for the given slope and intercept using different plot attributes.

pg. 12
IT Workshop -Scilab/MATLAB (BTCS 608) Piyush Mali (19100BTIT06588)

Experiment No. 07
Aim: Plot y1=A*sin(2πf1t), y2=B*cos(2πf2t) and y3=A*sin(2πf1t)+B*cos(2πf2t), in time and
frequency (after computing DFT or FFT) domains as subplots and infer the results.
For Example: Add two sine waves of 30 and 60 hz having sampling frequency of 1khz.
A) y1=A*sin(2πf1t)

pg. 13
IT Workshop -Scilab/MATLAB (BTCS 608) Piyush Mali (19100BTIT06588)

B) y2=B*cos(2πf2t)

pg. 14
IT Workshop -Scilab/MATLAB (BTCS 608) Piyush Mali (19100BTIT06588)

C) y3=A*sin(2πf1t)+B*cos(2πf2t)

pg. 15
IT Workshop -Scilab/MATLAB (BTCS 608) Piyush Mali (19100BTIT06588)

Experiment No. 08
Aim: Integrate and differentiate sin(x) and display the results on the same plot in different
colors. Also display sin(x) on the same plot.

pg. 16
IT Workshop -Scilab/MATLAB (BTCS 608) Piyush Mali (19100BTIT06588)

Experiment No. 09
Aim: Compute mean, median, standard deviation and variance of a set of data using built-
in functions.

 Mean is also known as average of all the numbers in the data set which is calculated by
below equation. In MATLAB, mean() function is used.
 Median is mid value in this ordered data set. In MATLAB, median() function is used.
 Standard Deviation: It is a measure of dispersion of observation within dataset relative
to their mean. It is square root of the variance and denoted by Sigma (σ) . Standard
deviation is expressed in the same unit as the values in the dataset so it measure how
much observations of the data set differs from its mean. In MATLAB, std() function is
used.
 Variance is the numerical values that describe the variability of the observations from its
arithmetic mean and denoted by sigma-squared (σ2). Variance measure how far
individuals in the group are spread out, in the set of data from the mean. In MATLAB,
var() function is used.

pg. 17
IT Workshop -Scilab/MATLAB (BTCS 608) Piyush Mali (19100BTIT06588)

Experiment No. 10
Aim: Find all the even and prime numbers between two numbers (range).
Even Numbers Program:

Prime Numbers Program:

pg. 18
IT Workshop -Scilab/MATLAB (BTCS 608) Piyush Mali (19100BTIT06588)

Experiment No. 11
Demonstrate:
(a) reading and display image-
 Read a sample RGB image ‘Blue Eye Dog’ by imread().

 Display the RGB image using imshow(). imshow() uses the default display range for the
image data type and optimizes figure, axes, and image object properties for image
display.

(b) converting color image to gray and black-and-white and plotting their histograms-
 Convert the RGB image to a grayscale image by using the rgb2gray function. Display the
grayscale image using imshow.

 Histogram for an image using the imhist() function. An image histogram is a chart that
shows the distribution of intensities in an indexed or grayscale image. The imhist()
function creates a histogram plot by defining n equally spaced bins, each representing a
range of data values, and then calculating the number of pixels within each range. You
can use the information in a histogram to choose an appropriate enhancement
operation. For example, if an image histogram shows that the range of intensity values is
small, you can use an intensity adjustment function to spread the values across a wider
range.

pg. 19
IT Workshop -Scilab/MATLAB (BTCS 608) Piyush Mali (19100BTIT06588)

(c) conversion of image file formats-


 imwrite(A,filename) writes image data A to the file specified by filename, inferring the
file format from the extension. imwrite creates the new file in your current folder. The
bit depth of the output image depends on the data type of A and the file format.

pg. 20
IT Workshop -Scilab/MATLAB (BTCS 608) Piyush Mali (19100BTIT06588)

pg. 21
IT Workshop -Scilab/MATLAB (BTCS 608) Piyush Mali (19100BTIT06588)

Experiment No. 12
Aim: Write a program to compute roots of a quadratic equation ax 2+bx+c=0 given a, b and
c.
Quadratic equation is a second order polynomial with 3 coefficients - a, b, c. The quadratic
equation is given by: ax2+bx+c=0 The solution to the quadratic equation is given by 2
numbers x1 and x2. We can change the quadratic equation to the form of: (x - x1)(x - x2) = 0
Quadratic Formula: The solution to the quadratic equation is given by the quadratic
formula:

The expression inside the square root is called discriminant and is denoted by Δ: Δ = b2 - 4ac
The quadratic formula with discriminant notation:

This expression is important because it can tell us about the solution:


 When Δ>0, there are 2 real roots x1=(-b+√Δ)/(2a) and x2=(-b-√Δ)/(2a).
 When Δ=0, there is one root x1=x2=-b/(2a).
 When Δ<0, there are no real roots, there are 2 complex roots:
x1=(-b+i√-Δ)/(2a) and x2=(-b-i√-Δ)/(2a).
For Example: Find the roots of 2x2+4x+1 = 0

pg. 22

You might also like