SlideShare a Scribd company logo
CSCI 2033: Elementary Computational Linear Algebra
(Spring 2020)
Assignment 1 (100 points)
Due date: February 21st, 2019 11:59pm
In this assignment, you will implement Matlab functions to
perform row
operations, compute the RREF of a matrix, and use it to solve a
real-world
problem that involves linear algebra, namely GPS localization.
For each function that you are asked to implement, you will
need to complete
the corresponding .m file with the same name that is already
provided to you in
the zip file. In the end, you will zip up all your complete .m
files and upload the
zip file to the assignment submission page on Gradescope.
In this and future assignments, you may not use any of Matlab’s
built-in
linear algebra functionality like rref, inv, or the linear solve
function Ab,
except where explicitly permitted. However, you may use the
high-level array
manipulation syntax like A(i,:) and [A,B]. See “Accessing
Multiple Elements”
and “Concatenating Matrices” in the Matlab documentation for
more informa-
tion. However, you are allowed to call a function you have
implemented in this
assignment to use in the implementation of other functions for
this assignment.
Note on plagiarism A submission with any indication of
plagiarism will be
directly reported to University. Copying others’ solutions or
letting another
person copy your solutions will be penalized equally. Protect
your code!
1 Submission Guidelines
You will submit a zip file that contains the following .m files to
Gradescope.
Your filename must be in this format: Firstname Lastname ID
hw1 sol.zip
(please replace the name and ID accordingly). Failing to do so
may result in
points lost.
• interchange.m
• scaling.m
• replacement.m
• my_rref.m
• gps2d.m
• gps3d.m
• solve.m
1
Ricardo
Ricardo
Ricardo
Ricardo
�
The code should be stand-alone. No credit will be given if the
function does not
comply with the expected input and output.
Late submission policy: 25% o↵ up to 24 hours late; 50% o↵ up
to 48 hours late;
No point for more than 48 hours late.
2 Elementary row operations (30 points)
As this may be your first experience with serious programming
in Matlab,
we will ease into it by first writing some simple functions that
perform the
elementary row operations on a matrix: interchange, scaling,
and replacement.
In this exercise, complete the following files:
function B = interchange(A, i, j)
Input: a rectangular matrix A and two integers i and j.
Output: the matrix resulting from swapping rows i and j, i.e.
performing the
row operation Ri $ Rj .
function B = scaling(A, i, s)
Input: a rectangular matrix A, an integer i, and a scalar s.
Output: the matrix resulting from multiplying all entries in row
i by s, i.e. per-
forming the row operation Ri sRi.
function B = replacement(A, i, j, s)
Input: a rectangular matrix A, two integers i and j, and a scalar
s.
Output: the matrix resulting from adding s times row j to row i,
i.e. performing
the row operation Ri Ri + sRj .
Implementation tips:
In each of these functions, you should check that the input
indices i and j are
of rows in the
matrix (which may not be the same as the number of columns!).
If any index
is out of range, print an error using the built-in function disp,
and return the
original matrix. This could help you diagnose problems when
you write your
RREF function in the next part.
Testing:
Test your code on rectangular m⇥n matrices of various sizes,
both when m < n
and when m > n. You can generate some simple matrices for
testing on using
the functions eye(m,n), ones(m,n), and randi(10,m,n).
2
3 RREF (40 points)
Next, you will use these row operations to write a function that
performs Gauss-
Jordan elimination and compute the reduced row echelon form
of any matrix.
We will call the function my_rref, because the rref function
already exists in
Matlab.
Specification:
function R = my_rref(A)
Input: a rectangular matrix A.
Output: the reduced row echelon form of A.
For full credit, your function should handle the following:
• Partial pivoting: At each step, you should swap the current
row with the
one whose entry in the pivot column has the largest absolute
value.
• Free variables: Due to numerical error, the entries in a column
corre-
sponding to a free variable may be extremely small but not
precisely zero.
Therefore, you should consider an entry to be zero if its
absolute value is
smaller than 10�12.
We suggest first implementing the algorithm without
considering these two issues,
then adding code to deal with them one at a time.
Implementation tips:
There are two di↵ erent ways one can implement Gauss-Jordan
elimination.
• In Section 1.2 under “The Row Reduction Algorithm”, the
book describes
it in two phases: first do Gaussian elimination (Steps 1-4), then
perform
row operations equivalent to back-substitution (Step 5).
• Gauss-Jordan elimination can also be done in a single phase:
every time
you find a pivot, perform scaling so the pivot entry becomes 1,
then perform
elimination on all the other rows, both above and below the
pivot row.
You may use either approach in your implementation. Below,
we provide
pseudocode for the latter approach.
In either case, since we want to be
able to handle free variables, the pivot
entry won’t necessarily be on the di-
agonal. Instead, you’ll need to keep
track of both the pivot row, say k, and
the pivot column, l, as you go along;
see the illustration on the right.
3
Algorithm 1 RREF
1: initialize pivot row k = 1, pivot column l = 1
3: among rows k to m, find the row p with the biggest* entry in
column l
4: Rk $ Rp
5: if akl is zero** then
6: l l + 1
7: else
8: Rk (1/akl)Rk
9: for i = 1, . . . , k � 1, k + 1, . . . ,m do
10: Ri Ri � (ail/akl)Rk
11: end for
12: k k + 1, l l + 1
13: end if
14: end while
*Here “biggest” means having the largest absolute value (abs in
Matlab).
**Consider a number to be zero if its absolute value is smaller
than 10�12.
Test cases:
my_rref([2,3,4; 1,1,0]) should return the matrix [1,0,-4; 0,1,4],
i.e.
2 3 4
1 1 0
�
!
1 0 �4
0 1 4
�
.
Partial pivoting: my_rref([0,6; -3,0]) should return the matrix
[1,0; 0,1]:
0 6
�3 0
�
!
1 0
0 1
�
.
Numerical error: my_rref([3,0,0,1; 0,3,0,1; 0,0,3,1; 1,1,1,1]):
2
664
3 0 0 1
0 3 0 1
0 0 3 1
1 1 1 1
3
775!
2
664
1 0 0 1/3
0 1 0 1/3
0 0 1 1/3
0 0 0 0
3
775
Free variables: my_rref([4,4,4,4; 2,2,4,4; 2,2,4,2]):
2
4
4 4 4 4
2 2 4 4
2 2 4 2
3
5!
2
4
1 1 0 0
0 0 1 0
0 0 0 1
3
5
You can also obtain a random m ⇥ n matrix with entries in {�1,
0, 1} by
calling A = randi([-1,1], m, n), then compare your result
my_rref(A) with
Matlab’s built-in rref(A).
4
Note: Solving linear systems (no points)
Once we have an RREF function, we can use it to solve linear
systems Ax = b
by computing the RREF of the augmented matrix [A | b]. For
simplicity, we
will assume that the system has a unique solution. In this case,
the RREF will
be of the form 2
64
1 x1
. . .
...
1 xn
3
75
and the solution vector is just its last column. This is easy to
implement in
Matlab (which is already provided to you as in solve.m):
function x = solve(A, b)
augmented_matrix = [A b];
R = my_rref(augmented_matrix);
x = R(:, end);
end
Test this function on some simple examples of linear systems
which you know to
have unique solutions.
4 GPS localization (30 points)
One real-life application of solving linear systems is GPS
localization. For
simplicity, let us work in a 2D world first. Suppose your
cellphone receives
signals from three GPS satellites at known positions A = (a1,
a2), B = (b1, b2),
and C = (c1, c2), and can measure its distances rA, rB, rC from
all of them, as
shown below.
1 2 4 5( , ) ( , )a a= =A
( , )x y
5r =A
1 2 5 2( , ) ( , )b b= = −B
5r =B
1 2 11 6( , ) ( , )c c= = −C
13r =C
This gives us three quadratic equations for our own position P =
(x, y):
r2A = (a1 � x)2 + (a2 � y)2, (1a)
r2B = (b1 � x)2 + (b2 � y)2, (1b)
r2C = (c1 � x)2 + (c2 � y)2. (1c)
5
Subtracting equation (1a) from equation (1b) and equation (1b)
from equa-
tion (1c), then simplifying, gives us a 2⇥ 2 linear system in x
and y:
r2B � r2A = 2(a1 � b1)x+ 2(a2 � b2)y � a21 � a22 + b21 +
b22, (2a)
r2C � r2B = 2(b1 � c1)x+ 2(b2 � c2)y � b21 � b22 + c21 +
c22. (2b)
Since this is a system of linear equations, it can be expressed in
matrix form,
⇤ ⇤
⇤ ⇤
�
x
y
�
=
⇤
⇤
�
, (3)
for some matrix and some vector on the right-hand side that you
should be able
to figure out. Your task in this part of the assignment is to
implement this
method in Matlab (in gps2D.m and gps3D.m). That is, given the
points A, B,
C and distances rA, rB, rC, you will have to:
1. construct the matrix and the right-hand side vector in (3)
corresponding
to the linear system (2a)-(2b),
2. pass this matrix and vector to the solve function (already
provided in
the zip file) to obtain the point P. Note: if you did not get your
my_rref
function to work, you can change it to the Matlab built-in rref
in the
solve function in solve.m.
Exactly the same approach also works in 3D, except we will
now need our
distances from four known points A = (a1, a2, a3), B = (b1, b2,
b3), C = (c1, c2, c3),
and D = (d1, d2, d3). Your second task is to work out the
analogous equations
to (2a)-(2b), and implement another program that works in 3D.
Specification:
function p = gps2d(a, b, c, ra, rb, rc)
Input: The 2D coordinates of three points A, B, C, and their
distances rA, rB,
rC from an unknown point P.
Output: The 2D coordinates of the point P.
function p = gps3d(a, b, c, d, ra, rb, rc, rd)
Input: The 3D coordinates of four points A, B, C, D, and their
distances rA, rB,
rC, rD from an unknown point P.
Output: The 3D coordinates of the point P.
Test cases:
gps2d([4;5], [5;-2], [-11;6], 5, 5, 13) should return the vector
[1;1].
gps3d([6;-3;3], [-1;-6;5], [-5;4;7], [6;8;4], 5, 7, 9, 9) should re-
turn [2;0;3].
In general, you can create a random 2D vector with entries
between say 0 and
10 by using a = 10*rand(2,1). Do this four times for a, b, c, and
p, and
set ra = norm(a - p) and so on. (The norm function returns the
length of a
vector.) Then check whether gps2d(a, b, c, ra, rb, rc) gives you
back p.
6
gps2d.m
%%
% Solve for the 2D coordinate of P as a problem of linear
system
%
% The parameters received are:
% - a (2 x 1): 2D coordinate of point A
% - b (2 x 1): 2D coordinate of point B
% - c (2 x 1): 2D coordinate of point C
% - ra (1 x 1): distance from A to P
% - rb (1 x 1): distance from B to P
% - rc (1 x 1): distance from C to P
%
% The function should return
% - p (2 x 1): 2D coordinate of P
function p = gps2d(a, b, c, ra, rb, rc)
%%%% YOUR CODE STARTS HERE
end
__MACOSX/._gps2d.m
gps3d.m
%%
% Solve for the 3D coordinate of P as a problem of linear
system
%
% The parameters received are:
% - a (3 x 1): 3D coordinate of point A
% - b (3 x 1): 3D coordinate of point B
% - c (3 x 1): 3D coordinate of point C
% - d (3 x 1): 3D coordinate of point D
% - ra (1 x 1): distance from A to P
% - rb (1 x 1): distance from B to P
% - rc (1 x 1): distance from C to P
% - rd (1 x 1): distance from D to P
%
% The function should return
% - p (3 x 1): 3D coordinate of P
function p = gps3d(a, b, c, d, ra, rb, rc, rd)
%%%% YOUR CODE STARTS HERE
end
__MACOSX/._gps3d.m
interchange.m
%%
% Swap row i and row j of a matrix
%
% The parameters received are:
% - A (m x n): a rectangular matrix
% - i (1 x 1)
% - j (1 x 1)
%
% The function should return
% - B (m x n): the resulting rectangular matrix
function B = interchange(A, i, j)
%%%% YOUR CODE STARTS HERE
end
__MACOSX/._interchange.m
my_rref.m
%%
% Computes the reduced row echelon form of a matrix
%
% The parameters received are:
% - A (m x n): a rectangular matrix
%
% The function should return
% - B (m x n): the reduce row echelon form of A
function B = my_rref(A)
%%%% YOUR CODE STARTS HERE
end
__MACOSX/._my_rref.m
replacement.m
%%
% Add the result of a scalar times row j to row i of a matrix
%
% The parameters received are:
% - A (m x n): a rectangular matrix
% - i (1 x 1)
% - j (1 x 1)
% - s (1 x 1): a scalar
%
% The function should return
% - B (m x n): the resulting rectangular matrix
function B = replacement(A, i, j, s)
%%%% YOUR CODE STARTS HERE
end
__MACOSX/._replacement.m
scaling.m
%%
% Multiply all entries in row i of a matrix by a scalar
%
% The parameters received are:
% - A (m x n): a rectangular matrix
% - i (1 x 1)
% - s (1 x 1): a scalar
%
% The function should return
% - B (m x n): the resulting rectangular matrix
function B = scaling(A, i, s)
%%%% YOUR CODE STARTS HERE
end
__MACOSX/._scaling.m
solve.m
%%
% Solve for the linear system Ax = b
%
% The parameters received are:
% - A (m x n): a rectangular matrix
% - b (m x 1): right hand side of a linear system
%
% The function should return
% - x (n x 1): solution vector [x_1, x_2, ..., x_n]
function x = solve(A, b)
augmented_matrix = [A b];
% you can change it to rref if your my_rref does not work
R = my_rref(augmented_matrix);
x = R(:, end);
end
__MACOSX/._solve.m
Ad

