Before you approach these exercises you are expected to have worked at the exercises from the slides. In particular, the creation and maninpulation of a file in Linux, the creation of a specific matrix and the creation, saving and execution of script.
Work in small groups (eg, two persons) at the computer to solve the following exercises.
Use Matlab to solve the two systems of linear equations derived in class for the examples on electrical circuits and chemical equations:
|
|
Use MATLAB to generate random 4× 4 matrices A=rand(4) and B=rand(4). For each of the following, compute A1, A2, A3, and A4 as indicated and determine which of the matrices are equal (you can use MATLAB to test whether two matrices are equal by computing their difference):
Compare the results with the ones you would instead achive using the
Matlab-sepcific, array operations, such as .*
.
Car owners occasionally trade in their used car for a new car and marketing people are interested in the following type of question: Assume that you own a Citroen. Will your next car be another Citroen or a Volkswagen? Customers’ choices eventually determine the market share of different brands. Car dealers need estimates of how the market share of their brand (or brands) will change as a function of time. The problem can be dealt with by matrix algebra, and ends up being an exercise in matrix multiplication.
Let the index i, 1≤ i ≤ n denote car brands, in alphabetic order. That is, 1 is Alfa Romeo, 2 is Aston Martin, 3 is Bentley, and n is Toyota. Let also t=1,2, … denote time, measured in years from an arbitrary initial time, and let Fj(t) be the fraction of cars of type j traded in year t. Assume for simplicity that car owners trade their cars in every year1 and let Cij be the fraction of cars of brand j that are traded in for a new car of brand i.
As an example you will use the following data from Table 1 and 2 that are also available in electronic form from this xls file or this txt file2. (We limit ourselves to n=5 because the matrices we then have are easily visualized on a screen, there are of course more car brands). The data refer to the absolute numbers, divided by 1000, from which fractions can be derived. We will assume that the distribution of the next outcome depends only on the previous outcome and that the trading fractions are constant over time.
| Fi(t) = 1. (1) |
Repeat by initializing ℂ as you prefer, but keeping in mind the above discussed restrictions on its elements and choosing any initial distribution F(0).
Set n=200 and generate an n × n matrix and two vectors in ℝn, both having integer entries, by setting
|
|
To compare the accuracy of the two methods, we can measure how close the computed solutions x and y are to the exact solution z. Do this with the commands
|
Which method produces the most accurate solution?
Read the documentation about magic squares doc magic
. Are magic
squares singular?
Use the MATLAB command det(magic(n))
to compute the determinants of the magic squares matrices in the cases n=3,4,…, 10.
What seems to be happening?
Check the cases n=24 and n=25 to see if the pattern always holds.