[go: up one dir, main page]

0% found this document useful (0 votes)
118 views14 pages

Practical-8 AIM:-To Perform LU Decomposition On A Given Matrix in MATLAB

Uploaded by

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

Practical-8 AIM:-To Perform LU Decomposition On A Given Matrix in MATLAB

Uploaded by

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

Faculty Of Engineering & Technology

Subject Name: IT Workshop 2


Subject Code: 203105258
B. Tech 2nd Year 4th Semester

PRACTICAL- 8

AIM:-To perform LU Decomposition on a given matrix in MATLAB

Compute the LU factorization of a matrix and examine the resulting factors. LU factorization is a
way of decomposing a matrix A into an upper triangular matrix U, a lower triangular matrix L, and
a permutation matrix P such that PA=LU. These matrices describe the steps needed to perform
Gaussian elimination on the matrix until it is in reduced row echelon form. The L matrix contains
all of the multipliers, and the permutation matrix P accounts for row interchanges.
1. [L,U] = lu(A) factorizes the full or sparse matrix A into an upper triangular matrix U and a
permuted lower triangular matrix L such that A = P*L

2. example

[L,U,P] = lu(A) also returns a permutation matrix P such that A = P'*L*U. With this syntax, L is
unit lower triangular and U is upper triangular.

example

[L,U,P] = lu(A,outputForm) returns P in the form specified by outputForm.


Specify outputForm as 'vector' to return P as a permutation vector such that A(P,:) = L*U.

example

[L,U,P,Q] = lu(S) factorizes sparse matrix S into a unit lower triangular matrix L, an upper


triangular matrix U, a row permutation matrix P, and a column permutation matrix Q, such
that P*S*Q = L*U.

[L,U,P,Q,D] = lu(S) also returns a diagonal scaling matrix D such that P*(D\S)*Q = L*U.


Typically, the row-scaling leads to a sparser and more stable factorization.

[___] = lu(S,thresh) specifies thresholds for the pivoting strategy employed by lu using any of the
previous output argument combinations. Depending on the number of output arguments specified,
the default value and requirements for the thresh input are different. See the thresh argument
description for details.

example

Enrollment no:190303105559
Faculty Of Engineering & Technology
Subject Name: IT Workshop 2
Subject Code: 203105258
B. Tech 2nd Year 4th Semester

[___] = lu(___,outputForm) returns P and Q in the form specified by outputForm.


Specify outputForm as 'vector' to return P and Q as permutation vectors. You can use any of the
input argument combinations in previous syntaxes.

INPUT

A = [10 -7 0
-3 2 6
5 -1 5];
[L,U] = lu(A)

INPU
T
[L,U,P] = lu(A)
OUTPUT

Enrollment no:190303105559
Faculty Of Engineering & Technology
Subject Name: IT Workshop 2
Subject Code: 203105258
B. Tech 2nd Year 4th Semester

INPU
T
P'*L*U
OUTPUT

INPUT
:
A = magic(5)
b = 65*ones(5,1);
x = A\b
OUTPUT:

Enrollment no:190303105559
Faculty Of Engineering & Technology
Subject Name: IT Workshop 2
Subject Code: 203105258
B. Tech 2nd Year 4th Semester

INPUT
[L,U,P] = lu(A)
OUTPUT

INPUT
y = L\(P*b);
x = U\y
OUTPUT

Enrollment no:190303105559
Faculty Of Engineering & Technology
Subject Name: IT Workshop 2
Subject Code: 203105258
B. Tech 2nd Year 4th Semester

PRACTICAL -9
Aim : To Perform singular value decomposition on a given matrix in MATLAB
Singular Value Decomposition

Singular value decomposition expresses an m-by-n matrix A as A = U*S*V'. Here, S is an m-by-


n diagonal matrix with singular values of A on its diagonal. The columns of the m-by-
m matrix U are the left singular vectors for corresponding singular values. The columns of the n-by-
n matrix V are the right singular vectors for corresponding singular values. V' is the Hermitian
transpose (the complex conjugate of the transpose) of V.
To compute the singular value decomposition of a matrix, use svd. This function lets you compute
singular values of a matrix separately or both singular values and singular vectors in one function
call. To compute singular values only, use svd without output arguments
svd(A)
or with one output argument
S = svd(A)
To compute singular values and singular vectors of a matrix, use three output arguments:
[U,S,V] = svd(A)

Enrollment no:190303105559
Faculty Of Engineering & Technology
Subject Name: IT Workshop 2
Subject Code: 203105258
B. Tech 2nd Year 4th Semester

svd returns two unitary matrices, U and V, the columns of which are singular vectors. It also
returns a diagonal matrix, S, containing singular values on its diagonal. The elements of all three
matrices are floating-point numbers. The accuracy of computations is determined by the current
setting of digits.
Create the n-by-n matrix A with elements defined by A(i,j) = 1/(i - j + 1/2). The
most obvious way of generating this matrix is
INPUT
n = 3;
for i = 1:n
for j = 1:n
A(i,j) = sym(1/(i-j+1/2));
end
end
For n = 3, the matrix is
A
A=
[ 2, -2, -2/3]
[ 2/3, 2, -2]
[ 2/5, 2/3, 2]
Compute the singular values of this matrix. If you use svd directly, it will return exact symbolic
result. For this matrix, the result is very long. If you prefer a shorter numeric result, convert the
elements of A to floating-point numbers using vpa. Then use svd to compute singular values of
this matrix using variable-precision arithmetic:
S = svd(vpa(A))
S=
3.1387302525015353960741348953506
3.0107425975027462353291981598225
1.6053456783345441725883965978052
Now, compute the singular values and singular vectors of A:

