MATLAB POLYSPACE RELEASE NOTES Bedienungsanleitung Seite 27

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 240
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 26
Matrices and Mag ic Squares
MATLAB displays the matrix you just ente red:
A=
163213
51011 8
96712
41514 1
This matrix matches the num bers in the engraving. Once you have entered
the matrix, it is automatically remembered in the M ATLAB w orkspace. You
can r efer to it simply as
A.NowthatyouhaveA intheworkspace,takealook
at what makes it so interesting. W hy is it magic?
sum, transpose, and diag
You are probably already aware that the special properties o f a magic square
have to do with the various ways of summing its elements. If y ou take the
sum along any row or column, or along either of the two main diagonals,
you will always get the same number. Let us verify that using M ATLAB.
The first statem ent to try is
sum(A)
MATLAB replies with
ans =
34 34 34 34
When you do not specify an output variable, MATLAB uses the variable ans,
short for answer, to store the results of a calculation. You have computed a
row vector containing the sums of the columns of
A. Sure enough, each of the
columnshasthesamesum,themagic sum, 34.
How about the row sums? MATLAB has a p reference for working with the
columnsofamatrix,soonewaytogettherowsumsistotransposethe
matrix, compute the column sums of the transpose, and then transpose the
result. For an additional way that avoids the double transpose use the
dimension argument for the
sum function.
MATLAB has two transpose operators. The apostrophe operator (e.g.,
A')
performs a complex conjugate transposition. It flips a matrix about its main
2-5
Seitenansicht 26
1 2 ... 22 23 24 25 26 27 28 29 30 31 32 ... 239 240

Kommentare zu diesen Handbüchern

Keine Kommentare