C++ study notes summary exercise: numerical methods

Numerical Methods

1.1 Random numbers

head File

#include<random>

Random Number Overview

  • random number distribution. The distribution of random numbers distribution

  • Random number engine. Generate random number engin. source of randomness

  • Random number generator. A random number generator is composed of a random number engine and a random number distribution.

Operation of the random number engine

insert image description here
insert image description here

  • The compiler will automatically select a random number engine as the engine of the type default_random_engine.
    default_random_engine e;
    cout<<e()<<endl;

Operations on Random Number Distributions

insert image description here
insert image description here

  • Need to choose a distribution sequence for the default random number engine.
uniform_int_distribution<unsigned> u<0,9>;
default_random_engine e(323);//指定初始化的种子

Standard operations for generating random numbers

#include <iostream>
#include <random>

#include<ctime>
using namespace std;
 
int main( ){
    default_random_engine e;
    cout<<time(NULL)<<endl;
    e.seed(time(NULL));
    uniform_int_distribution<unsigned> u(0, 9);
    for(int i=0; i<10; ++i)
        cout<<u(e)<<endl;
    return 0;
}

1.2 Random distribution engine

C++ provides 16 random number engines.
insert image description here

  • default_random_engine

1.3 Random distribution type

C++ provides five types of random distributions

insert image description here

  • uniform_int_distribution (up_bound, down_bound) Uniform integer distribution T: short int long long long. Specifies the maximum and minimum values ​​for the uniform distribution.
  • uniform_real_distribution (up_bound, down_bound) Uniform floating-point number distribution T: float double. Specify the maximum and minimum values ​​of the uniform distribution

1.4 Method of C

rand()

rand()%100//在100中产生随机数, 但是因为没有随机种子所以,下一次运行也是这个数,因此就要引出srand

srand()

srand((int)time(0));  // 产生随机种子把0换成NULL也行

2 plural

common operation

insert image description here

value access

insert image description here

Arithmetic

insert image description here

Input and output operations

insert image description here

transcendental function

insert image description here

3 Global Numeric Functions

head File

#include<cmath>
#include<cstdlib>

Numeric function

insert image description here

4 Valarray Numeric array

Guess you like

Origin blog.csdn.net/DeepLearning_/article/details/132153441