%%% matrices.m: to run this script noninteractively, type %%% matlab < matrices.m > matrices.out %%% %%% will dump output into file matrices.out %%% %%% contains some examples of array and matrix manipulation clc echo on %% To create a vector v = [1.0 2 3.0 4.0] %% To create a a 2x4 matrix A = [4.0 5.0 7.0 8.0; 9.0 10.0 11.0 12.0] %% To create a main diagonal matrix D = diag(v) %% Add an above main diagonal D = D + diag([pi pi pi], 1) %% Add a below main diagonal, now D is tridiagonal D = D + diag([-1 -2 -2], -1) %% Combine the blocks D and the 4x4 identity into an 8x4 matrix %% notice the answer is left in the special variable ans [D; eye(4)] %% a 3x3 matrix of all zeros (done 2 different ways) Z = zeros(3) Z = zeros(3,3) %% a matrix of all ones O = ones(2,3)