5.6 Miscellaneous

It is possible to place a matrix valued function as the condition of a branching construction or while loop. However one must be careful! Consider the construction

if A~=B, program, end

You would like program to execute if the matrices A and B differ i some entry. Under the convention, program will only execute when they differ on all entries. There are some ways around this problem. One is the construction

if A==B, else program, end

which will pass control to the "else" part if A and B differ on at least one entry. Another solution is to convert A==B into a binary valued functionm by using all(all(A==B)). The inside all creates a binary vector whose ith entry is 1 only if the ith column of A is the same as the ith column of B. The outside all produces a 1 if all the entries of the vector are 1. Thus if A and B differ on at least one entry, then all(all(A==B))=0. The construction

if ~all(all(A==B))), program, end

then behaves in the desired way.

Next Section: 5.7 Scripts


Created by F.G. Garvan (fgarvan@ufl.edu) on Wed, Oct 01, 97
Last update made Thu Oct 2 11:22:26 EDT 1997.
Back to 5.5 Recursion
Back to Table of Contents
EMAIL: fgarvan@ufl.edu fgarvan@ufl.edu