ABSTRACT

In the previous five chapters we have discussed a

wide range of topics, from what we called “the essential

essentials” of MATLAB and Octave to the usage of various

different objects that the software provides. We have also

highlighted the flexibility that is provided by the scripting

In this chapter we present a few examples that showcase the

use of both MATLAB and Octave in context. This should

not be taken as a thorough and rigorous discussion of

the topics used, but rather as a small smörgåsbord that

represents the handling of some of the techniques discussed

earlier on in the book. We therefore recommend reading

this chapter with the help of a suitable textbook, which may

help clarify some of the concepts and ideas, as well as a

running instance of MATLAB or Octave. We have provided

some basic references in each example with the intention

of guiding you to find further information on each of the

feel

Given that the most basic object in MATLAB and

Octave is a matrix, it seems natural to use the software for

linear algebra applications first. Consider the following

and solve the corresponding linear system to find the coeffi-

c1(2, 0,−1, 7) + c2(−1, 3, 4, 7) +c3(0, 2, 5, 7) + c4(0, 1, 3, 5) = (5, 4, 12, 33). (6.7)

We can write the system of equations in terms of matrices as

Notice that matrix A is made out of the transpose of the original vectors. We solve this problem in MATLAB and

It follows that the system is consistent with the solution

and hence v is a linear combination of v1 , v2 , v3 and v4 with

A =

 ; (6.19) we would like to find its eigenvalues and eigenvectors2. 2 Strang, G. (2003). Introduction

to Linear Algebra. WellesleyCambridge PressWe need to find the values λ that satisfy the characteristic

A− λI =

=

 , (6.21) and then calculate its determinant. Using MATLAB and

(A− λI) x = 0, (6.22)

The command eig returns a diagonal matrix, lambda, that

contains the eigenvalues, and a matrix V whose columns

correspond to the eigenvectors. This means that the eigen-

λ2 = −19.6154, (6.24) λ3 = −3.7534, (6.25)

−0.456435−0.099460 −0.884180

With the aid of Equation (6.22) we can verify that the results

given by MATLAB and Octave are correct. In this case, we

can recast the equation in terms of the eigenvector v1 to verify that Av1 = λ1v1 :

the dif-

precision used you may see a different result but very close

to zero. Finally, similar relationships can be verified for the

other eigenvectors and eigenvalues, i.e. Av2 = λ2v2 and Av3 = λ3v3 .