Matlab calculation

1. Solving the system of equations
1.1 Polynomial and its operation
x 5 + 3x 3 + x 2 +1
polynomial expression: p = [1 0 3 1 0 1]
1.2 polynomial addition ployadd
Justin Shriver, University of Michigan, USA, written for any order Subaddition polyadd between polynomials between orders.

function [poly] = polyadd(poly1,poly2)
if length (poly1)<length(poly2)
    short = poly1;
    long = poly2;
else
    short = poly2;
    long = poly1;
end
mz = length(long)-length(short);
if mz>0
    poly= [zeros(1,mz),short]+long;
else
    poly = long+short;
end

Polynomial addition and subtraction formula:
polynomials p1, p2

p = polyadd (p1, p2)% sum
q = polyadd (p1, -p2 )% sum

(2) Multiplication operation The multiplication of
two polynomials can be achieved by convolving their coefficients with the function conv, ie

p=conv(p1,p2)

(3) Division operation
Division is the inverse process of multiplication. Division can be achieved by the function deconv for coefficient convolution.

[p, r] = deconv (p1, p2)% p is the quotient, r is the remainder

1.3 Derivative of
polynomial Polynomial derivation is realized by the function polyder, which has the following three formats:

  • polyder§: Returns the derivative of the polynomial p.
  • polyder (p1, p2): Returns the derivative of the polynomial p1 * p2.
  • [q, d] = polyder (p1, p2): Returns the derivative of the polynomial p1 / p2, q is the numerator, and d is the denominator.

1.4 Evaluation of polynomials
(1) y = ployval (p, x): Calculate polynomials according to the rules of array operations.
(2) y = ployvaln (p, X): calculate the polynomial value according to the matrix operation rules, and X can only be a square matrix.
1.5 Polynomial root finding
using roots§ function to achieve

1.5 Solve using linear algebra
1.6 Solve nonlinear equations
Use the function fzero to achieve x = fzero (fun, x0)
II. Interpolation and fitting
2.1 Function interpolation The
interpolation function interpn (n-dimensional interpolation)
format: yi = interp1 (x, y, xi, 'method')
x and y are known sample point data; xi is the data point to be interpolated, yi is the function value corresponding to xi; method is the interpolation method, and the nearest term interpolation can be selected ('nearest' ), Linear interpolation ('linear'), spline interpolation ('spline') or cubic interpolation ('cubic'), the default linear interpolation.
2.2 Curve fitting
Format: p = polyfit (x, y, n)
x and y are the data of known sample points, n is the order of the fitted polynomial, and p is the coefficient of the fitted polynomial returned.
2.3 Extreme point of function
Format: x = fminbnd (fun, x1, x2)
Minimal point: x = fminsearch (fun, x0)
2.4 Numerical Calculus
2.4.1 Numerical Differentiation
(1) diff (x): First Differential
(2) diff (x, n): n-time differential
(3) diff (x, n, dim): n-time differential
2.5 numerical integration in the specified dimension dim direction
Rectangular integral cumsum
(1) cumsum (x)
(2) cumsum (x, dim)
2.6 Symbol objects
sym and syms
2.7 Factorization
function factor (s)
2.8 Combine similar terms
(1) collect (s)
(2) collect (s, v)
2.9 Polynomial expansion
function expands (s)
Third, other
3.1 Simplify simplify (s) or simple ( s)
3.2 numden ()

Published 19 original articles · Likes2 · Visits 1095

Guess you like

Origin blog.csdn.net/qq_42692319/article/details/102979942