Tutorial 3 -  Linear Algebra 1

generic ECE - U. Houston

                                                                                      Han Q. Le (c) copyrighted

page 1              page 2               page 3




3  General matrix dot product

3.1 Example: hypothetical portfolios

Consider that there are more than 1 client, and the shares are as follow:

In[158]:=

Tutorial_3_answer_107.gif

Now, how do we calculate the portfolio for each of them?

In[163]:=

Tutorial_3_answer_108.gif

As shown, it is straightforward: the share data are now a matrix of 3 columns for 3 clients (imagine, a brokerage may have millions of clients, and how big their share data matrix is).

This is known as matrix product ot matrix multiplication and matrix-vector dot product is just a special case of matrix dot product.

Review the Matrix Dot Product App again (see 2.4 above):

Tutorial_3_answer_110.gif

3.2 Matrix dot product associative property

What if we have this “cascade” problem:

Three bakeries purchase certain quantities of flour and eggs per week as shown below. Given the prices each week, what is the cost of each bakery each week? This is a straight forward matrix multiplication (dot).

Tutorial_3_answer_111.gif

Data matrices

Out[92]=


flour ($) eggs ($)
week 1 17.5 18.5
week 2 23.5 22.
week 3 20. 16.5
week 4 15.5 21.
bakery A bakery B bakery C
63.5 71.5 50 flour quantity
117.25 143.5 91 egg quantity

Exercise 3.1

Three bakeries purchase certain quantities of flour and eggs per week as shown. Given the prices each week, what is the cost of each bakery each week?

Answer

This is a straight forward matrix multiplication

In[93]:=

Tutorial_3_answer_112.png

Out[93]=

17.5 18.5
23.5 22.
20. 16.5
15.5 21.
.
63.5 71.5 50
117.25 143.5 91
=
3280.38 3906. 2558.5
4071.75 4837.25 3177.
3204.63 3797.75 2501.5
3446.5 4121.75 2686.

In[100]:=

Tutorial_3_answer_113.png

Out[100]=

weekly costs of the bakeries

bakery A bakery B bakery C
week 1 3280.38 3906. 2558.5
week 2 4071.75 4837.25 3177.
week 3 3204.63 3797.75 2501.5
week 4 3446.5 4121.75 2686.

Tutorial_3_answer_114.gif

Tutorial_3_answer_115.gif

Exercise 3.2

But now, we can get more into the details. There are 5 types of cakes, the quantity of flour and eggs for each type is shown below

In[166]:=

