tailieunhanh - Learning MATLAB Version 6 (Release 12) phần 3

Điều này chính xác phù hợp với con số trong khắc. Một khi bạn đã bước vào ma trận, nó sẽ tự động ghi nhớ trong không gian làm việc MATLAB. Bạn có thể tham khảo đơn giản là A. Bây giờ bạn có trong vùng làm việc, có một cái nhìn vào những gì làm cho nó thú vị. Tại sao nó kỳ diệu? | 4 Getting Started MATLAB displays the matrix you just entered A 16 3 2 13 5 10 11 8 9 6 7 12 4 15 14 1 This exactly matches the numbers in the engraving. Once you have entered the matrix it is automatically remembered in the MATLAB workspace. You can refer to it simply as A. Now that you have A in the workspace take a look at what makes it so interesting. Why is it magic sum transpose and diag You re probably already aware that the special properties of a magic square have to do with the various ways of summing its elements. If you take the sum along any row or column or along either of the two main diagonals you will always get the same number. Let s verify that using MATLAB. The first statement to try is sum A MATLAB replies with ans 34 34 34 34 When you don t 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 columns has the same sum the magic sum 34. How about the row sums MATLAB has a preference for working with the columns of a matrix so the easiest way to get the row sums is to transpose the matrix compute the column sums of the transpose and then transpose the result. The transpose operation is denoted by an apostrophe or single quote . It flips a matrix about its main diagonal and it turns a row vector into a column vector. So A produces 4-4 Matrices and Magic Squares ans 16 5 9 4 3 10 6 15 2 11 7 14 13 8 12 1 And sum A produces a column vector containing the row sums ans 34 34 34 34 The sum of the elements on the main diagonal is easily obtained with the help of the diag function which picks off that diagonal. diag A produces ans 16 10 7 1 and sum diag A produces ans 34 The other diagonal the so-called antidiagonal is not so important mathematically so MATLAB does not have a ready-made function for it. But a function originally intended for use in graphics fliplr flips a matrix from left to right. 4-5

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.