clc echo on % Example 3 % % Basic Matrix Operations % % Matrix Creation A = [1 2; 4 3] size(A) A(2,1) B = [ 1 3 0 -1 ] % Scalar Multiplication % multiply each element in the matrix by the scalar. % 2*A (-3)*B pause clc % Matrix Addition % The matrices must be the same size, % then add corresponding elements. % A = [1 2 3; 1 0 -1] B = [1 1 1; 3 2 1] A+B pause clc % Linear Combinations % Combines scalar multiplication and matrix addition % A = [ 1 2 4 3 ] B = [ 1 3 0 -1 ] 2*A - 3*B pause % Linear Combinations of Vectors % x = [1; 2; 3] y = [1 0 -1]' 2*x - 3*y pause % Matrix Multiplication % A = [1 2; 4 3] B = [1 0 1; 0 -1 2] A*B % Inner Product % x' * y % Outer Product % x * y' pause clc % Solving a system of linear equations % A = [3 2 -1; 1 -1 0; 0 5 1] y = [5; 6; 1] % Solve A*x = y % x = A\y format short e residual = A*x - y pause % The LU factorization % [L, U, P] = lu(A) pause clc % This factorization always exists % Even if the system can't be solved % C = [1 2 3; 1 0 -1; 1 1 1] [L, U, P] = lu(C) echo off