Graphics:PlotLabel /. Options[{RowBox[{RowBox[{cakes, =,
        RowBox[{{,
        RowBox[{GraphicsBox[TagBox[RasterBox[NumericArray[<33,50,4>,
        UnsignedInteger8], {{0, 33}, {50, 0}}, {0, 255}, ColorFunction
        -> RGBColor],
        BoxForm`ImageTag[System`Convert`CommonDump`ConvertText[Byte,
        System`Convert`HTMLDump`htmlsave, HTMLEntities ->
        {HTMLBasic}, AltMathOutput -> PlotLabel, WindowSize ->
        {2000, Automatic}, MathOutput -> PNG, ConvertClosed ->
        False, ConvertReverseClosed -> False, ConvertLinkedNotebooks
        -> False, CharacterEncoding -> Automatic,
        ConversionStyleEnvironment -> None, ConversionRules ->
        Automatic, HeadAttributes -> {}, HeadElements -> {}, CSS
        -> Automatic, ConvertLinkedNotebooks -> False, MathOutput
        -> GIF, GraphicsOutput -> GIF, Graphics3DOutput ->
        Automatic, ManipulateOutput -> CDF, ConvertClosed -> True,
        ConvertReverseClosed -> False, FullDocument -> True,
        AltMathOutput -> FileName, TableOutput -> {TextForm,
        Automatic}, AnimationOutput -> Automatic, FilesDirectory
        -> HTMLFiles, LinksDirectory -> HTMLLinks, HTMLEntities
        -> {HTML}, AllowBlockMathML -> False, ShowStyles ->
        True, DataUri -> False, MathMLOptions ->
        {UseUnicodePlane1Characters -> False,
        IncludeMarkupAnnotations -> False, Entities -> MathML}],
        ColorSpace -> System`Convert`CommonDump`ConvertText[RGB,
        System`Convert`HTMLDump`htmlsave, HTMLEntities ->
        {HTMLBasic}, AltMathOutput -> PlotLabel, WindowSize ->
        {2000, Automatic}, MathOutput -> PNG, ConvertClosed ->
        False, ConvertReverseClosed -> False, ConvertLinkedNotebooks
        -> False, CharacterEncoding -> Automatic,
        ConversionStyleEnvironment -> None, ConversionRules ->
        Automatic, HeadAttributes -> {}, HeadElements -> {}, CSS
        -> Automatic, ConvertLinkedNotebooks -> False, MathOutput
        -> GIF, GraphicsOutput -> GIF, Graphics3DOutput ->
        Automatic, ManipulateOutput -> CDF, ConvertClosed -> True,
        ConvertReverseClosed -> False, FullDocument -> True,
        AltMathOutput -> FileName, TableOutput -> {TextForm,
        Automatic}, AnimationOutput -> Automatic, FilesDirectory
        -> HTMLFiles, LinksDirectory -> HTMLLinks, HTMLEntities
        -> {HTML}, AllowBlockMathML -> False, ShowStyles ->
        True, DataUri -> False, MathMLOptions ->
        {UseUnicodePlane1Characters -> False,
        IncludeMarkupAnnotations -> False, Entities -> MathML}],
        Interleaving -> True], Selectable -> False],
        DefaultBaseStyle ->
        System`Convert`CommonDump`ConvertText[ImageGraphics,
        System`Convert`HTMLDump`htmlsave, HTMLEntities ->
        {HTMLBasic}, AltMathOutput -> PlotLabel, WindowSize ->
        {2000, Automatic}, MathOutput -> PNG, ConvertClosed ->
        False, ConvertReverseClosed -> False, ConvertLinkedNotebooks
        -> False, CharacterEncoding -> Automatic,
        ConversionStyleEnvironment -> None, ConversionRules ->
        Automatic, HeadAttributes -> {}, HeadElements -> {}, CSS
        -> Automatic, ConvertLinkedNotebooks -> False, MathOutput
        -> GIF, GraphicsOutput -> GIF, Graphics3DOutput ->
        Automatic, ManipulateOutput -> CDF, ConvertClosed -> True,
        ConvertReverseClosed -> False, FullDocument -> True,
        AltMathOutput -> FileName, TableOutput -> {TextForm,
        Automatic}, AnimationOutput -> Automatic, FilesDirectory
        -> HTMLFiles, LinksDirectory -> HTMLLinks, HTMLEntities
        -> {HTML}, AllowBlockMathML -> False, ShowStyles ->
        True, DataUri -> False, MathMLOptions ->
        {UseUnicodePlane1Characters -> False,
        IncludeMarkupAnnotations -> False, Entities -> MathML}],
        ImageSizeRaw -> {50, 33}, PlotRange -> {{0, 50}, {0,
        33}}], ,,
        GraphicsBox[TagBox[RasterBox[NumericArray[<75,50,4>,
        UnsignedInteger8], {{0, 75}, {50, 0}}, {0, 255}, ColorFunction
        -> RGBColor],
        BoxForm`ImageTag[System`Convert`CommonDump`ConvertText[Byte,
        System`Convert`HTMLDump`htmlsave, HTMLEntities ->
        {HTMLBasic}, AltMathOutput -> PlotLabel, WindowSize ->
        {2000, Automatic}, MathOutput -> PNG, ConvertClosed ->
        False, ConvertReverseClosed -> False, ConvertLinkedNotebooks
        -> False, CharacterEncoding -> Automatic,
        ConversionStyleEnvironment -> None, ConversionRules ->
        Automatic, HeadAttributes -> {}, HeadElements -> {}, CSS
        -> Automatic, ConvertLinkedNotebooks -> False, MathOutput
        -> GIF, GraphicsOutput -> GIF, Graphics3DOutput ->
        Automatic, ManipulateOutput -> CDF, ConvertClosed -> True,
        ConvertReverseClosed -> False, FullDocument -> True,
        AltMathOutput -> FileName, TableOutput -> {TextForm,
        Automatic}, AnimationOutput -> Automatic, FilesDirectory
        -> HTMLFiles, LinksDirectory -> HTMLLinks, HTMLEntities
        -> {HTML}, AllowBlockMathML -> False, ShowStyles ->
        True, DataUri -> False, MathMLOptions ->
        {UseUnicodePlane1Characters -> False,
        IncludeMarkupAnnotations -> False, Entities -> MathML}],
        ColorSpace -> System`Convert`CommonDump`ConvertText[RGB,
        System`Convert`HTMLDump`htmlsave, HTMLEntities ->
        {HTMLBasic}, AltMathOutput -> PlotLabel, WindowSize ->
        {2000, Automatic}, MathOutput -> PNG, ConvertClosed ->
        False, ConvertReverseClosed -> False, ConvertLinkedNotebooks
        -> False, CharacterEncoding -> Automatic,
        ConversionStyleEnvironment -> None, ConversionRules ->
        Automatic, HeadAttributes -> {}, HeadElements -> {}, CSS
        -> Automatic, ConvertLinkedNotebooks -> False, MathOutput
        -> GIF, GraphicsOutput -> GIF, Graphics3DOutput ->
        Automatic, ManipulateOutput -> CDF, ConvertClosed -> True,
        ConvertReverseClosed -> False, FullDocument -> True,
        AltMathOutput -> FileName, TableOutput -> {TextForm,
        Automatic}, AnimationOutput -> Automatic, FilesDirectory
        -> HTMLFiles, LinksDirectory -> HTMLLinks, HTMLEntities
        -> {HTML}, AllowBlockMathML -> False, ShowStyles ->
        True, DataUri -> False, MathMLOptions ->
        {UseUnicodePlane1Characters -> False,
        IncludeMarkupAnnotations -> False, Entities -> MathML}],
        Interleaving -> True], Selectable -> False],
        DefaultBaseStyle ->
        System`Convert`CommonDump`ConvertText[ImageGraphics,
        System`Convert`HTMLDump`htmlsave, HTMLEntities ->
        {HTMLBasic}, AltMathOutput -> PlotLabel, WindowSize ->
        {2000, Automatic}, MathOutput -> PNG, ConvertClosed ->
        False, ConvertReverseClosed -> False, ConvertLinkedNotebooks
        -> False, CharacterEncoding -> Automatic,
        ConversionStyleEnvironment -> None, ConversionRules ->
        Automatic, HeadAttributes -> {}, HeadElements -> {}, CSS
        -> Automatic, ConvertLinkedNotebooks -> False, MathOutput
        -> GIF, GraphicsOutput -> GIF, Graphics3DOutput ->
        Automatic, ManipulateOutput -> CDF, ConvertClosed -> True,
        ConvertReverseClosed -> False, FullDocument -> True,
        AltMathOutput -> FileName, TableOutput -> {TextForm,
        Automatic}, AnimationOutput -> Automatic, FilesDirectory
        -> HTMLFiles, LinksDirectory -> HTMLLinks, HTMLEntities
        -> {HTML}, AllowBlockMathML -> False, ShowStyles ->
        True, DataUri -> False, MathMLOptions ->
        {UseUnicodePlane1Characters -> False,
        IncludeMarkupAnnotations -> False, Entities -> MathML}],
        ImageSizeRaw -> {50, 75}, PlotRange -> {{0, 50}, {0,
        75}}], ,,
        GraphicsBox[TagBox[RasterBox[NumericArray[<45,50,4>,
        UnsignedInteger8], {{0, 45}, {50, 0}}, {0, 255}, ColorFunction
        -> RGBColor],
        BoxForm`ImageTag[System`Convert`CommonDump`ConvertText[Byte,
        System`Convert`HTMLDump`htmlsave, HTMLEntities ->
        {HTMLBasic}, AltMathOutput -> PlotLabel, WindowSize ->
        {2000, Automatic}, MathOutput -> PNG, ConvertClosed ->
        False, ConvertReverseClosed -> False, ConvertLinkedNotebooks
        -> False, CharacterEncoding -> Automatic,
        ConversionStyleEnvironment -> None, ConversionRules ->
        Automatic, HeadAttributes -> {}, HeadElements -> {}, CSS
        -> Automatic, ConvertLinkedNotebooks -> False, MathOutput
        -> GIF, GraphicsOutput -> GIF, Graphics3DOutput ->
        Automatic, ManipulateOutput -> CDF, ConvertClosed -> True,
        ConvertReverseClosed -> False, FullDocument -> True,
        AltMathOutput -> FileName, TableOutput -> {TextForm,
        Automatic}, AnimationOutput -> Automatic, FilesDirectory
        -> HTMLFiles, LinksDirectory -> HTMLLinks, HTMLEntities
        -> {HTML}, AllowBlockMathML -> False, ShowStyles ->
        True, DataUri -> False, MathMLOptions ->
        {UseUnicodePlane1Characters -> False,
        IncludeMarkupAnnotations -> False, Entities -> MathML}],
        ColorSpace -> System`Convert`CommonDump`ConvertText[RGB,
        System`Convert`HTMLDump`htmlsave, HTMLEntities ->
        {HTMLBasic}, AltMathOutput -> PlotLabel, WindowSize ->
        {2000, Automatic}, MathOutput -> PNG, ConvertClosed ->
        False, ConvertReverseClosed -> False, ConvertLinkedNotebooks
        -> False, CharacterEncoding -> Automatic,
        ConversionStyleEnvironment -> None, ConversionRules ->
        Automatic, HeadAttributes -> {}, HeadElements -> {}, CSS
        -> Automatic, ConvertLinkedNotebooks -> False, MathOutput
        -> GIF, GraphicsOutput -> GIF, Graphics3DOutput ->
        Automatic, ManipulateOutput -> CDF, ConvertClosed -> True,
        ConvertReverseClosed -> False, FullDocument -> True,
        AltMathOutput -> FileName, TableOutput -> {TextForm,
        Automatic}, AnimationOutput -> Automatic, FilesDirectory
        -> HTMLFiles, LinksDirectory -> HTMLLinks, HTMLEntities
        -> {HTML}, AllowBlockMathML -> False, ShowStyles ->
        True, DataUri -> False, MathMLOptions ->
        {UseUnicodePlane1Characters -> False,
        IncludeMarkupAnnotations -> False, Entities -> MathML}],
        Interleaving -> True], Selectable -> False],
        DefaultBaseStyle ->
        System`Convert`CommonDump`ConvertText[ImageGraphics,
        System`Convert`HTMLDump`htmlsave, HTMLEntities ->
        {HTMLBasic}, AltMathOutput -> PlotLabel, WindowSize ->
        {2000, Automatic}, MathOutput -> PNG, ConvertClosed ->
        False, ConvertReverseClosed -> False, ConvertLinkedNotebooks
        -> False, CharacterEncoding -> Automatic,
        ConversionStyleEnvironment -> None, ConversionRules ->
        Automatic, HeadAttributes -> {}, HeadElements -> {}, CSS
        -> Automatic, ConvertLinkedNotebooks -> False, MathOutput
        -> GIF, GraphicsOutput -> GIF, Graphics3DOutput ->
        Automatic, ManipulateOutput -> CDF, ConvertClosed -> True,
        ConvertReverseClosed -> False, FullDocument -> True,
        AltMathOutput -> FileName, TableOutput -> {TextForm,
        Automatic}, AnimationOutput -> Automatic, FilesDirectory
        -> HTMLFiles, LinksDirectory -> HTMLLinks, HTMLEntities
        -> {HTML}, AllowBlockMathML -> False, ShowStyles ->
        True, DataUri -> False, MathMLOptions ->
        {UseUnicodePlane1Characters -> False,
        IncludeMarkupAnnotations -> False, Entities -> MathML}],
        ImageSizeRaw -> {50, 45}, PlotRange -> {{0, 50}, {0,
        45}}], ,,
        GraphicsBox[TagBox[RasterBox[NumericArray[<38,50,4>,
        UnsignedInteger8], {{0, 38}, {50, 0}}, {0, 255}, ColorFunction
        -> RGBColor],
        BoxForm`ImageTag[System`Convert`CommonDump`ConvertText[Byte,
        System`Convert`HTMLDump`htmlsave, HTMLEntities ->
        {HTMLBasic}, AltMathOutput -> PlotLabel, WindowSize ->
        {2000, Automatic}, MathOutput -> PNG, ConvertClosed ->
        False, ConvertReverseClosed -> False, ConvertLinkedNotebooks
        -> False, CharacterEncoding -> Automatic,
        ConversionStyleEnvironment -> None, ConversionRules ->
        Automatic, HeadAttributes -> {}, HeadElements -> {}, CSS
        -> Automatic, ConvertLinkedNotebooks -> False, MathOutput
        -> GIF, GraphicsOutput -> GIF, Graphics3DOutput ->
        Automatic, ManipulateOutput -> CDF, ConvertClosed -> True,
        ConvertReverseClosed -> False, FullDocument -> True,
        AltMathOutput -> FileName, TableOutput -> {TextForm,
        Automatic}, AnimationOutput -> Automatic, FilesDirectory
        -> HTMLFiles, LinksDirectory -> HTMLLinks, HTMLEntities
        -> {HTML}, AllowBlockMathML -> False, ShowStyles ->
        True, DataUri -> False, MathMLOptions ->
        {UseUnicodePlane1Characters -> False,
        IncludeMarkupAnnotations -> False, Entities -> MathML}],
        ColorSpace -> System`Convert`CommonDump`ConvertText[RGB,
        System`Convert`HTMLDump`htmlsave, HTMLEntities ->
        {HTMLBasic}, AltMathOutput -> PlotLabel, WindowSize ->
        {2000, Automatic}, MathOutput -> PNG, ConvertClosed ->
        False, ConvertReverseClosed -> False, ConvertLinkedNotebooks
        -> False, CharacterEncoding -> Automatic,
        ConversionStyleEnvironment -> None, ConversionRules ->
        Automatic, HeadAttributes -> {}, HeadElements -> {}, CSS
        -> Automatic, ConvertLinkedNotebooks -> False, MathOutput
        -> GIF, GraphicsOutput -> GIF, Graphics3DOutput ->
        Automatic, ManipulateOutput -> CDF, ConvertClosed -> True,
        ConvertReverseClosed -> False, FullDocument -> True,
        AltMathOutput -> FileName, TableOutput -> {TextForm,
        Automatic}, AnimationOutput -> Automatic, FilesDirectory
        -> HTMLFiles, LinksDirectory -> HTMLLinks, HTMLEntities
        -> {HTML}, AllowBlockMathML -> False, ShowStyles ->
        True, DataUri -> False, MathMLOptions ->
        {UseUnicodePlane1Characters -> False,
        IncludeMarkupAnnotations -> False, Entities -> MathML}],
        Interleaving -> True], Selectable -> False],
        DefaultBaseStyle ->
        System`Convert`CommonDump`ConvertText[ImageGraphics,
        System`Convert`HTMLDump`htmlsave, HTMLEntities ->
        {HTMLBasic}, AltMathOutput -> PlotLabel, WindowSize ->
        {2000, Automatic}, MathOutput -> PNG, ConvertClosed ->
        False, ConvertReverseClosed -> False, ConvertLinkedNotebooks
        -> False, CharacterEncoding -> Automatic,
        ConversionStyleEnvironment -> None, ConversionRules ->
        Automatic, HeadAttributes -> {}, HeadElements -> {}, CSS
        -> Automatic, ConvertLinkedNotebooks -> False, MathOutput
        -> GIF, GraphicsOutput -> GIF, Graphics3DOutput ->
        Automatic, ManipulateOutput -> CDF, ConvertClosed -> True,
        ConvertReverseClosed -> False, FullDocument -> True,
        AltMathOutput -> FileName, TableOutput -> {TextForm,
        Automatic}, AnimationOutput -> Automatic, FilesDirectory
        -> HTMLFiles, LinksDirectory -> HTMLLinks, HTMLEntities
        -> {HTML}, AllowBlockMathML -> False, ShowStyles ->
        True, DataUri -> False, MathMLOptions ->
        {UseUnicodePlane1Characters -> False,
        IncludeMarkupAnnotations -> False, Entities -> MathML}],
        ImageSizeRaw -> {50, 38}, PlotRange -> {{0, 50}, {0,
        38}}], ,,
        GraphicsBox[TagBox[RasterBox[NumericArray[<75,50,4>,
        UnsignedInteger8], {{0, 75}, {50, 0}}, {0, 255}, ColorFunction
        -> RGBColor],
        BoxForm`ImageTag[System`Convert`CommonDump`ConvertText[Byte,
        System`Convert`HTMLDump`htmlsave, HTMLEntities ->
        {HTMLBasic}, AltMathOutput -> PlotLabel, WindowSize ->
        {2000, Automatic}, MathOutput -> PNG, ConvertClosed ->
        False, ConvertReverseClosed -> False, ConvertLinkedNotebooks
        -> False, CharacterEncoding -> Automatic,
        ConversionStyleEnvironment -> None, ConversionRules ->
        Automatic, HeadAttributes -> {}, HeadElements -> {}, CSS
        -> Automatic, ConvertLinkedNotebooks -> False, MathOutput
        -> GIF, GraphicsOutput -> GIF, Graphics3DOutput ->
        Automatic, ManipulateOutput -> CDF, ConvertClosed -> True,
        ConvertReverseClosed -> False, FullDocument -> True,
        AltMathOutput -> FileName, TableOutput -> {TextForm,
        Automatic}, AnimationOutput -> Automatic, FilesDirectory
        -> HTMLFiles, LinksDirectory -> HTMLLinks, HTMLEntities
        -> {HTML}, AllowBlockMathML -> False, ShowStyles ->
        True, DataUri -> False, MathMLOptions ->
        {UseUnicodePlane1Characters -> False,
        IncludeMarkupAnnotations -> False, Entities -> MathML}],
        ColorSpace -> System`Convert`CommonDump`ConvertText[RGB,
        System`Convert`HTMLDump`htmlsave, HTMLEntities ->
        {HTMLBasic}, AltMathOutput -> PlotLabel, WindowSize ->
        {2000, Automatic}, MathOutput -> PNG, ConvertClosed ->
        False, ConvertReverseClosed -> False, ConvertLinkedNotebooks
        -> False, CharacterEncoding -> Automatic,
        ConversionStyleEnvironment -> None, ConversionRules ->
        Automatic, HeadAttributes -> {}, HeadElements -> {}, CSS
        -> Automatic, ConvertLinkedNotebooks -> False, MathOutput
        -> GIF, GraphicsOutput -> GIF, Graphics3DOutput ->
        Automatic, ManipulateOutput -> CDF, ConvertClosed -> True,
        ConvertReverseClosed -> False, FullDocument -> True,
        AltMathOutput -> FileName, TableOutput -> {TextForm,
        Automatic}, AnimationOutput -> Automatic, FilesDirectory
        -> HTMLFiles, LinksDirectory -> HTMLLinks, HTMLEntities
        -> {HTML}, AllowBlockMathML -> False, ShowStyles ->
        True, DataUri -> False, MathMLOptions ->
        {UseUnicodePlane1Characters -> False,
        IncludeMarkupAnnotations -> False, Entities -> MathML}],
        Interleaving -> True], Selectable -> False],
        DefaultBaseStyle ->
        System`Convert`CommonDump`ConvertText[ImageGraphics,
        System`Convert`HTMLDump`htmlsave, HTMLEntities ->
        {HTMLBasic}, AltMathOutput -> PlotLabel, WindowSize ->
        {2000, Automatic}, MathOutput -> PNG, ConvertClosed ->
        False, ConvertReverseClosed -> False, ConvertLinkedNotebooks
        -> False, CharacterEncoding -> Automatic,
        ConversionStyleEnvironment -> None, ConversionRules ->
        Automatic, HeadAttributes -> {}, HeadElements -> {}, CSS
        -> Automatic, ConvertLinkedNotebooks -> False, MathOutput
        -> GIF, GraphicsOutput -> GIF, Graphics3DOutput ->
        Automatic, ManipulateOutput -> CDF, ConvertClosed -> True,
        ConvertReverseClosed -> False, FullDocument -> True,
        AltMathOutput -> FileName, TableOutput -> {TextForm,
        Automatic}, AnimationOutput -> Automatic, FilesDirectory
        -> HTMLFiles, LinksDirectory -> HTMLLinks, HTMLEntities
        -> {HTML}, AllowBlockMathML -> False, ShowStyles ->
        True, DataUri -> False, MathMLOptions ->
        {UseUnicodePlane1Characters -> False,
        IncludeMarkupAnnotations -> False, Entities -> MathML}],
        ImageSizeRaw -> {50, 75}, PlotRange -> {{0, 50}, {0,
        75}}]}], }}]}], ;}], , ingrmat = {{0., 0.3, 0.1, 0.5, 0.4},
        {0.75, 0.25, 0.5, 0.2, 0.6}} ;, , Grid[MapThread[Prepend,
        {Join[{cakes}, ingrmat] , {, flour quantity, egg quantity}}],
        Frame-&gt;All]}]

Out[168]=


Tutorial_3_answer_117.gif Tutorial_3_answer_118.gif Tutorial_3_answer_119.gif Tutorial_3_answer_120.gif Tutorial_3_answer_121.gif
flour quantity 0. 0.3 0.1 0.5 0.4
egg quantity 0.75 0.25 0.5 0.2 0.6

And the daily quantities of each cake produced by the bakeries are as follow:

In[169]:=

Tutorial_3_answer_122.gif

Out[170]=

bakery A bakery B bakery C
55 70 40 Tutorial_3_answer_123.gif
80 50 40 Tutorial_3_answer_124.gif
30 45 30 Tutorial_3_answer_125.gif
25 40 30 Tutorial_3_answer_126.gif
60 80 50 Tutorial_3_answer_127.gif

What are the daily ingredient demands of the bakeries?

Answer

This is what gives the net four and egg demands of the bakeries each week:

In[171]:=

Tutorial_3_answer_128.png

Out[171]=

bakery A bakery B bakery C
63.5 71.5 50. flour quantity
117.25 143.5 91. egg quantity

This is what we did:

In[172]:=

Tutorial_3_answer_129.gif

Out[173]=

63.5 71.5 50.
117.25 143.5 91.

Then, we multiply the price matrix to the demand matrix to get the cost matrix for the 3 bakeries:

In[95]:=

Tutorial_3_answer_130.png

Out[95]=

3280.38 3906. 2558.5
4071.75 4837.25 3177.
3204.63 3797.75 2501.5
3446.5 4121.75 2686.

End exercise

Tutorial_3_answer_131.gif

Tutorial_3_answer_132.gif

In other words: costmatrix = pricematrix . demandmatrix
                       costmatrix = pricematrix . (ingredientmatrix .  bakeryproductionmatrix)
                         4 × 3                 4×2           (      2×5                               5×3        )

However, can we do this?
                       costmatrix = (pricematrix . ingredientmatrix)  .  bakeryproductionmatrix

because pricematrix . ingredientmatrix = cakeunitcostmatrix
and the total cost can also be obtained by multiplying cake unit cost with the cake production matrix. This is the cake unit cost

Exercise 3.3

Find the weekly cost of each type of cake, based on the weekly price of the ingredients and the ingredient requirement of each cake type.

Answer

In[85]:=

Tutorial_3_answer_133.png

Out[85]=


flour ($) eggs ($)
week 1 34. 33.
week 2 31. 30.5
week 3 37.5 35.5
week 4 30. 38.
Tutorial_3_answer_134.gif Tutorial_3_answer_135.gif Tutorial_3_answer_136.gif Tutorial_3_answer_137.gif Tutorial_3_answer_138.gif
0. 0.3 0.1 0.5 0.4 flour quantity
0.75 0.25 0.5 0.2 0.6 egg quantity

In[177]:=

Tutorial_3_answer_139.gif

Out[178]=

cost of each cake each week

Tutorial_3_answer_140.gif Tutorial_3_answer_141.gif Tutorial_3_answer_142.gif Tutorial_3_answer_143.gif Tutorial_3_answer_144.gif
week 1 13.875 9.875 11. 12.45 18.1
week 2 16.5 12.55 13.35 16.15 22.6
week 3 12.375 10.125 10.25 13.3 17.9
week 4 15.75 9.9 12.05 11.95 18.8

End exercise

If we know the weekly ingredient cost of each type of cake, and we know how many cakes of each type each bakery makes daily, then, can we find the net weekly ingredient costs of the bakeries? This is the next exercise

Exercise 3.3

Find the weekly ingredient costs of the bakeries, based on the weekly ingredient cost of each type of cake, and the quantities of cakes of the bakeries.

Answer

We can just multiply this with a # of cakes produced by each bakery per week to get the cost

Tutorial_3_answer_145.png

In[179]:=

Tutorial_3_answer_146.gif

Out[180]=

3280.38 3906. 2558.5
4071.75 4837.25 3177.
3204.63 3797.75 2501.5
3446.5 4121.75 2686.

End exercise

Clearly:  
              Tutorial_3_answer_147.gif

In other words, there are more than one way to cut a cake. We can calculate the total flour and egg demand of each bakery per week, and multiply the ingredient prices to get the cost
                                            OR
we can multiply the ingredient amount of each cake with the weekly ingredient price to get the weekly cost of each cake, and multiply to the production volume of the cakes.
Both give the same result.

Mathematically, what it means is that for 3 matrices A, B, C:
                                 (A . B) . C = A . (B . C)
This is known as associative property. From now on, we don’t have to use parentheses when multiplying many matrices together.

Tutorial_3_answer_148.gif

Tutorial_3_answer_149.gif

In[141]:=

Tutorial_3_answer_150.gif

Out[145]=

A.B
C
(A.B).C
Tutorial_3_answer_151.png . Tutorial_3_answer_152.png = Tutorial_3_answer_153.png
A
B.C
A.(B.C)
Tutorial_3_answer_154.png . Tutorial_3_answer_155.png = Tutorial_3_answer_156.png

Exercise 3.4

Do a demonstration similar to the above to show the associative property of dot product. It is OK to copy and paste the code. But you must choose the range of random integer and the matrix dimensions according to this:
Range of random integer {-r, r} where r is the 2nd largest digit of your Student ID, but not smaller than 3. For example 1094724 is your ID. The second largest digit is 7 (9 is the largest).
For matrix dimensions, we need this: {m, n},{n, p},{p, q}
Let m=3rd largest digit of your ID, but not smaller than 3, n=Min[8, birth month +2], p=Max[3,Floor[birth date/4.]], q=Max[2,Ceiling[last digit birth year/2]].
If you cannot calculate, use the App below (but you should verify to understand and know why the results are what they are).

In[203]:=

Tutorial_3_answer_157.png

Out[203]=

Answer

In[204]:=

Tutorial_3_answer_159.gif

Out[208]=

A.B
C
(A.B).C
Tutorial_3_answer_160.png . Tutorial_3_answer_161.png = Tutorial_3_answer_162.png
A
B.C
A.(B.C)
Tutorial_3_answer_163.png . Tutorial_3_answer_164.png = Tutorial_3_answer_165.png

3.3 Transpose theorem

One more frequently-used property is:
                                       Tutorial_3_answer_166.png

In[154]:=

Tutorial_3_answer_167.gif

Out[157]=

A B A.B Tutorial_3_answer_168.png
Tutorial_3_answer_169.png Tutorial_3_answer_170.png Tutorial_3_answer_171.png Tutorial_3_answer_172.png
Tutorial_3_answer_173.png Tutorial_3_answer_174.png
Tutorial_3_answer_175.png
Tutorial_3_answer_176.png Tutorial_3_answer_177.png
Tutorial_3_answer_178.png

Exercise 3.5

Do a demonstration of the transpose theorem like above, but matA and matB are based on your range and dimension from Exercise 3.4.

Answer

In[209]:=

Tutorial_3_answer_179.gif

Out[212]=

A B A.B Tutorial_3_answer_180.png
Tutorial_3_answer_181.png Tutorial_3_answer_182.png Tutorial_3_answer_183.png Tutorial_3_answer_184.png
Tutorial_3_answer_185.png Tutorial_3_answer_186.png
Tutorial_3_answer_187.png
Tutorial_3_answer_188.png Tutorial_3_answer_189.png
Tutorial_3_answer_190.png

End exercise

Tutorial_3_answer_191.gif

Tutorial_3_answer_192.gif

3.4  Serious and common errors

In[9]:=

Tutorial_3_answer_193.png

Out[9]=

Tutorial_3_answer_194.png

In[10]:=

Tutorial_3_answer_195.gif

Out[11]//MatrixForm=

Tutorial_3_answer_196.png

Shoud we do vt3 . matx3 or matx3 . vt3?

In[12]:=

Tutorial_3_answer_197.png

Tutorial_3_answer_198.png

Out[12]=

Tutorial_3_answer_199.png

Error because we are doing this:

Tutorial_3_answer_200.png

The number of row must match with the number of column. We should do this instead:
Tutorial_3_answer_201.png

In[13]:=

Tutorial_3_answer_202.png

Out[13]=

Tutorial_3_answer_203.png

The rule is simple:

In[14]:=

Tutorial_3_answer_204.png

Out[14]=

Tutorial_3_answer_205.png

If we have a vector of length 5, it should be on the left side of the matrix. If length 3, it should be on the right side. The actual orientation, row or column doesn’t matter, because Mathematica knows that if it is on the left, it is automatically row, and column if on the right. Hence:

In[15]:=

Tutorial_3_answer_206.png

Out[15]=

Tutorial_3_answer_207.png

But the above is not the worst error, because it tells us if there is an error. This is actually worse:

In[16]:=

Tutorial_3_answer_208.gif

Out[17]//MatrixForm=

Tutorial_3_answer_209.png

now

In[18]:=

Tutorial_3_answer_210.png

Out[18]=

Tutorial_3_answer_211.png

In[19]:=

Tutorial_3_answer_212.png

Out[19]=

Tutorial_3_answer_213.png

The above are totally different, but there is no execution error warning. This type of hidden bug is far more serious. It is up to the programmer to determine which one is correct.

Exercise 3.6

Generate an {m,n} matrix and an{n,p} of your choice, such that n≠m≠p.
Try to dot {n,p} to {m,n} and observe error. Then, do the dot the correct order to obtain answer.

Answer

3.5  Inverse matrix and determinant

Consider this problem:

Tutorial_3_answer_214.png

the items purchased are Tutorial_3_answer_215.png

Consider that the cost ($) for the above purchase is: Tutorial_3_answer_216.png

What are the prices of apple, orange, and pear? This is the equation:

Tutorial_3_answer_217.png

How do we solve?

In[39]:=

Tutorial_3_answer_218.png

Out[39]=

Tutorial_3_answer_219.png

The linear algebraic way to do it is to take the inverse matrix:
                        Tutorial_3_answer_220.png
    Tutorial_3_answer_221.png
By definition:
          Tutorial_3_answer_222.png
Hence:          
    Tutorial_3_answer_223.png    
                     Tutorial_3_answer_224.png            

In[40]:=

Tutorial_3_answer_225.png

Out[40]=

Tutorial_3_answer_226.png

indeed, these are the prices.

Tutorial_3_answer_227.gif

Tutorial_3_answer_228.gif

Exercise 3.7

Create 2 equations with 2 unknowns, use inverse matrix to solve it.

Answer

Problem 3.8

Consider this circuit:

Tutorial_3_answer_229.gif

Solve for its response. Find  steady-state voltage Tutorial_3_answer_230.png for harmonic Tutorial_3_answer_231.png and Tutorial_3_answer_232.png of arbitrary input frequency, amplitude, and relative phase.

Answer given

The mesh-current equations of the Laplace-transformed circuit is:

Tutorial_3_answer_233.png     

where Tutorial_3_answer_234.png is the initial current in Tutorial_3_answer_235.png inductor, and Tutorial_3_answer_236.png is the initial voltage of Tutorial_3_answer_237.png capacitor.

Define     Tutorial_3_answer_238.png
We can write the Laplace-transformed mesh current simply:
                            Tutorial_3_answer_239.png           
we can find Tutorial_3_answer_240.png although it is rather messy:

In[21]:=

Tutorial_3_answer_241.png

Out[23]//TraditionalForm=

Tutorial_3_answer_242.png

It is much easier to look at with substituted numerical values for the components

In[2]:=

Tutorial_3_answer_243.png

Out[4]//TraditionalForm=

Tutorial_3_answer_244.png

Out[6]//TraditionalForm=

Tutorial_3_answer_245.png

Out[8]//TraditionalForm=

Tutorial_3_answer_246.png

Out[11]//TraditionalForm=

Tutorial_3_answer_247.png

Out[12]=

Tutorial_3_answer_248.png

Out[13]=

Tutorial_3_answer_249.gif

The roots indicate the transient responses, which can be overdamped, underdamped, or critically damped.

If we are interested only steady state solutions, we can ignore all the transient terms. Start with:

In[264]:=

Tutorial_3_answer_250.gif

Out[267]//TraditionalForm=

Tutorial_3_answer_251.png

Then, because we care only for steady-state solutions, we can also ignore and make all the initial conditions such as current Tutorial_3_answer_252.png in inductors and voltage Tutorial_3_answer_253.png in capacitors to be zero. Then:
      Tutorial_3_answer_254.png    
The mes current vector Tutorial_3_answer_255.png is obtained by Inverse-Laplace transforming Tutorial_3_answer_256.png

Demo of numerical calculation

                  

End exercise

Can we take the inverse of this?

In[46]:=

Tutorial_3_answer_258.gif

Out[47]//MatrixForm=

Tutorial_3_answer_259.png

In[48]:=

Tutorial_3_answer_260.png

Tutorial_3_answer_261.png

Out[48]=

Tutorial_3_answer_262.png

Exercise 3.9

Generate an non-square {m,n} matrix, denote it A. Take the inverse of A and see what happens.
Then define a new matrice:               Tutorial_3_answer_263.png      and      Tutorial_3_answer_264.png   
Which one, P or Q has inverse, which one doesn’t, and can you explain or guess why one does and the other doesn’t?

Answer

End exercise

By its definition, only square matrix can be inversed.

Note, by theorem, if  Tutorial_3_answer_265.png, where I is the identity matrix, then:
                Tutorial_3_answer_266.png  ,          Tutorial_3_answer_267.png    ,     and    Tutorial_3_answer_268.png
These theorems simply follow the associative and transpose properties. For example:
Given A, let Tutorial_3_answer_269.png and Tutorial_3_answer_270.png be such that:  A . Tutorial_3_answer_271.png = I  and  Tutorial_3_answer_272.png = I
Then,            Tutorial_3_answer_273.png .  (A . Tutorial_3_answer_274.png) = Tutorial_3_answer_275.png . I  = Tutorial_3_answer_276.png
By associative:      Tutorial_3_answer_277.png . A) . Tutorial_3_answer_278.png =  Tutorial_3_answer_279.png
                                    I .  Tutorial_3_answer_280.png =  Tutorial_3_answer_281.png  or  Tutorial_3_answer_282.png =  Tutorial_3_answer_283.png

One important quantity of a square matrix is determinant. In Mathematica, Det[] gives the determinant of a matrix.

Demo: statistical property (Gaussian -> Laplacian distribution) of det of random matrix

In[85]:=

Tutorial_3_answer_284.gif

                         






Back to:  page 1       page 2

Created with the Wolfram Language