This is the 15th day of my participation in the August More text Challenge. For details, see: August More Text Challenge

The easiest way to get started with high ai is with octave, which makes it easier to write in python or c++.

Introduction to the

GNU Octave is a high-level language primarily intended for numerical computations. It is typically used for such problems as solving linear and nonlinear equations, numerical linear algebra, statistical analysis, and for performing other numerical experiments. It may also be used as a batch-oriented language for automated data processing.

GNU Octave is a high-level language used primarily for numerical calculations. It is commonly used to solve linear and nonlinear equations, numerical linear algebra, statistical analysis, and other numerical experiments. It can also be used as a batch-oriented language for automated data processing.

This is just a simple introduction, see the official document for more features:octave.pdf

basic

  1. Annotation %
    • Similar to // in C++ and # in python
  2. Ans is used to store output results
  3. If you don’t like the line prefixes, you can customize themPS1(' what you want to change ');

Operator operation

Arithmetic operators add, subtract, multiply, divide, and square

octave:1> 1+5
ans = 6
octave:2> 1*5
ans = 5
octave:3> 1/5
ans = 0.2000
octave:4> 1- 5
ans = 4 -
octave:5> 5^2
ans = 25
>>sqrt(5)
ans = 2.2361
>>sqrt(4)
ans = 2
Copy the code

Logical operator

  • Is equal to the = =
  • Is not equal to ~ =
  • Or | |
  • With &&
  • Exclusive or xor (a, b)
  • Greater than or equal to greater than or equal to
  • More than >
ans = 0
>>1= =1
ans = 1
>>1~ =2
ans = 1
>>1&&2
ans = 1
>>1&&0
ans = 0
>>1||0
ans = 1
>>xor(1.1)
ans = 0
>>xor(1.2)
ans = 0
>>xor(0.1)
ans = 1
>>1> =2
ans = 0
>>1<2
ans = 1
Copy the code

Assignment operator

  • = assignment operator
    • A semicolon after a statement does not print an assignment statement directly
    • Print an assignment statement without a semicolon after it
>>a=1   %a=1There's no semicolon, so the next line after you type enter will just print a equals1
a = 1>>a % Type a and press Enter to see if the assignment succeeded. A =1
>>b=2;  %b=2It's followed by a semicolon, so the next line won't print assignment to b >>b %, type b, press enter, and see the assignment to b, b =2   

>>c=pi
c = 3.1416 
Copy the code

Formatted output

  • Disp (x) : displays the value of x
  • Disp (sprintf(‘%0.2f’,c)) : format output with two decimal places, just like c
  • Format long/short: This parameter does not affect the integer format, but affects the decimal format
>>disp(a)
1
>>disp(c)
3.1416
>>disp(sprintf('% 0.2 f',c))
3.14

>>format long
>>a
a = 1
>>c
c = 3.141592653589793
>>format short
>>a
a = 1
>>c
c = 3.1416
Copy the code

Vectors and matrices

The official statement matrix reads:

Vectors and matrices are the basic building blocks for numerical analysis. To create a new matrix and store it in a variable so that you can refer to it later, type the command

octave:1> A = [ 1, 1, 2; 3, 5, 8; 13, 21, 34 ]

Octave will respond by printing the matrix in neatly aligned columns.

>>martix = [1.2.3;4.5.6;7.8.9]
martix =

   1   2   3
   4   5   6
   7   8   9
Copy the code

There are a lot of other ways to write it, but I’m not going to list them here.

Declare a row vector without adding symbols or commas between elements.

martix =

   1   2
   2   3
   3   4

>>vector= [1 2 3]
vector =

   1   2   3

>>vector = [4;5;6]
vector =

   4
   5
   6
Copy the code

Other special writing:

  • Variable = start: Step: stop, will generate a vector
    • .
  • Ones (a,b) produces a matrix where a has only one row and b column
    • With the exception of Ones and Zeros, all generated elements are zeros, but no twos, threes…
  • Rand (a,b) generates a matrix of random numbers between 0 and 1 in row A and column B
  • Randn (a,b) also generates a random number matrix with row A and column B, but conforms to the Gaussian distribution (normal distribution). Returns a matrix with normally distributed random elements with a mean of zero and a variance of 1.
    • Normal distribution:

  • randi()
    • Randi (Max,m,n) : generates a matrix of m rows and n columns with 1~ Max
    • Randi ([min, Max],m,n) : Generate a matrix of m rows and n columns for min~ Max

Hist (variable)

I can graph the variables

If you think that’s too little. That can be usedHist (variable, number of stripes)Here is the image with 50 stripes drawn.