MATLAB: [5] Data analysis and polynomial calculation

Table of contents

 

5.1 Statistical analysis of data

5.2 Polynomial calculation

5.3 Data interpolation

5.4 Curve Fitting


5.1 Statistical analysis of data

Find the largest and smallest elements

  • When the argument is a vector

max(X) returns the maximum value of the vector X, if it contains complex elements, take the maximum value by modulo

min(X)

[y,k] = max(X) returns the maximum value of the vector X to y, and the maximum element number to k

[y,k] = min(X) 

  •  When the parameter is a matrix

max(X) returns a row vector, the i-th element of the vector is the maximum value of the i-th column of the matrix

[Y,U] = max(X) returns the row vectors Y and U, Y records the maximum value of each column of A, and the U vector records the row number of the maximum element of each column

[Y, U] = max(X, [], dim) When dim is 1 or 2, this function is exactly the same as max(A); when dim is 2, this function returns a column vector whose first The i element is the maximum value on the i-th row of the A matrix

Find the mean and median

  • Average: Refers to the arithmetic mean, that is, the sum of each item divided by the number of items
  • Median: The element whose size is in the middle of the data sequence, if the data sequence is odd, it is the middle value. If the data sequence is even, take the average of the middle two numbers
  • mean() calculates the arithmetic mean
  • median() finds the median
  • Other usages are the same as max and min, slightly

Sum and Product

  • sum() summation function
  • prod() quadrature function
  • Other usages are the same as max and min, slightly

cumulative sum and cumulative product

  • cumsum() cumulative sum function
  • cumprod() cumulative product function

Find standard deviation and correlation coefficient

  • std(X) calculates the standard deviation of the vector X
  • std(A) calculates the standard deviation of each column of matrix A
  • std(A, flag, dim) When flag=0, calculate the sample standard deviation according to the formula listed in S1; when flag=1, calculate the overall standard deviation according to the formula listed in S2; default: flag=0, dim=1

  • corrcoef(A) returns a correlation coefficient matrix formed by matrix A, where the element in column i and row j represents the correlation coefficient between column i and column j in the original matrix A
  • corrcoef(X,Y) Here, X and Y are vectors, and they have the same function as corrcoef([X,Y]), which is used to find the correlation coefficient between X and Y vectors

to sort

  • sort(X) sorts the vector X in ascending order
  • [Y,I] = sort(A, dim, mode) where dim indicates whether to sort the columns or rows of A. mode indicates whether to sort in ascending or descending order. If "acesnd" is selected, it is in ascending order. If "descend" is selected, In descending order, the default is ascending order. In the output parameter, Y is the sorted matrix, and I records the position of the elements in Y in A.

5.2 Polynomial calculation

Representation of polynomials

  • In MATLAB, a polynomial of degree n is represented by a row vector of length n+1.
  • The order of the polynomial coefficient vector is from high to low
  • The polynomial coefficient vector contains coefficients of degree 0, so its length is the highest degree of the polynomial plus 1
  • If there are no items, the corresponding position of the coefficient vector should be filled with 0

Four Arithmetic Operations of Polynomials

  • Addition and subtraction of polynomials: directly correspond to loud addition and subtraction
  • Polynomial multiplication: conv(P1,P2) 
  • Polynomial division: [Q, r] = deconv(P1,P2) Q is the quotient, r is the remainder

Derivation of Polynomials

  • polyder() polynomial derivation function
  • p = ployder(P) Find the derivative function of the polynomial P
  • p = ployder(P,Q) Find the derivative function of P·Q
  • [p, q] = ployder(P,Q) Find the derivative function of P/Q, the numerator of the derivative function is stored in p, and the denominator is stored in q

Polynomial Evaluation

  • polyval(p, x) Algebraic polynomial evaluation: p is a polynomial coefficient, x can be a scalar, vector or matrix. If x is a scalar, the value of the polynomial at this point is calculated; if x is a vector or matrix, the vector or Evaluates the polynomial for each element in the matrix.
  • polyvalm(p, x) Matrix polynomial evaluation, requires x to be a square matrix, and uses the square matrix as an independent variable to find the value of the polynomial

polynomial root finding

  • roots(p) polynomial root finding
  • p = poly(x) All the roots of the polynomial are known, and the polynomial can be established with the poly function

5.3 Data interpolation

  • Data interpolation is a method of function approximation
  • interp1() one-dimensional interpolation function
  • Y1 = interp1(X, Y, X1, method) Calculate the value of the function at X1 according to the values ​​of X and Y. Among them, X and Y are two known vectors of equal length, representing the sampling points and sampling values ​​respectively. X1 is a vector or scalar representing the points to interpolate.
  • mothod is used to specify the interpolation method, and the commonly used values ​​are the following four
  1. linear: Linear interpolation, the default method. Connect two data points close to the interpolation point with a straight line, and then select the data corresponding to the interpolation point on the straight line.
  2. nearest: the nearest point interpolation, drill the value closest to the sample point as the interpolation data
  3. pchip: Piecewise 3 Hermitian interpolation. Using subscaled cubic polynomials, in addition to satisfying the interpolation conditions, it is also necessary to satisfy the first-order derivatives of adjacent production value functions at several nodes. shape
  4. spline: 3-degree spline interpolation, constructing a 3-degree polynomial in each segment, so that the interpolation function not only satisfies the interpolation conditions, but also requires continuous second-order derivatives at each node
  • interp2() binary interpolation function
  • Z1 = interp2(X,Y, Z, X1, Y1, method) Among them, X, Y are two vectors, which represent the sampling points of Li An parameters, and Z is the function value corresponding to the sampling points. X1, Y1 are two A scalar or vector representing the points to interpolate

5.4 Curve Fitting

  • Similar to data interpolation, curve fitting is also a method of function approximation, using the least squares method for fitting
  • plotfit() polynomial fitting function
  • P = plotfit(X, Y, m) outputs polynomial coefficients p
  • [P, S] = plotfit(X, Y, m) S is the sampling point error data
  • [P, S, mu] = plotfit(X, Y, m) mu is a binary vector, mu(1) is mean(X), mu(2) is std(X)

Guess you like

Origin blog.csdn.net/Alex497259/article/details/104583774