Basic Learning of MATLAB -------- relational and logical operations and polynomial operations

Source: Internet
Author: User

An instance is provided directly. The instance contains instructions on knowledge points:

% Relational operator % <<=>== ~ = (Not equal to) % compare the values of the Chinese learning elements in the cube matrix to 4%. cube matrix: the sum of each column and two diagonal lines in the matrix is equal. A = magic (3) % generate a 3*3 cube matrix A> 4 * ones (3) % to compare with a matrix of all 4 magic (6) % generate 6x6 cube matrix % running result: % A = % 8 1 6% 3 5 7% 4 9 2% ans = % 1 0 1% 0 1 1% 0 1 0% ans = % 35 1 6 26 19 24% 3 32 7 21 23 25% 31 9 2 22 27 20% 8 28 33 17 10 15% 30 5 34 12 14 16% 4 36 29 13 18 11% % logical operator % & | ~ (Not) XOR (exclusive or) % relationship with logical function % XOR (x, y) exclusive or operation % Any (x) If X contains non-0 elements, 1 is returned, otherwise, 0% all (X) is returned. If all elements in the element are not 0, 1 is returned. Otherwise, 0% isequal (x, y) X and Y are returned, otherwise, set 0% ismember (x, y). If X is a subset of Y, the corresponding x element is set to 1, otherwise, set instance A = [1 2-3 0 0] B = [0 1 0 3 0] XOR (A, B) % result % A = % 1 2-3 0 0% B = % 0 1 0 3 0% ans = % 1 0 1 0any () % result % ans = % 1All (a) % result % ans = % 0 isequal (a, B) % result % ans = % 0 abismember (A, B) % if Element A is a subset of Element B, set the corresponding x element to 1. Otherwise, set the result to % A = % 1 2-3 0 0% B = % 0 1 0 3 0%. Ans = % 1 0 0 1 1 corresponds to 1, 0, 0 is all elements in B % polynomial operation % MATLAB stores the Polynomials with the Order N in the row vector with the length n + 1, and the elements are polynomial coefficients, % polynomial calculation function % polyval (p, x) is arranged in descending order of X to calculate polynomial p. If X is a scalar, the polynomial value at the X point is calculated. If X is a matrix or vector, all values are calculated. p1 = [2 3-5]; p2 = [3 0 0-4]; polyval (P1, 2) % calculated polynomial value at x = 2% result % ans = % 9 polyval (P1, P2) % calculate multiple values % result % ans = % 22-5-5 15% polyvalm (P, A) perform polynomial calculation on matrix A directly % Example A = [1 2 3]; % polynomial x ^ 2 + 2 * x + 3A = [1 2; 3 4]; % defines a two-dimensional matrix polyvalm (A,) % The result % ans = % 12 14% 21 33% is equivalent to directly replacing the variable X with the two-dimensional matrix A, that is, finding the Matrix polynomial of a ^ 2 + 2 * A + 3 * E. % Poly (B) Calculate the feature polynomial vector B of matrix A = [1 2 3; 4 5 6; 7 8 9] poly (B) % result % B = % 1 2 3% 4 5 6% 7 8 9% ans = % 1.0000-15.0000-18.0000-0.0000% poly (X1) returns a polynomial coefficient, the solution of this polynomial is the value X1 = [2 2 3 4]; Poly (X1) % result % ans = % 1-11 44-76 48% description: returns the polynomial p (x) = x ^ 4-11x ^ 3 + 44x ^ 2-76x + 48. if p (x) = 0, the root of Polynomial P is calculated as 2 2 3 4% roots (p) (the result may be a plural number) P = [1-11 44-76 48] roots (P) % result % P = % 1-11 44-76 48% ans = % 4.0000 + 0.20. I % 3.0000 + 0.20. I % 2.0000 + 0.20. I % 2.0000-0.20. I % compan (P) calculate a friend matrix of Polynomials with coefficients P. The characteristic polynomials of this matrix are pp = [1 2 3 4]; compan (P) % result % ans = %-2-3-4% 1 0 0% 0 1 0% Conv (p, q) Calculate the product of Polynomial p and q, convolutional P = [1, 2, 3] q = [4 5 6 7 8] Conv (p, q) % result % P = % 1 2 3% q = % 4 5 6 7 8% ans = % 4 13 28 34 40 37 24% [K, R] = deconv (p, q) calculate the polynomial P in addition to Q, k is the quotient polynomial, and r is the residue polynomial, which is equivalent to the inverse convolution q = [1, 2, 3] P = [4 5 6 7 8] [K, R] = deconv (p, q) % result % q = % 1 2 3% P = % 4 5 6 7 8% K = % 4-3 0% r = % 0 0 0 16 8


Basic Learning of MATLAB -------- relational and logical operations and polynomial operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.