MATLAB Tutorial 1

Introduction 3

About this tutorial 3

About MATLAB 3

MATLAB M-Book 3

Getting help with MATLAB commands 4

Getting started with MATLAB 4

Vectors and matrices in MATLAB 8

More about M-Books 9

Simple graphics in MATLAB 9

Symbolic computation in MATLAB 15

Manipulating functions in MATLAB 18

Saving your MATLAB session 20

About the rest of this tutorial 20

Chapter 1: Classification of differential equations 21

Chapter 2: Models in one dimension 23

Section 2.1: Heat flow in a bar; Fourier's Law 23

Solving simple boundary value problems by integration 25

The MATLAB solve command 25

Chapter 3: Essential linear algebra 31

Section 3.1 Linear systems as linear operator equations 31

Section 3.2: Existence and uniqueness of solutions to Ax=b 32

Section 3.3: Basis and dimension 34

Symbolic linear algebra 37

Programming in MATLAB, part I 38

Defining a MATLAB function in an M-file. 38

Optional inputs with default values 43

Comments in M-files 44

M-files as scripts 44

Section 3.4: Orthogonal bases and projection 46

Working with the L2 inner product 46

Section 3.5: Eigenvalues and eigenvectors of a symmetric matrix 53

Numerical eigenvalues and eigenvectors 53

Symbolic eigenvalues and eigenvectors 53

Review: Functions in MATLAB 56

Chapter 4: Essential ordinary differential equations 59

Section 4.2: Solutions to some simple ODEs 59

Second-order linear homogeneous ODEs with constant coefficients 60

A special inhomogeneous second-order linear ODE 61

First-order linear ODEs 62

Section 4.3: Linear systems with constant coefficients 64

Inhomogeneous systems and variation of parameters 66

Programming in MATLAB, Part II 68

Conditional execution 69

Passing one function into another 70

Section 4.4: Numerical methods for initial value problems 72

Programming in MATLAB, part III 78

Efficient MATLAB programming 81

More about graphics in MATLAB 81

Chapter 5: Boundary value problems in statics 83

Section 5.2: Introduction to the spectral method; eigenfunctions 83

Section 5.5: The Galerkin method 88

Computing the stiffness matrix and load vector in loops 92

Section 5.6: Piecewise polynomials and the finite element method 93

Computing the load vector 95

Computing the stiffness matrix 96

The nonconstant coefficient case 99

Creating a piecewise linear function from the nodal values 100

More about sparse matrices 101

Chapter 6: Heat flow and diffusion 104

Section 6.1: Fourier series methods for the heat equation 104

Section 6.4: Finite element methods for the heat equation 107

Chapter 8: First-Order PDEs and the Method of Characteristics 110

Section 8.1: The simplest PDE and the method of characteristics 110

Two-dimensional graphics in MATLAB 110

Section 8.2: First-order quasi-linear PDEs 113

Chapter 11: Problems in multiple spatial dimensions 114

Section 11.2: Fourier series on a rectangular domain 114

Section 8.3: Fourier series on a disk 117

Graphics on the disk 118

Chapter 12: More about Fourier series 121

Section 12.1: The complex Fourier series 121

Section 9.2: Fourier series and the FFT 123

Chapter 13: More about finite element methods 125

Section 13.1 Implementation of finite element methods 125

Creating a mesh 125

Computing the stiffness matrix and the load vector 128

Testing the code 132

Using the code 136