[U,S,V] = svd(A)
U=
[ 0.53254331027335338470683368360204, 0.76576895948802052989304092179952,...
0.36054891952096214791189887728353]
[ -0.82525689650849463222502853672224, 0.37514965283965451993171338605042,...
0.42215375485651489522488031917364]

Enrollment no:190303105559
Faculty Of Engineering & Technology
Subject Name: IT Workshop 2
Subject Code: 203105258
B. Tech 2nd Year 4th Semester

[ 0.18801243961043281839917114171742, -0.52236064041897439447429784257224,...
0.83173955292075192178421874331406]

S=
[ 3.1387302525015353960741348953506, 0,...
0]
[ 0, 3.0107425975027462353291981598225,...
0]
[ 0, 0,...
1.6053456783345441725883965978052]

V=
[ 0.18801243961043281839917114171742, 0.52236064041897439447429784257224,...
0.83173955292075192178421874331406]
[ -0.82525689650849463222502853672224, -0.37514965283965451993171338605042,...
0.42215375485651489522488031917364]
[ 0.53254331027335338470683368360204, -0.76576895948802052989304092179952,...
0.36054891952096214791189887728353]

Enrollment no:190303105559
Faculty Of Engineering & Technology
Subject Name: IT Workshop 2
Subject Code: 203105258
B. Tech 2nd Year 4th Semester

PRACTICAL :10

AIM:CASE STUDY ON ANY FIELD OF YOUR INTEREST AS AN

APPLICATION OF MATLAB

Enrollment no:190303105559
Faculty Of Engineering & Technology
Subject Name: IT Workshop 2
Subject Code: 203105258
B. Tech 2nd Year 4th Semester

Video Processing with MATLAB


Video processing can be used to detect and count objects that move in video sequences.

In this case study, scientists in Australia are using video footage to estimate the wildlife
population of waterbirds.

Case study: Advancing Wildlife Research: The Development of a Solution to Process Video
Footage of Waterbirds

https://www.mathworks.com/content/dam/mathworks/mathworks-dot-
com/solutions/aerospace-defense/files/2017/conf-au/advancing-wildlife-research-the-
development-of-a-solution-to-process-video-footage-of-waterbirds.pdf

Video applications present common but difficult challenges that require flexible analysis
and processing functionality. Using MATLAB® and Simulink® products, you can develop
solutions to common video processing challenges such as video stabilization, video
mosaicking, target detection, and tracking.MATLAB® provides tools and algorithms that
let you view, analyze, read, and write videos. Video processing can be useful in applications
like:

Object recognition with deep learning


Motion estimation such as optical flow
Face detection and tracking
Video Processing in 4 Easy Steps

Video processing in MATLAB involves the following steps:

Enrollment no:190303105559
Faculty Of Engineering & Technology
Subject Name: IT Workshop 2
Subject Code: 203105258
B. Tech 2nd Year 4th Semester

1. Reading the video


2. Displaying the video
3. Processing the video
4. Writing the video
Step 1. Reading the Video
You can read video from files or directly from cameras.
A single MATLAB command lets you read in videos from a file:

>> vid = VideoReader('filename.avi')


Step 2. Displaying the Video
There are two methods for displaying video in MATLAB:
deployableVideoPlayer: Efficiently view a series of video frames
implay: Launch the Video Viewer app for viewing videos

Enrollment no:190303105559
Faculty Of Engineering & Technology
Subject Name: IT Workshop 2
Subject Code: 203105258
B. Tech 2nd Year 4th Semester

Enrollment no:190303105559
Faculty Of Engineering & Technology
Subject Name: IT Workshop 2
Subject Code: 203105258
B. Tech 2nd Year 4th Semester

Step 3. Processing the Video


A video is a sequence of individual video frames, or images. This means an algorithm
designed to perform edge detection on an image can be quickly converted to perform edge
detection on a video.

Video processing can be very simple, as in the example using edge detection, or
significantly more complex, such as tracking algorithms that must account for an object’s
location in previous frames.
Step 4. Writing the Video
After processing, you can write each frame of a video back to a file. You can create a video
file with the function:
>> vid_w = VideoWriter('newfile.avi');
>> open(vid_w)

The variable vid_w can accumulate new frames to create a video.


Putting all the components together, let’s run through a complete example to show the steps
of reading, displaying, processing, and writing video:
%% Read and process a video into MATLAB

Enrollment no:190303105559
Faculty Of Engineering & Technology
Subject Name: IT Workshop 2
Subject Code: 203105258
B. Tech 2nd Year 4th Semester

% Setup: create Video Reader and Writer


videoFileReader = VideoReader('tilted_face.avi');
myVideo = VideoWriter('myFile.avi');

% Setup: create deployable video player and face detector


depVideoPlayer = vision.DeployableVideoPlayer;
faceDetector = vision.CascadeObjectDetector();
open(myVideo);

%% Detect faces in each frame


while hasFrame(videoFileReader)

% read video frame


videoFrame = readFrame(videoFileReader);
% process frame
bbox = faceDetector(videoFrame);
videoFrame = insertShape(videoFrame, 'Rectangle', bbox);

% Display video frame to screen


depVideoPlayer(videoFrame);

% Write frame to final video file


writeVideo(myVideo, videoFrame);
pause(1/videoFileReader.FrameRate);

end
close(myVideo)

Enrollment no:190303105559
Faculty Of Engineering & Technology
Subject Name: IT Workshop 2
Subject Code: 203105258
B. Tech 2nd Year 4th Semester

Enrollment no:190303105559

You might also like