Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
backward substitution???

Subject: backward substitution???

From: overman@math.ohio-state.edu (Ed Overman)

Date: 17 Nov, 1999 22:18:50

Message: 1 of 2



Is there an actual MATLAB command for doing back substitution. I realize
this is part of Gaussian elimination, but I have been showing my students
how to solve under- and over-determined systems by the QR decomposition.
The final linear system they have to solve is upper triangular and so I
would like them to use back substitution directly rather than \ which is
just regular Gaussian elimination.

Thanks,
Ed Overman

Subject: backward substitution???

From: Nathan Cahill

Date: 18 Nov, 1999 09:49:17

Message: 2 of 2

Ed Overman wrote:
>
> Is there an actual MATLAB command for doing back substitution. I realize
> this is part of Gaussian elimination, but I have been showing my students
> how to solve under- and over-determined systems by the QR decomposition.
> The final linear system they have to solve is upper triangular and so I
> would like them to use back substitution directly rather than \ which is
> just regular Gaussian elimination.

If you don't want to use \, I don't know that MATLAB has a command that
directly computes backward substitution. However, it is simple to write
a function to do this. The following function is a bit slower than
using \, but it does the job.

HTH,
Nathan Cahill

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function x=backsub(A,y);
% backsub: solves upper triangular system A*x = y using backwards
substitution
% usage: x=backsub(A,y);
%
% arguments:
% A (nxn) - upper triangular matrix
% y (nx1) - vector
%
% x (nx1) - solution to A*x = y

% check to see that A is upper triangular
if any(any(tril(A,-1)))
   error('A must be upper triangular')
end

% check dimensions of A and y
[n,m]=size(A);
if n~=m
   error('A must be square');
end
if any([n 1]~=size(y))
   error('y must be a vector with the same # of rows as A');
end

% perform backwards substitution
x=zeros(n,1);
x(n)=y(n)/A(n,n);
for i=n-1:-1:1
   x(i)=(y(i)-A(i,i+1:n)*x(i+1:n))/A(i,i);
end

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us