Download Using MATLAB for analysing generalised linear models
Transcript
CHAPTER 2. STARTING WITH MATLAB >> A + B’ ans = 1 2 6 4 8 15 >> A - B’ ans = 1 0 -4 -4 -4 3 >> A * B ans = 21 54 5 27 51 >> inv( A * B ) ans = -0.1318 0.0698 0.1395 -0.0543 There are other operations in MATLAB apart from the standard operations. Preceding an operation with a period (.) causes the operation to be applied on an element by element basis. For example, consider the following commands: >> C = [0 -3 4; 5 -4 3] C = 0 -3 4 5 -4 3 >> D = [1 1 9; -3 0 1] D = 1 1 9 -3 0 1 >> C * D ??? Error using ==> * Inner matrix dimensions must agree. >> C .* D ans = 0 -3 -15 0 36 3 Here’s another example of MATLAB’s element by element procedure: >> E = [1:4] E = 1 2 3 4 >> E * E ??? Error using ==> * Inner matrix dimensions must agree. >> E ˆ2 ??? Error using ==> ˆ Matrix must be square. >> E .ˆ 2 ans = 1 4 9 16 %Eˆ2 is the same as E*E