"Vibration simulation using MATLAB" chapter I "Fundamentals of Matlab"

Source: Internet
Author: User

MATLAB is an interactive language which can be used for numerical analysis and data visualization, and it is widely used in the analysis and design of vibration control engineering. A variety of toolboxes allow MATLAB to be extended to different areas.

1.1 Matrix Generation

  A matrix is a collection of values organized by rows and columns (column).

  A=[1 2 3 4;5 6 7 8;9 10 11 12]

The matrix can be transpose (transpose) with an apostrophe (apostrophe)

  B=a '

Use a colon (colon) between two integers to generate all integers between two integers

  A=1:8 generates line vectors (row vector) a=[1 2 3 4 5 6 7 8]

Use a colon between three numbers to generate all numbers in the middle number of steps between two numbers

  b=0.0:. 2:1 generates a row vector (row vector) b=[0.0 0.2 0.4 0.6 0.8 1.0]

Other ways to build it are as follows:

  C=linspace (0,10,21)//Generate linear space line vector (21 generated between 0~10)

  D=logspace ( -1,1,10)//Generate logarithmic space row vectors (10 generated between -1~1)

  Eye (3)//Generate 3*3 unit matrix (identity matrix)

  Zeros (3,2)//Generate 3*2 full 0 matrix

1.2 Matrix Processing

  Number of matrix cells

Suppose there is a matrix A (2,3)

Size (A) returns the number of rows and columns

  D=size (A)//d=[2 3]

Length (A) returns the maximum value in all dimensions

  E=length (rand (2,3,5))//e=5

Transpose (Transpose)

  A

Get a column or a row in a matrix

  A (:, 3)//Get the 3rd column of data in a

  A (2,:)//Get the 2nd row of data in a

Matrix point multiplication, two matrix dimensions must be exactly the same

  A (2,3); B (2,3); C=a.*b;

If it is a square matrix, similar to E, multiple multiplication can be abbreviated as

  E.^4

Matrix multiplication

  A (2,3); B (3,2); C=a*b//c should be C (2,2)

If it is a square matrix, similar to E, multiple multiplication can be abbreviated as

  E^4

1.3 Functions

MATLAB contains many standard functions, such as sin and cos

  i=0+1.0i;

  j=0+1.0i;

  cos (pi) =-1;

  EXP (1) = 2.7183;

  LOG (exp (1)) = 1;

  LOG10 (10) = 1;

INV () returns the inverse matrix of the matrix (inverse matrix)

  b=Inv (A);

Det () Returns the value of the determinant of the matrix (determinant of a matrix)

  Det (A);

Trace () returns the sum of the main diagonal values of the matrix

  Trace (A);

You can use the Help function name to get a description of the function

1.4 Drawing

MATLAB can be convenient for drawing rich numerical graphics.

e.g in [pi/100, 10pi] The figure of sin (x) x/

  X=pi/100:pi/100:10*pi;

  Y=sin (x)/x;

  Plot (x, y);

  grid;

Common drawing functions:

Plot (x, y)//Paint function

Subplot ()//a sheet of paper to draw multiple graphs, to determine the position of the diagram

  Figure

  Subplot (2,1,1);

  Plot (x,y1);

  Subplot (2,1,2);

  Plot (x,y2);

  Title ()

Xlabel ();

Ylabel ();

Grid

1.5 Programming

1.5.1 M-File

Files that contain many MATLAB statements are called M files.

1.5.2 Cycle

For loop

      For N=0:10

        X (n+1) =sin (PI*N/10);

      End

Loops can be nested

      H=zeors (5)

      For K=1:5

        For L=1:5

          H (k,l) =1/(K+L-1)

        End

      End

1.5.3 If statement

      If condition

        Statement

      End

      If condition

        Statement

      else condition

        Statement

      End

1.5.4 Sub-function

functions [return value] = function name (parameter)

    function [mean] = stat (x)

    n = length (x);

    mean = SUM (x)/n;

"Vibration simulation using MATLAB" chapter I "Fundamentals of Matlab"

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.