• 计算方法/数值分析 期末复习整理


    1.多项式计算的秦九韶算法

    对于 f ( x ) = a 0 x n + a 1 x n − 1 . . . a n − 1 x + a n f(x)=a_0x^n+a_1x^{n-1}...a_{n-1}x+a_n f(x)=a0xn+a1xn1...an1x+an

    计算顺序按表格从上往下,从左往右

    a 0 a_0 a0 a 1 a_1 a1 a 2 a_2 a2 a n − 1 a_{n-1} an1 a n a_n an
    x = x 0 x=x_0 x=x0 b 0 x 0 b_0x_0 b0x0 b 1 x 0 b_1x_0 b1x0 b n − 2 x 0 b_{n-2}x_0 bn2x0 b n − 1 x 0 b_{n-1}x_0 bn1x0
    b 0 b_0 b0 b 1 b_1 b1 b 2 b_2 b2 b n − 1 b_{n-1} bn1 b n = f ( x 0 ) b_n=f(x_0) bn=f(x0)

    例如, x 0 = 2 , f ( x ) = 3 x 4 − x 2 + x + 2 x_0=2,f(x)=3x^4-x^2+x+2 x0=2,f(x)=3x4x2+x+2

    30-112
    x 0 = 2 x_0=2 x0=26122246
    36112348

    2.方程求根的二分法算法描述

    伪代码示例:

    input a,b//满足f(a)f(b)<0
    input 精度要求e
    do{
    	x=(a+b)/2;
    	if (f(a)f(x)<0)
    		b=x
    	else
    		a=x
    }while(b-a>e);
    output x
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    真实代码:求一个数的三次方根

    #include 
    #include 
    double n;
    using namespace std;
    int main() {
        cin >> n;
        double l, r, mid;
        l = -2147483648;
        r =  2147483647;
        while (r - l >= 1e-7) {
            mid = (l + r) / 2;
            if (mid * mid * mid >= n)
                r = mid;
            else l = mid;
        }
        cout << fixed << setprecision(6) << mid;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    3.方程求根的简单迭代法

    迭代格式 x = ϕ ( x ) x=\phi(x) x=ϕ(x), ϕ ( x ) \phi(x) ϕ(x) [ a , b ] [a,b] [a,b]上具有连续一阶导数, x ∈ [ a , b ] x\in[a,b] x[a,b] ϕ ( x ) ∈ [ a , b ] \phi(x)\in[a,b] ϕ(x)[a,b], ∃ L < 1 \exist L<1 L<1使得 ∀ x ∈ [ a , b ] , ∣ ϕ ′ ( x ) ∣ ≤ L \forall x\in[a,b],|\phi '(x)|\le L x[a,b],ϕ(x)L,则有 x ∗ = ϕ ( x ∗ ) x^*=\phi(x^*) x=ϕ(x)

    将方程改写为等价形式 x = ϕ ( x ) x=\phi(x) x=ϕ(x),得到迭代格式 x k + 1 = ϕ ( x k ) x_{k+1}=\phi(x_k) xk+1=ϕ(xk),取 x 0 ∈ [ a , b ] x_0\in[a,b] x0[a,b],得到序列 x 0 , x 1 , . . . , x n x_0,x_1,...,x_n x0,x1,...,xn

    事后估计式: ∣ x k − x ∗ ∣ ≤ L 1 − L ∣ x k − x k − 1 ∣ |x_k-x^*|\le \frac{L}{1-L}|x_k-x_{k-1}| xkx1LLxkxk1,终止条件 ∣ x k − x k − 1 ∣ ≤ ϵ |x_k-x_{k-1}|\le \epsilon xkxk1ϵ

    事前估计式: ∣ x k − x ∗ ∣ ≤ L k 1 − L ∣ x 1 − x 0 ∣ |x_k-x^*|\le \frac{L^k}{1-L}|x_1-x_0| xkx1LLkx1x0

    渐进估计式: lim ⁡ k → 0 x k + 1 − x ∗ x k − x ∗ = ϕ ′ ( x ∗ ) \lim\limits_{k\to 0}\frac{x_{k+1}-x^*}{x_k-x^*}=\phi'(x^*) k0limxkxxk+1x=ϕ(x)

    [ a , b ] [a,b] [a,b]内存在根 x ∗ x^* x, x ∈ [ a , b ] x\in[a,b] x[a,b] ∣ ϕ ′ ( x ) ≥ 1 ∣ |\phi'(x)\ge 1| ϕ(x)1∣,则发散

    局部收敛:在 x ∗ x^* x邻域 S S S内对 ∀ x 0 ∈ S , x k + 1 = ϕ ( x k ) \forall x_0\in S,x_{k+1}=\phi(x_k) x0S,xk+1=ϕ(xk)收敛,则局部收敛。即: ∣ ϕ ′ ( x ∗ ) ∣ < 1 |\phi'(x^*)|<1 ϕ(x)<1,局部收敛。 ∣ ϕ ′ ( x ) ∣ > 1 |\phi'(x)|>1 ϕ(x)>1,发散

    收敛速度: e k = x k − x ∗ , lim ⁡ k → ∞ e k + 1 e k p = c e_k=x_k-x^*,\lim _{k\to\infty}\frac{e_{k+1}}{e_k^p}=c ek=xkx,limkekpek+1=c,则 p p p阶收敛。若 p = 1 p=1 p=1 0 < ∣ c ∣ < 1 0<|c|<1 0<c<1,则线性收敛。若 p > 1 p>1 p>1,则超线性收敛。若 p = 2 p=2 p=2,则平方收敛。简单迭代法当 ϕ ′ ( x ∗ ) ≠ 0 \phi'(x^*)\ne 0 ϕ(x)=0时线性收敛

    4.线性方程组数值解的高斯消去法

    普通的高斯消元法:输入一个包含 n n n 个方程 n n n 个未知数的线性方程组。方程组中的系数为实数。求解这个方程组。

    高斯消元法分两个步骤:1.消元 2.回代。在列主元高斯消元法中,每一次消元都需要交换行,选择
    ∣ a t , k ( k ) ∣ = max ⁡ k ≤ i ≤ n ∣ a i , k ( k ) ∣ |a_{t,k}^{(k)}|=\max_{k\le i\le n}|a_{i,k}^{(k)}| at,k(k)=kinmaxai,k(k)

    伪代码描述:

    for k=1 to n-1 do
    	for i=k+1 to n do
        {
        	l=-a[i][k]/a[k][k];
        	for j = 1 to n do
        		a[i][j]=a[i][j]+l*a[k][j]
        	b[i]=b[i]+l*b[k];
        }
      
    for k = n downto 1 do
    	{
    		s=0;
    		for j=k+1 to n do
    			s=s+a[k][j]*x[j];
    		x[k]=(b[k]-s)/a[k][k];
    	}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    真实代码:

    #include
    #include
    #include
    using namespace std;
    const double ep=1e-6;
    double a[105][105];
    int n;
    int main(){
        cin>>n;
        for(int i=0;i>a[i][j];
        int c,r;
        for(c=0,r=0;cfabs(a[t][c]))    
                    t=i;
            }
            if (fabs(a[t][c])=c;i--)
                a[r][i]/=a[r][c];
            for(int i=r+1;iep)
                    for(int j=n;j>=c;j--)
                        a[i][j]-=a[r][j]*a[i][c];
            r++;
        }
        if (rep){
                    puts("No solution");
                    return 0;
                }
            puts("Infinite group solutions");
            return 0;
        }
        else{
            for(int i=n-1;i>=0;i--)
                for(int j=i+1;j<=n;j++)
                    a[i][n]-=a[j][n]*a[i][j];
            for (int i = 0; i < n; i ++ ) 
                printf("%.2lf\n", a[i][n]);
        }
        return 0;        
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49

    5.拉格郎日插值多项式与插值余项

    f ( x k ) = y k f(x_k)=y_k f(xk)=yk
    L n ( x ) = ∑ k = 0 n y k l k ( x ) = ∑ k = 0 n ( ∏ i = 0 i ≠ k x − x i x k − x i ) y k L_n(x)=\sum_{k=0}^ny_kl_k(x)=\sum_{k=0}^n(\prod_{i=0ik}\frac{x-x_i}{x_k-x_i})y_k Ln(x)=k=0nyklk(x)=k=0n(i=0i=kxkxixxi)yk

    R n ( x ) = f ( x ) − L n ( x ) = f ( n + 1 ) ( ξ ) ( n + 1 ) ! W n + 1 ( x ) R_n(x)=f(x)-L_n(x)=\frac{f^{(n+1)}(\xi)}{(n+1)!}W_{n+1}(x) Rn(x)=f(x)Ln(x)=(n+1)!f(n+1)(ξ)Wn+1(x)

    (3)为插值多项式余项。其中,
    W n + 1 ( x ) = ( x − x 0 ) ( x − x 1 ) . . . ( x − x n ) W_{n+1}(x)=(x-x_0)(x-x_1)...(x-x_n) Wn+1(x)=(xx0)(xx1)...(xxn)
    f ( x ) f(x) f(x)为次数不超过 n n n的多项式,则 R n ( x ) = 0 R_n(x)=0 Rn(x)=0.
    f ( x ) ≡ 1 ⇒ ∑ j = 0 n l j ( x ) ≡ 1 f(x)\equiv 1\Rightarrow \sum_{j=0}^nl_j(x)\equiv 1 f(x)1j=0nlj(x)1
    f n + 1 ( ξ ) f^{n+1}(\xi) fn+1(ξ)不能具体求出。但可以求出误差限:
    max ⁡ a ≤ x ≤ b ∣ f ( n + 1 ) ( x ) ∣ = M n + 1 \max_{a\le x\le b}|f^{(n+1)}(x)|=M_{n+1} axbmaxf(n+1)(x)=Mn+1

    ∣ R n ( x ) ∣ ≤ M n + 1 ( n + 1 ) ! ∣ W n + 1 ( x ) ∣ |R_n(x)|\le \frac{M_{n+1}}{(n+1)!}|W_{n+1}(x)| Rn(x)(n+1)!Mn+1Wn+1(x)

    6.曲线拟合的最小二乘法多项式拟合方程组

    P ( x ) = a 0 + a 1 x + a 2 x 2 . . . a m x m P(x)=a_0+a_1x+a_2x^2...a_mx^m P(x)=a0+a1x+a2x2...amxm
    ( ∑ i = 1 n x i 0 ∑ i = 1 n x i 1 . . . ∑ i = 1 n x i m ∑ i = 1 n x i 1 ∑ i = 1 n x i 2 . . . ∑ i = 1 n x i m + 1 . . . . . . . . . . . . ∑ i = 1 n x i m ∑ i = 1 n x i m + 1 . . . ∑ i = 1 n x i 2 m ) ( a 0 a 1 . . . a m ) = ( ∑ i = 1 n y i ∑ i = 1 n x i y i . . . ∑ i = 1 n x i m y i ) (ni=1x0ini=1x1i...ni=1xmini=1x1ini=1x2i...ni=1xm+1i............ni=1xmini=1xm+1i...ni=1x2mi)(a0a1...am)=(ni=1yini=1xiyi...ni=1xmiyi) i=1nxi0i=1nxi1...i=1nximi=1nxi1i=1nxi2...i=1nxim+1............i=1nximi=1nxim+1...i=1nxi2m a0a1...am = i=1nyii=1nxiyi...i=1nximyi

    7.定积分计算的复化辛卜生公式算法描述

    S n ( f ) = h 6 [ f ( x 0 ) + 2 ∑ k = 1 n − 1 f ( x k ) + f ( x n ) + 4 ∑ k = 0 n − 1 f ( x k + 1 2 ) ] S_n(f)=\frac h6[f(x_0)+2\sum_{k=1}^{n-1}f(x_k)+f(x_n)+4\sum_{k=0}^{n-1}f(x_{k+\frac 12})] Sn(f)=6h[f(x0)+2k=1n1f(xk)+f(xn)+4k=0n1f(xk+21)]

    h = ( b − a ) / n , x 1 = a , x 2 = a + h 2 ; y 1 = 0 ; y 2 = f ( x 2 ) h=(b-a)/n,x_1=a,x_2=a+\frac h2;y_1=0;y_2=f(x_2) h=(ba)/n,x1=a,x2=a+2h;y1=0;y2=f(x2)

    伪代码:

    for (i=1;i<=n-1;i++){
        x1=x1+h;
        x2=x2+h;
        y1=y1+f(x1);
        y2=y2+f(x2);
    }
    S=(f(a)+f(b)+2*y1+4*y2)*h/6
    output S
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    8. 复化求积公式的阶与变步长求积公式稳定性

    lim ⁡ h → 0 I ( f ) − I n ( f ) h p = c , h = b − a n \lim_{h\to 0}\frac{I(f)-I_n(f)}{h^p}=c,h=\frac{b-a}n h0limhpI(f)In(f)=c,h=nba

    该公式 p p p阶收敛

    复化梯形:2阶。复化辛卜生:4阶。复化柯特斯:6阶

    复化求积公式误差: I ( f ) − I n ( f ) = c h p , I ( f ) − I 2 n ( f ) ≈ 1 2 p c h p I(f)-I_n(f)=ch^p,I(f)-I_{2n}(f)\approx\frac 1{2^p}ch^p I(f)In(f)=chp,I(f)I2n(f)2p1chp, ∣ I ( f ) − I 2 n ( f ) ∣ ≈ 1 2 p − 1 ∣ I 2 n ( f ) − I n ( f ) ∣ ≤ ϵ |I(f)-I_{2n}(f)|\approx\frac{1}{2^p-1}|I_{2n}(f)-I_n(f)|\le \epsilon I(f)I2n(f)2p11I2n(f)In(f)ϵ

    变步长梯形公式:
    T n ( f ) = ∑ k = 0 n − 1 h 2 [ f ( x k ) + f ( x k + 1 ) ] T 2 n ( f ) = 1 2 T n + h 2 ∑ k = 0 n − 1 f ( x k + 1 2 ) T_n(f)=\sum_{k=0}^{n-1}\frac h2[f(x_k)+f(x_{k+1})]\\ T_{2n}(f)=\frac 12 T_n+\frac h2 \sum_{k=0}^{n-1}f(x_{k+\frac 12}) Tn(f)=k=0n12h[f(xk)+f(xk+1)]T2n(f)=21Tn+2hk=0n1f(xk+21)
    其中, h h h为二分前的步长
    I ( f ) − I 2 n ( f ) ≈ 1 2 p [ ( I ( f ) − I n ( f ) ] < 1 I(f)-I_{2n}(f)\approx \frac 1{2^p}[(I(f)-I_n(f)]<1 I(f)I2n(f)2p1[(I(f)In(f)]<1
    即:每二分一次,截断误差缩小2倍,变步长求积公式稳定。
    ∣ I ( f ) − I 2 n ( f ) I ( f ) − I n ( f ) ∣ = 1 2 p < 1 |\frac{I(f)-I_{2n}(f)}{I(f)-I_n(f)}|=\frac 1{2^p}<1 I(f)In(f)I(f)I2n(f)=2p1<1
    复化梯形公式:
    T n ( f ) = ∑ k = 0 n − 1 h 2 [ f ( x k ) + f ( x k + 1 ) ] , S n ( f ) = ∑ k = 0 n − 1 h 6 [ f ( x k ) + 4 f ( x k + 1 2 ) + f ( x k + 1 ) ] , C n ( f ) = ∑ k = 0 n − 1 h 90 [ 7 f ( x k ) + 32 f ( x k + 1 4 ) + 12 f ( x k + 1 2 ) + 32 f ( x k + 3 4 ) + 7 f ( x k + 1 ) ] T_n(f)=\sum_{k=0}^{n-1}\frac h2[f(x_k)+f(x_{k+1})],\\S_n(f)=\sum_{k=0}^{n-1}\frac h6[f(x_k)+4f(x_{k+\frac 12})+f(x_{k+1})],\\C_n(f)=\sum_{k=0}^{n-1}\frac h{90}[7f(x_k)+32f(x_{k+\frac 14})+12f(x_{k+\frac 12})+32f(x_{k+\frac 34})+7f(x_{k+1})] Tn(f)=k=0n12h[f(xk)+f(xk+1)],Sn(f)=k=0n16h[f(xk)+4f(xk+21)+f(xk+1)],Cn(f)=k=0n190h[7f(xk)+32f(xk+41)+12f(xk+21)+32f(xk+43)+7f(xk+1)]
    例如:计算 I = ∫ 0 1 4 1 + x 2 d x I=\int_0^1\frac{4}{1+x^2}dx I=011+x24dx
    T 1 = 1 − 0 2 [ f ( 0 ) + f ( 1 ) ] = 3 T 2 = 1 2 T 1 + 1 2 f ( 1 2 ) = 3.1 T 4 = 1 2 T 2 + 1 2 ∗ 1 2 ∗ [ f ( 1 4 ) + f ( 3 4 ) ] = 3.13118 T 8 = 1 2 T 4 + 1 2 ∗ 1 4 ∗ [ f ( 1 8 ) + f ( 3 8 ) + f ( 5 8 ) + f ( 7 8 ) ] = 3.13899... T_1=\frac{1-0}{2}[f(0)+f(1)]=3\\T_2=\frac 12T_1+\frac 12f(\frac 12)=3.1\\T_4=\frac 12T_2+\frac 12*\frac 12 *[f(\frac 14)+f(\frac 34)]=3.13118\\ T_8=\frac 12T_4+\frac 12*\frac 14*[f(\frac 18)+f(\frac 38)+f(\frac 58)+f(\frac 78)]=3.13899... T1=210[f(0)+f(1)]=3T2=21T1+21f(21)=3.1T4=21T2+2121[f(41)+f(43)]=3.13118T8=21T4+2141[f(81)+f(83)+f(85)+f(87)]=3.13899...
    对于精度 ϵ \epsilon ϵ, 1 2 p − 1 ∣ I 2 n ( f ) − I n ( f ) ∣ < ϵ \frac 1{2^p-1}|I_{2n}(f)-I_n(f)|<\epsilon 2p11I2n(f)In(f)<ϵ时, I ( f ) − I 2 n ( f ) ≈ 1 2 p − 1 ∣ I 2 n ( f ) − I n ( f ) ∣ ≤ ϵ I(f)-I_{2n}(f)\approx \frac 1{2^p-1}|I_{2n}(f)-I_n(f)|\le \epsilon I(f)I2n(f)2p11I2n(f)In(f)ϵ

    9.数值微分计算的中点公式

    D ( h ) = f ( x 0 + h ) − f ( x 0 − h ) 2 h f ′ ( x ) = 1 2 h [ − f ( x 0 ) + f ( x 2 ) − h 2 6 f ′ ′ ′ ( ξ 2 ) ] D 1 ( h ) = 4 3 D ( h 2 ) − 1 3 D ( h ) D(h)=\frac{f(x_0+h)-f(x_0-h)}{2h}\\f'(x)=\frac 1{2h}[-f(x_0)+f(x_2)-\frac{h^2}6f'''(\xi _2)]\\ D_1(h)=\frac 43D(\frac h2)-\frac 13D(h) D(h)=2hf(x0+h)f(x0h)f(x)=2h1[f(x0)+f(x2)6h2f′′′(ξ2)]D1(h)=34D(2h)31D(h)

    10.一阶常微分方程数值解法梯形公式

    单步隐式公式
    { y i + 1 = y i + h ϕ ( x i , y i , y i + 1 , h ) y 0 = η {yi+1=yi+hϕ(xi,yi,yi+1,h)y0=η {yi+1=yi+hϕ(xi,yi,yi+1,h)y0=η

    ϕ ( x , y , y ‾ , h ) = 1 2 [ f ( x , y ) + f ( x + h , y ~ ) ] y i + 1 = y i + h 2 [ f ( x i , y i ) + f ( x i + 1 , y i + 1 ) ] y ′ = f ( x , y ) , y ( a ) = η \phi(x,y,\overline y,h)=\frac 12[f(x,y)+f(x+h,\tilde y)]\\ y_{i+1}=y_i+\frac h2[f(x_i,y_i)+f(x_{i+1},y_{i+1})]\\ y'=f(x,y),y(a)=\eta ϕ(x,y,y,h)=21[f(x,y)+f(x+h,y~)]yi+1=yi+2h[f(xi,yi)+f(xi+1,yi+1)]y=f(x,y),y(a)=η

    例如
    y ′ = − 2 x y ( 0 ≤ x ≤ 1.8 ) , y ( 0 ) = 1 , h = 0.1 y i + 1 = y i + h 2 [ f ( x i , y i ) + f ( x i + 1 , y i + 1 ) ] y i + 1 = y i − h x i y i − h x i + 1 y i + 1 , 其中 y i + 1 = y i − h x i y i 1 + h x i + 1 y'=-2xy(0\le x \le 1.8),y(0)=1,h=0.1\\ y_{i+1}=y_i+\frac h2[f(x_i,y_i)+f(x_{i+1},y_{i+1})]\\ y_{i+1}=y_i-hx_iy_i-hx_{i+1}y_{i+1},\\其中y_{i+1}=\frac{y_i-hx_iy_i}{1+hx_{i+1}} y=2xy(0x1.8),y(0)=1,h=0.1yi+1=yi+2h[f(xi,yi)+f(xi+1,yi+1)]yi+1=yihxiyihxi+1yi+1,其中yi+1=1+hxi+1yihxiyi

    x_iy_i
    01
    0.10.9901
    0.20.96098
    0.30.9143
    0.40.8527
  • 相关阅读:
    C++STL详解(三)list的使用及其模拟实现
    day19-web开发会话技术01
    自动化测试基础篇:Selenium 框架设计(POM)
    【学习笔记】 CF850F Rainbow Balls
    Dubbo 服务注册与启动源码解析
    浙大陈越何钦铭数据结构06-图1 列出连通集
    LeetCode 2 两数相加
    多孔聚合双阴离子中心离子液体(PPDIL)包覆的羧甲基纤维素钠(CMC)修饰四氧化三铁纳米复合材料(Fe3O4@CMC@PPDIL)试剂
    单点登录原理及JWT实现
    LeetCode-152. 乘积最大子数组
  • 原文地址:https://blog.csdn.net/qq_46640863/article/details/126651884