More Related Content

Similar to CSCI 2033 Elementary Computational Linear Algebra(Spring 20.docx (20)

Graph Algorithms, Sparse Algebra, and the GraphBLAS with Janice McMahon
Graph Algorithms, Sparse Algebra, and the GraphBLAS with Janice McMahonGraph Algorithms, Sparse Algebra, and the GraphBLAS with Janice McMahon
Graph Algorithms, Sparse Algebra, and the GraphBLAS with Janice McMahon
Christopher Conlan
 
EPE821_Lecture3.pptx
EPE821_Lecture3.pptxEPE821_Lecture3.pptx
EPE821_Lecture3.pptx
Ihtisham Uddin
 
INTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxINTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptx
Devaraj Chilakala
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
Vikash Jakhar
 
Control system Lab record
Control system Lab record Control system Lab record
Control system Lab record
Yuvraj Singh
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
amanabr
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
Kurmendra Singh
 
Intro matlab and convolution islam
Intro matlab and convolution islamIntro matlab and convolution islam
Intro matlab and convolution islam
Islam Alabbasy
 
Multinomial Logistic Regression with Apache Spark
Multinomial Logistic Regression with Apache SparkMultinomial Logistic Regression with Apache Spark
Multinomial Logistic Regression with Apache Spark
DB Tsai
 
Alpine Spark Implementation - Technical
Alpine Spark Implementation - TechnicalAlpine Spark Implementation - Technical
Alpine Spark Implementation - Technical
alpinedatalabs
 
MATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdfMATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdf
ahmed8651
 
Introduction to Data Science With R Lab Record
Introduction to Data Science With R Lab RecordIntroduction to Data Science With R Lab Record
Introduction to Data Science With R Lab Record
Lakshmi Sarvani Videla
 
MATLAB
MATLABMATLAB
MATLAB
svati sharma
 
Matlab anilkumar
Matlab  anilkumarMatlab  anilkumar
Matlab anilkumar
THEMASTERBLASTERSVID
 
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptxMATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
prashantkumarchinama
 
Quiz
QuizQuiz
Quiz
Qazi Ejaz
 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptx
raghav415187
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
agnesdcarey33086
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
anhlodge
 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab session
Dr. Krishna Mohbey
 
Graph Algorithms, Sparse Algebra, and the GraphBLAS with Janice McMahon
Graph Algorithms, Sparse Algebra, and the GraphBLAS with Janice McMahonGraph Algorithms, Sparse Algebra, and the GraphBLAS with Janice McMahon
Graph Algorithms, Sparse Algebra, and the GraphBLAS with Janice McMahon
Christopher Conlan
 
INTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxINTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptx
Devaraj Chilakala
 
Control system Lab record
Control system Lab record Control system Lab record
Control system Lab record
Yuvraj Singh
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
amanabr
 
Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013Dsp lab _eec-652__vi_sem_18012013
Dsp lab _eec-652__vi_sem_18012013
Kurmendra Singh
 
Intro matlab and convolution islam
Intro matlab and convolution islamIntro matlab and convolution islam
Intro matlab and convolution islam
Islam Alabbasy
 
Multinomial Logistic Regression with Apache Spark
Multinomial Logistic Regression with Apache SparkMultinomial Logistic Regression with Apache Spark
Multinomial Logistic Regression with Apache Spark
DB Tsai
 
Alpine Spark Implementation - Technical
Alpine Spark Implementation - TechnicalAlpine Spark Implementation - Technical
Alpine Spark Implementation - Technical
alpinedatalabs
 
MATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdfMATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdf
ahmed8651
 
Introduction to Data Science With R Lab Record
Introduction to Data Science With R Lab RecordIntroduction to Data Science With R Lab Record
Introduction to Data Science With R Lab Record
Lakshmi Sarvani Videla
 
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptxMATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
prashantkumarchinama
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
agnesdcarey33086
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
anhlodge
 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab session
Dr. Krishna Mohbey
 

More from mydrynan (20)

CSIA 413 Cybersecurity Policy, Plans, and Programs.docx
CSIA 413 Cybersecurity Policy, Plans, and Programs.docxCSIA 413 Cybersecurity Policy, Plans, and Programs.docx
CSIA 413 Cybersecurity Policy, Plans, and Programs.docx
mydrynan
 
CSIS 100CSIS 100 - Discussion Board Topic #1One of the object.docx
CSIS 100CSIS 100 - Discussion Board Topic #1One of the object.docxCSIS 100CSIS 100 - Discussion Board Topic #1One of the object.docx
CSIS 100CSIS 100 - Discussion Board Topic #1One of the object.docx
mydrynan
 
CSI Paper Grading Rubric- (worth a possible 100 points) .docx
CSI Paper Grading Rubric- (worth a possible 100 points)   .docxCSI Paper Grading Rubric- (worth a possible 100 points)   .docx
CSI Paper Grading Rubric- (worth a possible 100 points) .docx
mydrynan
 
CSIA 413 Cybersecurity Policy, Plans, and ProgramsProject #4 IT .docx
CSIA 413 Cybersecurity Policy, Plans, and ProgramsProject #4 IT .docxCSIA 413 Cybersecurity Policy, Plans, and ProgramsProject #4 IT .docx
CSIA 413 Cybersecurity Policy, Plans, and ProgramsProject #4 IT .docx
mydrynan
 
CSI 170 Week 3 AssingmentAssignment 1 Cyber Computer CrimeAss.docx
CSI 170 Week 3 AssingmentAssignment 1 Cyber Computer CrimeAss.docxCSI 170 Week 3 AssingmentAssignment 1 Cyber Computer CrimeAss.docx
CSI 170 Week 3 AssingmentAssignment 1 Cyber Computer CrimeAss.docx
mydrynan
 
CSE422 Section 002 – Computer Networking Fall 2018 Ho.docx
CSE422 Section 002 – Computer Networking Fall 2018  Ho.docxCSE422 Section 002 – Computer Networking Fall 2018  Ho.docx
CSE422 Section 002 – Computer Networking Fall 2018 Ho.docx
mydrynan
 
CSCI  132  Practical  Unix  and  Programming   .docx
CSCI  132  Practical  Unix  and  Programming   .docxCSCI  132  Practical  Unix  and  Programming   .docx
CSCI  132  Practical  Unix  and  Programming   .docx
mydrynan
 
CSCI 714 Software Project Planning and EstimationLec.docx
CSCI 714 Software Project Planning and EstimationLec.docxCSCI 714 Software Project Planning and EstimationLec.docx
CSCI 714 Software Project Planning and EstimationLec.docx
mydrynan
 
CSCI 561Research Paper Topic Proposal and Outline Instructions.docx
CSCI 561Research Paper Topic Proposal and Outline Instructions.docxCSCI 561Research Paper Topic Proposal and Outline Instructions.docx
CSCI 561Research Paper Topic Proposal and Outline Instructions.docx
mydrynan
 
CSCI 561 DB Standardized Rubric50 PointsCriteriaLevels of .docx
CSCI 561 DB Standardized Rubric50 PointsCriteriaLevels of .docxCSCI 561 DB Standardized Rubric50 PointsCriteriaLevels of .docx
CSCI 561 DB Standardized Rubric50 PointsCriteriaLevels of .docx
mydrynan
 
CryptographyLesson 10© Copyright 2012-2013 (ISC)², Inc. Al.docx
CryptographyLesson 10© Copyright 2012-2013 (ISC)², Inc. Al.docxCryptographyLesson 10© Copyright 2012-2013 (ISC)², Inc. Al.docx
CryptographyLesson 10© Copyright 2012-2013 (ISC)², Inc. Al.docx
mydrynan
 
CSCI 352 - Digital Forensics Assignment #1 Spring 2020 .docx
CSCI 352 - Digital Forensics Assignment #1 Spring 2020 .docxCSCI 352 - Digital Forensics Assignment #1 Spring 2020 .docx
CSCI 352 - Digital Forensics Assignment #1 Spring 2020 .docx
mydrynan
 
CSCE 1040 Homework 2 For this assignment we are going to .docx
CSCE 1040 Homework 2  For this assignment we are going to .docxCSCE 1040 Homework 2  For this assignment we are going to .docx
CSCE 1040 Homework 2 For this assignment we are going to .docx
mydrynan
 
CSCE509–Spring2019Assignment3updated01May19DU.docx
CSCE509–Spring2019Assignment3updated01May19DU.docxCSCE509–Spring2019Assignment3updated01May19DU.docx
CSCE509–Spring2019Assignment3updated01May19DU.docx
mydrynan
 
CSCE 3110 Data Structures & Algorithms Summer 2019 1 of .docx
CSCE 3110 Data Structures & Algorithms Summer 2019   1 of .docxCSCE 3110 Data Structures & Algorithms Summer 2019   1 of .docx
CSCE 3110 Data Structures & Algorithms Summer 2019 1 of .docx
mydrynan
 
CSCI 340 Final Group ProjectNatalie Warden, Arturo Gonzalez, R.docx
CSCI 340 Final Group ProjectNatalie Warden, Arturo Gonzalez, R.docxCSCI 340 Final Group ProjectNatalie Warden, Arturo Gonzalez, R.docx
CSCI 340 Final Group ProjectNatalie Warden, Arturo Gonzalez, R.docx
mydrynan
 
CSC-321 Final Writing Assignment In this assignment, you .docx
CSC-321 Final Writing Assignment  In this assignment, you .docxCSC-321 Final Writing Assignment  In this assignment, you .docx
CSC-321 Final Writing Assignment In this assignment, you .docx
mydrynan
 
Cryptography is the application of algorithms to ensure the confiden.docx
Cryptography is the application of algorithms to ensure the confiden.docxCryptography is the application of algorithms to ensure the confiden.docx
Cryptography is the application of algorithms to ensure the confiden.docx
mydrynan
 
CSc3320 Assignment 6 Due on 24th April, 2013 Socket programming .docx
CSc3320 Assignment 6 Due on 24th April, 2013 Socket programming .docxCSc3320 Assignment 6 Due on 24th April, 2013 Socket programming .docx
CSc3320 Assignment 6 Due on 24th April, 2013 Socket programming .docx
mydrynan
 
Cryptography KeysCryptography provides confidentiality, inte.docx
Cryptography KeysCryptography provides confidentiality, inte.docxCryptography KeysCryptography provides confidentiality, inte.docx
Cryptography KeysCryptography provides confidentiality, inte.docx
mydrynan
 
CSIA 413 Cybersecurity Policy, Plans, and Programs.docx
CSIA 413 Cybersecurity Policy, Plans, and Programs.docxCSIA 413 Cybersecurity Policy, Plans, and Programs.docx
CSIA 413 Cybersecurity Policy, Plans, and Programs.docx
mydrynan
 
CSIS 100CSIS 100 - Discussion Board Topic #1One of the object.docx
CSIS 100CSIS 100 - Discussion Board Topic #1One of the object.docxCSIS 100CSIS 100 - Discussion Board Topic #1One of the object.docx
CSIS 100CSIS 100 - Discussion Board Topic #1One of the object.docx
mydrynan
 
CSI Paper Grading Rubric- (worth a possible 100 points) .docx
CSI Paper Grading Rubric- (worth a possible 100 points)   .docxCSI Paper Grading Rubric- (worth a possible 100 points)   .docx
CSI Paper Grading Rubric- (worth a possible 100 points) .docx
mydrynan
 
CSIA 413 Cybersecurity Policy, Plans, and ProgramsProject #4 IT .docx
CSIA 413 Cybersecurity Policy, Plans, and ProgramsProject #4 IT .docxCSIA 413 Cybersecurity Policy, Plans, and ProgramsProject #4 IT .docx
CSIA 413 Cybersecurity Policy, Plans, and ProgramsProject #4 IT .docx
mydrynan
 
CSI 170 Week 3 AssingmentAssignment 1 Cyber Computer CrimeAss.docx
CSI 170 Week 3 AssingmentAssignment 1 Cyber Computer CrimeAss.docxCSI 170 Week 3 AssingmentAssignment 1 Cyber Computer CrimeAss.docx
CSI 170 Week 3 AssingmentAssignment 1 Cyber Computer CrimeAss.docx
mydrynan
 
CSE422 Section 002 – Computer Networking Fall 2018 Ho.docx
CSE422 Section 002 – Computer Networking Fall 2018  Ho.docxCSE422 Section 002 – Computer Networking Fall 2018  Ho.docx
CSE422 Section 002 – Computer Networking Fall 2018 Ho.docx
mydrynan
 
CSCI  132  Practical  Unix  and  Programming   .docx
CSCI  132  Practical  Unix  and  Programming   .docxCSCI  132  Practical  Unix  and  Programming   .docx
CSCI  132  Practical  Unix  and  Programming   .docx
mydrynan
 
CSCI 714 Software Project Planning and EstimationLec.docx
CSCI 714 Software Project Planning and EstimationLec.docxCSCI 714 Software Project Planning and EstimationLec.docx
CSCI 714 Software Project Planning and EstimationLec.docx
mydrynan
 
CSCI 561Research Paper Topic Proposal and Outline Instructions.docx
CSCI 561Research Paper Topic Proposal and Outline Instructions.docxCSCI 561Research Paper Topic Proposal and Outline Instructions.docx
CSCI 561Research Paper Topic Proposal and Outline Instructions.docx
mydrynan
 
CSCI 561 DB Standardized Rubric50 PointsCriteriaLevels of .docx
CSCI 561 DB Standardized Rubric50 PointsCriteriaLevels of .docxCSCI 561 DB Standardized Rubric50 PointsCriteriaLevels of .docx
CSCI 561 DB Standardized Rubric50 PointsCriteriaLevels of .docx
mydrynan
 
CryptographyLesson 10© Copyright 2012-2013 (ISC)², Inc. Al.docx
CryptographyLesson 10© Copyright 2012-2013 (ISC)², Inc. Al.docxCryptographyLesson 10© Copyright 2012-2013 (ISC)², Inc. Al.docx
CryptographyLesson 10© Copyright 2012-2013 (ISC)², Inc. Al.docx
mydrynan
 
CSCI 352 - Digital Forensics Assignment #1 Spring 2020 .docx
CSCI 352 - Digital Forensics Assignment #1 Spring 2020 .docxCSCI 352 - Digital Forensics Assignment #1 Spring 2020 .docx
CSCI 352 - Digital Forensics Assignment #1 Spring 2020 .docx
mydrynan
 
CSCE 1040 Homework 2 For this assignment we are going to .docx
CSCE 1040 Homework 2  For this assignment we are going to .docxCSCE 1040 Homework 2  For this assignment we are going to .docx
CSCE 1040 Homework 2 For this assignment we are going to .docx
mydrynan
 
CSCE509–Spring2019Assignment3updated01May19DU.docx
CSCE509–Spring2019Assignment3updated01May19DU.docxCSCE509–Spring2019Assignment3updated01May19DU.docx
CSCE509–Spring2019Assignment3updated01May19DU.docx
mydrynan
 
CSCE 3110 Data Structures & Algorithms Summer 2019 1 of .docx
CSCE 3110 Data Structures & Algorithms Summer 2019   1 of .docxCSCE 3110 Data Structures & Algorithms Summer 2019   1 of .docx
CSCE 3110 Data Structures & Algorithms Summer 2019 1 of .docx
mydrynan
 
CSCI 340 Final Group ProjectNatalie Warden, Arturo Gonzalez, R.docx
CSCI 340 Final Group ProjectNatalie Warden, Arturo Gonzalez, R.docxCSCI 340 Final Group ProjectNatalie Warden, Arturo Gonzalez, R.docx
CSCI 340 Final Group ProjectNatalie Warden, Arturo Gonzalez, R.docx
mydrynan
 
CSC-321 Final Writing Assignment In this assignment, you .docx
CSC-321 Final Writing Assignment  In this assignment, you .docxCSC-321 Final Writing Assignment  In this assignment, you .docx
CSC-321 Final Writing Assignment In this assignment, you .docx
mydrynan
 
Cryptography is the application of algorithms to ensure the confiden.docx
Cryptography is the application of algorithms to ensure the confiden.docxCryptography is the application of algorithms to ensure the confiden.docx
Cryptography is the application of algorithms to ensure the confiden.docx
mydrynan
 
CSc3320 Assignment 6 Due on 24th April, 2013 Socket programming .docx
CSc3320 Assignment 6 Due on 24th April, 2013 Socket programming .docxCSc3320 Assignment 6 Due on 24th April, 2013 Socket programming .docx
CSc3320 Assignment 6 Due on 24th April, 2013 Socket programming .docx
mydrynan
 
Cryptography KeysCryptography provides confidentiality, inte.docx
Cryptography KeysCryptography provides confidentiality, inte.docxCryptography KeysCryptography provides confidentiality, inte.docx
Cryptography KeysCryptography provides confidentiality, inte.docx
mydrynan
 
Ad

Recently uploaded (20)

Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Herbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptxHerbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptx
RAJU THENGE
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx   quiz by Ridip HazarikaTHE STG QUIZ GROUP D.pptx   quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
Ridip Hazarika
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
APM Midlands Region April 2025 Sacha Hind Circulated.pdf
APM Midlands Region April 2025 Sacha Hind Circulated.pdfAPM Midlands Region April 2025 Sacha Hind Circulated.pdf
APM Midlands Region April 2025 Sacha Hind Circulated.pdf
Association for Project Management
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Grade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable WorksheetGrade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable Worksheet
Sritoma Majumder
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
Herbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptxHerbs Used in Cosmetic Formulations .pptx
Herbs Used in Cosmetic Formulations .pptx
RAJU THENGE
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx   quiz by Ridip HazarikaTHE STG QUIZ GROUP D.pptx   quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
Ridip Hazarika
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
Grade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable WorksheetGrade 2 - Mathematics - Printable Worksheet
Grade 2 - Mathematics - Printable Worksheet
Sritoma Majumder
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Ad

CSCI 2033 Elementary Computational Linear Algebra(Spring 20.docx

  • 1. CSCI 2033: Elementary Computational Linear Algebra (Spring 2020) Assignment 1 (100 points) Due date: February 21st, 2019 11:59pm In this assignment, you will implement Matlab functions to perform row operations, compute the RREF of a matrix, and use it to solve a real-world problem that involves linear algebra, namely GPS localization. For each function that you are asked to implement, you will need to complete the corresponding .m file with the same name that is already provided to you in the zip file. In the end, you will zip up all your complete .m files and upload the zip file to the assignment submission page on Gradescope. In this and future assignments, you may not use any of Matlab’s built-in linear algebra functionality like rref, inv, or the linear solve function Ab, except where explicitly permitted. However, you may use the high-level array manipulation syntax like A(i,:) and [A,B]. See “Accessing Multiple Elements” and “Concatenating Matrices” in the Matlab documentation for more informa- tion. However, you are allowed to call a function you have
  • 2. implemented in this assignment to use in the implementation of other functions for this assignment. Note on plagiarism A submission with any indication of plagiarism will be directly reported to University. Copying others’ solutions or letting another person copy your solutions will be penalized equally. Protect your code! 1 Submission Guidelines You will submit a zip file that contains the following .m files to Gradescope. Your filename must be in this format: Firstname Lastname ID hw1 sol.zip (please replace the name and ID accordingly). Failing to do so may result in points lost. • interchange.m • scaling.m • replacement.m • my_rref.m • gps2d.m • gps3d.m • solve.m 1
  • 3. Ricardo Ricardo Ricardo Ricardo � The code should be stand-alone. No credit will be given if the function does not comply with the expected input and output. Late submission policy: 25% o↵ up to 24 hours late; 50% o↵ up to 48 hours late; No point for more than 48 hours late.
  • 4. 2 Elementary row operations (30 points) As this may be your first experience with serious programming in Matlab, we will ease into it by first writing some simple functions that perform the elementary row operations on a matrix: interchange, scaling, and replacement. In this exercise, complete the following files: function B = interchange(A, i, j) Input: a rectangular matrix A and two integers i and j. Output: the matrix resulting from swapping rows i and j, i.e. performing the row operation Ri $ Rj . function B = scaling(A, i, s) Input: a rectangular matrix A, an integer i, and a scalar s. Output: the matrix resulting from multiplying all entries in row i by s, i.e. per- forming the row operation Ri sRi. function B = replacement(A, i, j, s) Input: a rectangular matrix A, two integers i and j, and a scalar s. Output: the matrix resulting from adding s times row j to row i, i.e. performing the row operation Ri Ri + sRj . Implementation tips: In each of these functions, you should check that the input indices i and j are of rows in the
  • 5. matrix (which may not be the same as the number of columns!). If any index is out of range, print an error using the built-in function disp, and return the original matrix. This could help you diagnose problems when you write your RREF function in the next part. Testing: Test your code on rectangular m⇥n matrices of various sizes, both when m < n and when m > n. You can generate some simple matrices for testing on using the functions eye(m,n), ones(m,n), and randi(10,m,n). 2 3 RREF (40 points) Next, you will use these row operations to write a function that performs Gauss- Jordan elimination and compute the reduced row echelon form of any matrix. We will call the function my_rref, because the rref function already exists in Matlab. Specification: function R = my_rref(A) Input: a rectangular matrix A. Output: the reduced row echelon form of A.
  • 6. For full credit, your function should handle the following: • Partial pivoting: At each step, you should swap the current row with the one whose entry in the pivot column has the largest absolute value. • Free variables: Due to numerical error, the entries in a column corre- sponding to a free variable may be extremely small but not precisely zero. Therefore, you should consider an entry to be zero if its absolute value is smaller than 10�12. We suggest first implementing the algorithm without considering these two issues, then adding code to deal with them one at a time. Implementation tips: There are two di↵ erent ways one can implement Gauss-Jordan elimination. • In Section 1.2 under “The Row Reduction Algorithm”, the book describes it in two phases: first do Gaussian elimination (Steps 1-4), then perform row operations equivalent to back-substitution (Step 5). • Gauss-Jordan elimination can also be done in a single phase: every time you find a pivot, perform scaling so the pivot entry becomes 1, then perform elimination on all the other rows, both above and below the pivot row.
  • 7. You may use either approach in your implementation. Below, we provide pseudocode for the latter approach. In either case, since we want to be able to handle free variables, the pivot entry won’t necessarily be on the di- agonal. Instead, you’ll need to keep track of both the pivot row, say k, and the pivot column, l, as you go along; see the illustration on the right. 3 Algorithm 1 RREF 1: initialize pivot row k = 1, pivot column l = 1 3: among rows k to m, find the row p with the biggest* entry in column l 4: Rk $ Rp 5: if akl is zero** then 6: l l + 1 7: else 8: Rk (1/akl)Rk 9: for i = 1, . . . , k � 1, k + 1, . . . ,m do 10: Ri Ri � (ail/akl)Rk 11: end for 12: k k + 1, l l + 1 13: end if 14: end while
  • 8. *Here “biggest” means having the largest absolute value (abs in Matlab). **Consider a number to be zero if its absolute value is smaller than 10�12. Test cases: my_rref([2,3,4; 1,1,0]) should return the matrix [1,0,-4; 0,1,4], i.e. 2 3 4 1 1 0 � ! 1 0 �4 0 1 4 � . Partial pivoting: my_rref([0,6; -3,0]) should return the matrix [1,0; 0,1]: 0 6 �3 0 � ! 1 0 0 1
  • 9. � . Numerical error: my_rref([3,0,0,1; 0,3,0,1; 0,0,3,1; 1,1,1,1]): 2 664 3 0 0 1 0 3 0 1 0 0 3 1 1 1 1 1 3 775! 2 664 1 0 0 1/3 0 1 0 1/3 0 0 1 1/3 0 0 0 0 3 775 Free variables: my_rref([4,4,4,4; 2,2,4,4; 2,2,4,2]): 2 4 4 4 4 4 2 2 4 4
  • 10. 2 2 4 2 3 5! 2 4 1 1 0 0 0 0 1 0 0 0 0 1 3 5 You can also obtain a random m ⇥ n matrix with entries in {�1, 0, 1} by calling A = randi([-1,1], m, n), then compare your result my_rref(A) with Matlab’s built-in rref(A). 4 Note: Solving linear systems (no points) Once we have an RREF function, we can use it to solve linear systems Ax = b by computing the RREF of the augmented matrix [A | b]. For simplicity, we will assume that the system has a unique solution. In this case, the RREF will be of the form 2
  • 11. 64 1 x1 . . . ... 1 xn 3 75 and the solution vector is just its last column. This is easy to implement in Matlab (which is already provided to you as in solve.m): function x = solve(A, b) augmented_matrix = [A b]; R = my_rref(augmented_matrix); x = R(:, end); end Test this function on some simple examples of linear systems which you know to have unique solutions. 4 GPS localization (30 points) One real-life application of solving linear systems is GPS localization. For simplicity, let us work in a 2D world first. Suppose your cellphone receives signals from three GPS satellites at known positions A = (a1, a2), B = (b1, b2),
  • 12. and C = (c1, c2), and can measure its distances rA, rB, rC from all of them, as shown below. 1 2 4 5( , ) ( , )a a= =A ( , )x y 5r =A 1 2 5 2( , ) ( , )b b= = −B 5r =B 1 2 11 6( , ) ( , )c c= = −C 13r =C This gives us three quadratic equations for our own position P = (x, y): r2A = (a1 � x)2 + (a2 � y)2, (1a) r2B = (b1 � x)2 + (b2 � y)2, (1b) r2C = (c1 � x)2 + (c2 � y)2. (1c) 5 Subtracting equation (1a) from equation (1b) and equation (1b) from equa- tion (1c), then simplifying, gives us a 2⇥ 2 linear system in x and y: r2B � r2A = 2(a1 � b1)x+ 2(a2 � b2)y � a21 � a22 + b21 + b22, (2a) r2C � r2B = 2(b1 � c1)x+ 2(b2 � c2)y � b21 � b22 + c21 +
  • 13. c22. (2b) Since this is a system of linear equations, it can be expressed in matrix form, ⇤ ⇤ ⇤ ⇤ � x y � = ⇤ ⇤ � , (3) for some matrix and some vector on the right-hand side that you should be able to figure out. Your task in this part of the assignment is to implement this method in Matlab (in gps2D.m and gps3D.m). That is, given the points A, B, C and distances rA, rB, rC, you will have to: 1. construct the matrix and the right-hand side vector in (3) corresponding to the linear system (2a)-(2b), 2. pass this matrix and vector to the solve function (already provided in
  • 14. the zip file) to obtain the point P. Note: if you did not get your my_rref function to work, you can change it to the Matlab built-in rref in the solve function in solve.m. Exactly the same approach also works in 3D, except we will now need our distances from four known points A = (a1, a2, a3), B = (b1, b2, b3), C = (c1, c2, c3), and D = (d1, d2, d3). Your second task is to work out the analogous equations to (2a)-(2b), and implement another program that works in 3D. Specification: function p = gps2d(a, b, c, ra, rb, rc) Input: The 2D coordinates of three points A, B, C, and their distances rA, rB, rC from an unknown point P. Output: The 2D coordinates of the point P. function p = gps3d(a, b, c, d, ra, rb, rc, rd) Input: The 3D coordinates of four points A, B, C, D, and their distances rA, rB, rC, rD from an unknown point P. Output: The 3D coordinates of the point P. Test cases: gps2d([4;5], [5;-2], [-11;6], 5, 5, 13) should return the vector [1;1]. gps3d([6;-3;3], [-1;-6;5], [-5;4;7], [6;8;4], 5, 7, 9, 9) should re- turn [2;0;3].
  • 15. In general, you can create a random 2D vector with entries between say 0 and 10 by using a = 10*rand(2,1). Do this four times for a, b, c, and p, and set ra = norm(a - p) and so on. (The norm function returns the length of a vector.) Then check whether gps2d(a, b, c, ra, rb, rc) gives you back p. 6 gps2d.m %% % Solve for the 2D coordinate of P as a problem of linear system % % The parameters received are: % - a (2 x 1): 2D coordinate of point A % - b (2 x 1): 2D coordinate of point B % - c (2 x 1): 2D coordinate of point C % - ra (1 x 1): distance from A to P % - rb (1 x 1): distance from B to P % - rc (1 x 1): distance from C to P % % The function should return % - p (2 x 1): 2D coordinate of P function p = gps2d(a, b, c, ra, rb, rc) %%%% YOUR CODE STARTS HERE end
  • 16. __MACOSX/._gps2d.m gps3d.m %% % Solve for the 3D coordinate of P as a problem of linear system % % The parameters received are: % - a (3 x 1): 3D coordinate of point A % - b (3 x 1): 3D coordinate of point B % - c (3 x 1): 3D coordinate of point C % - d (3 x 1): 3D coordinate of point D % - ra (1 x 1): distance from A to P % - rb (1 x 1): distance from B to P % - rc (1 x 1): distance from C to P % - rd (1 x 1): distance from D to P % % The function should return % - p (3 x 1): 3D coordinate of P function p = gps3d(a, b, c, d, ra, rb, rc, rd) %%%% YOUR CODE STARTS HERE end __MACOSX/._gps3d.m interchange.m %% % Swap row i and row j of a matrix % % The parameters received are: % - A (m x n): a rectangular matrix % - i (1 x 1)
  • 17. % - j (1 x 1) % % The function should return % - B (m x n): the resulting rectangular matrix function B = interchange(A, i, j) %%%% YOUR CODE STARTS HERE end __MACOSX/._interchange.m my_rref.m %% % Computes the reduced row echelon form of a matrix % % The parameters received are: % - A (m x n): a rectangular matrix % % The function should return % - B (m x n): the reduce row echelon form of A function B = my_rref(A) %%%% YOUR CODE STARTS HERE end __MACOSX/._my_rref.m
  • 18. replacement.m %% % Add the result of a scalar times row j to row i of a matrix % % The parameters received are: % - A (m x n): a rectangular matrix % - i (1 x 1) % - j (1 x 1) % - s (1 x 1): a scalar % % The function should return % - B (m x n): the resulting rectangular matrix function B = replacement(A, i, j, s) %%%% YOUR CODE STARTS HERE end __MACOSX/._replacement.m scaling.m %% % Multiply all entries in row i of a matrix by a scalar % % The parameters received are: % - A (m x n): a rectangular matrix % - i (1 x 1) % - s (1 x 1): a scalar % % The function should return % - B (m x n): the resulting rectangular matrix function B = scaling(A, i, s) %%%% YOUR CODE STARTS HERE
  • 19. end __MACOSX/._scaling.m solve.m %% % Solve for the linear system Ax = b % % The parameters received are: % - A (m x n): a rectangular matrix % - b (m x 1): right hand side of a linear system % % The function should return % - x (n x 1): solution vector [x_1, x_2, ..., x_n] function x = solve(A, b) augmented_matrix = [A b]; % you can change it to rref if your my_rref does not work R = my_rref(augmented_matrix); x = R(:, end); end __MACOSX/._solve.m