Octave for Chapter 4

The templates in this section provide sample Octave code for matrix operations and -factorization. You can access our code through the link at the bottom of each template. Feel free to modify the code and experiment to learn more!

You can write your own code using Octave software or online Octave cells. To access Octave cells online, go to the Sage Math Cell Webpage, select OCTAVE as the language, enter your code, and press EVALUATE.

To ”save” or share your online code, click on the Share button, select Permalink, then copy the address directly from the browser window. You can store this link to access your work later or share this link with others. You will need to get a new Permalink every time you modify the code.

Octave Tutorial

Basic Operations
Using Loops

We first introduced loops in Octave for Chapter 1. Examples in this section and the corresponding exercises will allow you to practice using loops while also encouraging you to delve deeper into various ways of thinking about matrix multiplication.

-factorization

Before we proceed with the code, recall that if the elementary matrices used to reduce the given matrix to row-echelon form are all lower triangular, then we can find an factorization. In general, the following theorem applies.

Octave Exercises

Let Solve in two different ways. First, use the reduced row-echelon form of , second multiply both sides of the equation by . Verify that both methods produce the same answer.
Let . Find in two different ways. First, use the inv function. Second, find .
To allow for an input matrix, you can use length to automatically detect matrix size.
            M = [A eye(length(A))]
 
        
Generate a matrix filled with ’s.
Write a routine that multiplies an matrix by an vector by computing the linear combination of the columns of the matrix, as in the following definition from Matrix Multiplication:

Recall that you can use the following code to reference the column of matrix .
    A(:,i)
 
 
Write a routine that multiplies an matrix by an matrix.
You can use this Wikipedia page for reference.
A Vandermonde matrix of order is a square matrix of the form

If you studied section Curve Fitting this matrix may look familiar to you.

Use loops to create a Vandermonde matrix for .

Use -factorization to solve the system

Text Source

Problem prob_oct_mat_lu was adapted from Problem 2.7.3(d) of Keith Nicholson’s Linear Algebra with Applications. (CC-BY-NC-SA)

W. Keith Nicholson, Linear Algebra with Applications, Lyryx 2018, Open Edition, p. 127

2024-09-28 14:48:19