Intermediate Mathematics for Economists ECON3272
Computer Assignment 1. Matrix Algebra
In this course the opensource software R is used for numerical exercises. R includes a line editor but it is more convenient to use R with RStudio.
R is available in the computer labs and you may download it freely from the web onto your PC (http://www.rproject.org/).
For the installation of R and RStudio see:
Torfs, P. and Brauer, C. “A (very) short introduction to R”, 3 March 2014.
(http://cran.rproject.org/doc/contrib/Torfs+BrauerShortRIntro.pdf)
RStudio splits the computer screen into four windows:
Editor window
• This window provides a text editor.
• Click Run or press CTRL+ENTER to send a line to the consol window where it is executed.
• You may edit and save the programs that you write in this window. Workspace/history window
• The workspace window shows the objects R has in its memory. You can edit their values by clicking on them.
• The history window provides a protocol of what has been typed.
Consol (command) window
• Commands are executed in this window.
• You may write directly into this window using the line editor. Plots/help/files/packages window
• R sends plots to this window.
• You may also use the help function, view files and install packages in this window.
A more detailed introduction to R can be found in:
Venables W.N. and Smith D.M. “An Introduction to R”, 16 April 2015.
(http://cran.rproject.org/doc/manuals/Rintro.pdf)
Data Input
Lines that start with # are comments that are ignored by R. Only copy the command lines without the comments. R is case sensitive; that is, x and X or gdp and Gdp indicate different objects.
# Start R.
# Input the vectors x and h.
x < c(4, 3, 2, 7)
h < c(5, 3, 1, 7, 6, 8, 1, 9, 6, 4, 0, 2)
# The assignment operator <, which looks like an arrow, assigns
# the value to the right of it to the name on the left. The two
# vectors are now objects in the workspace of R.
# Rearrange the vector h into the 4×3 matrix A.
A < array(h, dim=c(4,3))
# There are now three objects in the workspace. The following
# command shows the names of those objects.
objects()
# The output is
# [1] “A” “h” “x”
# Remove the vector h from the workspace.
rm(h)
objects()
# The output is
# [1] “A” “x”
# Show the two objects.
x; A
# The ouput is
# [1] 4 3 2 7
# [,1] [,2] [,3]
# [1,] 5 6 6
# [2,] 3 8 4
# [3,] 1 1 0
# [4,] 7 9 2
# Note that matrix A is filled with numbers column by column. The
# elements of a vector are always listed in a row.
# Similarly, input the matrices B, C, D, E, F.
h < c(3, 5, 5, 7, 4, 9, 8, 4, 0, 1, 7, 9)
B < array(h, dim=c(3,4))
rm(h)
h < c(1, 2, 4, 5, 7, 3, 8, 1, 6, 1, 1, 3)
C < array(h, dim=c(3,4))
rm(h)
h < c(7, 4, 2, 1, 9, 5, 0, 3, 6, 1, 4, 7, 0, 2, 1, 2)
D < array(h, dim=c(4,4))
rm(h)
h < c(3, 2, 1, 4, 5, 2, 7, 9, 6, 4, 2, 8, 0, 1, 9, 3)
E < array(h, dim=c(4,4))
rm(h)
h < c(4, 6, 1, 3, 6, 2, 4, 8, 1, 4, 3, 0, 3, 8, 0, 7)
F < array(h, dim=c(4,4))
rm(h)
# There are now six matrices and one vector in the workspace.
objects()
# Show all objects.
x; A; B; C; D; E; F
# Exercise 1
# Compute K=AB, L=BA, M=CD, N=DC, P=A(B+C), R=AB+AC. Display the
# results and provide comments where appropriate.
# For example, the R code for K and P is:
K < A%*%B
K
P < A%*%(B+C)
P
# Exercise 2
# Compute S=(AB)’B’A’. The R function t produces the transpose of # a matrix. Comment.
S < t(A%*%B)t(B)%*%t(A)
S
# Exercise 3
# Find the determinants of matrices A, D and E. Call the
# determinants a, b, c. Comment where appropriate.
# Hint: One of these determinants does not exist. Also inspect the # columns of matrix E.
# Example:
a < det(A)
a
# Exercise 4
# Compute the inverses of matrices A, D and E. Call them U, V, W. # Comment where appropriate.
# Hint: See the preceding question.
Example:
U < solve(A)
U
# Exercise 5
# a) Compute the quadratic form x’Fx.
d < t(x)%*%F%*%x
d
# The following code also works because R uses vectors in whatever
# way is multiplicatively coherent. Therefore, there is no need to
# transpose x; R does it automatically.
e < x%*%F%*%x
e
# b) Compute the eigenvalues and eigenvectors of the symmetric
# matrix F.
ev < eigen(F)
ev
# The eigenvalues are the row vector and the eigenvectors are the # columns of the matrix.
# c) Retrieve the matrix of eigenvectors.
Q < ev$vec
# Compute J = Q’Q. Comment.
J = t(Q)%*%Q
J
# Hint: See the matrix whose columns are eigenvectors in the
# course handbook.
# d) What is the definiteness of the quadratic form x’Fx and
# matrix F?
# Exercise 6
objects()
# Remove all objects from the workspace.
rm(list=ls(all=TRUE))
# Check whether the workspace is now empty.
objects()
# a) Consider the linear equation system given in Bretscher
# (2009), Exercises 1.2, 17.
#
# Using matrix notations, the equation system is:
# Input the vector b and matrix A and display them. How to do this # is shown at the beginning of this assignment.
# b) Does the system have a unique solution?
# Hint: Compute the determinant of A. Is A invertible? For the R
# code see Exercise 3.
# c) Solve the system of equations.
# The following R code uses the inverse of A:
x < solve(A)%*%b
# This code is, however, numerically inefficient and potentially
# unstable. A safer and more efficient code is:
solve(A,b)
# Note: In numerical linear algebra matrix inversion is avoided.
# There are other, more efficient ways to solve a linear equation
# system.
# Finally, do some housekeeping and remove all objects.
rm(list=ls(all=TRUE))
Our Service Charter

Excellent Quality / 100% PlagiarismFree
We employ a number of measures to ensure top quality essays. The papers go through a system of quality control prior to delivery. We run plagiarism checks on each paper to ensure that they will be 100% plagiarismfree. So, only clean copies hit customers’ emails. We also never resell the papers completed by our writers. So, once it is checked using a plagiarism checker, the paper will be unique. Speaking of the academic writing standards, we will stick to the assignment brief given by the customer and assign the perfect writer. By saying “the perfect writer” we mean the one having an academic degree in the customer’s study field and positive feedback from other customers. 
Free Revisions
We keep the quality bar of all papers high. But in case you need some extra brilliance to the paper, here’s what to do. First of all, you can choose a top writer. It means that we will assign an expert with a degree in your subject. And secondly, you can rely on our editing services. Our editors will revise your papers, checking whether or not they comply with high standards of academic writing. In addition, editing entails adjusting content if it’s off the topic, adding more sources, refining the language style, and making sure the referencing style is followed. 
Confidentiality / 100% No Disclosure
We make sure that clients’ personal data remains confidential and is not exploited for any purposes beyond those related to our services. We only ask you to provide us with the information that is required to produce the paper according to your writing needs. Please note that the payment info is protected as well. Feel free to refer to the support team for more information about our payment methods. The fact that you used our service is kept secret due to the advanced security standards. So, you can be sure that no one will find out that you got a paper from our writing service. 
Money Back Guarantee
If the writer doesn’t address all the questions on your assignment brief or the delivered paper appears to be off the topic, you can ask for a refund. Or, if it is applicable, you can opt in for free revision within 1430 days, depending on your paper’s length. The revision or refund request should be sent within 14 days after delivery. The customer gets 100% moneyback in case they haven't downloaded the paper. All approved refunds will be returned to the customer’s credit card or Bonus Balance in a form of store credit. Take a note that we will send an extra compensation if the customers goes with a store credit. 
24/7 Customer Support
We have a support team working 24/7 ready to give your issue concerning the order their immediate attention. If you have any questions about the ordering process, communication with the writer, payment options, feel free to join live chat. Be sure to get a fast response. They can also give you the exact price quote, taking into account the timing, desired academic level of the paper, and the number of pages.