function y = BackwardSub(A,b) % The function solves a system of linear equations ax = b % where a is an upper triangular matrix by using back substitution. % Input variables: % a The matrix of coefficients. % b A column vector of constants. % Output variable: % y A column vector with the solution. n=length(b); y(n,1)=b(n)/A(n,n); for i=n-1:-1:1 y(i,1)=(b(i)-A(i,i+1:n)*y(i+1:n,1)) ./A(i,i); end