Question 2: System of linear equations
Write your solutions in a script file, as you will need to reuse the code for the second
part of the question.
(a) Consider the system of linear equations,
. Write this
system in matrix form, Ax=b. First show whether there is a valid solution for
this system (HINT: A has to be non-singular, so the determinant should be
nonzero) then show that the system can be solved in the following ways:
I. Find the solution using MATLAB left division command “\“.
II. Find the solution by using the inverse of the coefficient matrix
III. Find the solution via the transposed system
T T AA
In this case we use the right division sign “/”
(b) Each of the equations can be rearranged in the form x3=…… Do this and then
plot each of the planes in a 3D plot. Add the point which forms the solution to
these equations and use your plot to show that the solution is the point where
all three planes intersect.
(HINT: First create your x and y axes using a vector declaration. Then you will
need to use the ‘meshgrid’ command to create two arrays. Calculate the z
arrays for each of the three cases using the same X and X arrays, then use the
‘mesh’ command to create the plots.)
(c) Now repeat the procedure in (a) and (b) for the following equations,
2 2x 10x 5
1 2 3
1 2 3
1 2 3
x x x
x x 5x
. Discuss your results using the 3D plots, as before.
Question 3: Writing scripts to calculate yields from investments, or
repayments on loans.
Each part of this question requires you to write a new script, but if you declare variables
carefully, you can reuse your code from previous steps, with some modifications. Write down
the equations you need, the variables you will need to declare, etc. before you start. This will
help A LOT!
(a) You have £1000. Write an equation in Matlab to calculate how much you will have
after 1 year. Now write a loop to calculate how much you will have if you invest it in a
long term account for 10 years with an annual interest rate of 5%. Declare variables
for the initial amount, final amount, interest rate, etc. so that it is easy to change
(b) Now consider a situation where the interest rate changes every year. Write a vector to
show the interest rate in each year, using the following data: 5%, 4%, 4.5%, 3%, 2%,
2%, 1%, 1%, 2.5%, 2%. Modify the loop you have created in (a) to calculate the cash
you will have after 10 years.
(c) Now consider a related question. How long will it take for you to double your money?
Write a script to see how many years you will need to wait to double your money.
Show your results for 5% and 7% annual interest rates.
(d) Now consider that you have a loan on your credit card of £1000. You make
repayments every month of £50. The monthly interest rate is 3%. How long will it
take you to pay back the loan?
(e) Now consider that the interest rate from part (c) goes up to 5%. Run the script again.
What happens? How should you improve the script in this case? (HINT: If you’re not
sure what is happening, show the current loan amount on the screen after each step.)
These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction
of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice.
Unethical use is strictly forbidden.
A=[1 1 5; 3 2 1; -2 1 -1];
determinantA = det(A)
str1='intersection point x';