tailieunhanh - MATLAB Demystified phần 2

Tôi thậm chí không thực hiện tất cả các tính năng mảng. Làm thế nào tôi sẽ thực hiện SHIFT, UNSHIFT, hoặc mối nối? Dưới đây là một gợi ý: hãy nhớ rằng Perl đã làm điều này cho các mảng và chuỗi thực. Thay vì chuyển các thứ trên mỗi khi tôi ảnh hưởng đến mặt trước của các dữ liệu, theo dõi nơi mà nó bắt đầu, mà có thể không là sự khởi đầu của dữ liệu. | CHAPTER 2 Vectors and Matrices If we just compute the sum of the vector multiplication as we did in the previous example we get a complex number that won t work sum u. u ans 12. So let s define another vector which is the complex conjugate transpose of u. MATLAB does this automatically with the transpose operator v u v 0 - - Now we can perform our sum b sum v. u Error using times Matrix dimensions must agree. Unfortunately it looks like we ve been led down a blind alley It appears there isn t quite a one to one correspondence to what we would do on paper. How can we get around this Let s just compute the complex conjugate of the vector and form the sum. We can get the complex conjugate of a vector with the conj command v conj u v 0 - - Now we obtain the correct answer and can get the magnitude b sum v. u b 22 magu sqrt b magu Of course this could all be done in one step by writing c sqrt sum conj u . u c T- 24 MATLAB Demystified Here we are actually doing things the hard way just to illustrate the method and some MATLAB commands. In the next section we will see how to compute the magnitude of a vector automatically. We can use the abs command to return the absolute value of a vector which is a vector whose elements are the absolute values of the elements in the original vector . A -2 0 -1 9 B abs A B 2 0 1 9 Vector Dot and Cross Products The dot product between two vectors A a1 a2 . an and B b1 b2 . bn is given by A B y ab i i i In MATLAB the dot product of two vectors a b can be calculated using the dot a b command. The dot product between two vectors is a scalar . it s just a number. Let s compute a simple example using MATLAB a 1 4 7 b 2 -1 5 c dot a b c 33 The dot product can be used to calculate the magnitude of a vector. All that needs to be done is to pass the same vector to both arguments. Consider the vector in the last section J 0 3 4 Calling dot we obtain dot J J ans 25 .

TỪ KHÓA LIÊN QUAN