Professional Documents
Culture Documents
Piyush Mali MATLAB
Piyush Mali MATLAB
Lab File
IT Workshop -Scilab/MATLAB (BTCS 608)
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
pg. 2
IT Workshop -Scilab/MATLAB (BTCS 608) Piyush Mali (19100BTIT06588)
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)
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
pg. 10
IT Workshop -Scilab/MATLAB (BTCS 608) Piyush Mali (19100BTIT06588)
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:
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)
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:
pg. 22