汪群超 Chun-Chao Wang

Dept. of Statistics, National Taipei University, Taiwan

Lesson 9: System of nonlinear equations

Objective:

  1. Learn how to solve system of nonlinear equations by numerical algorithms

Prerequisite:


範例 1: Solve the system of nonliear equations

x_1^2 + x_2^2 - 2  =  0
e^{x_1-1}+x_2^3 - 3  =  0
or expressed by

F(x) = \left[\begin{array}{c}                 x_1^2 + x_2^2 - 2 \\                 e^{x_1-1}+x_2^3 - 3             \end{array} \right] = \underline{0}

import numpy as np
import scipy.optimize as opt

def fun(x) :
    f = [x[0]**2 + x[1]**2 -2, np.exp(x[0]-1) + x[1]**3 -3]
    return f

sol = opt.root(fun, x0 = [1, 1]) 
# print(sol)
print('The solutions are [{:.4f},{:.4f}]'.format(sol.x[0], sol.x[1]))

練習: Solve each system of nonlinear equations

  1. 2(x_1+x_2)^2+(x_1-x_2)^2-8 = 0
    5x_1^2+(x_2-3)^2 - 9 =0
  2. F(x) = \left[\begin{array}{c}         4(x_1-2)^3+2(x_1-2)x_2^2 \\         2(x_1-2)^2x_2 + 2(x_2+1)     \end{array} \right] = \underline{0}
  3. F(x) = \left[\begin{array}{c}         -400x_1(x_2-x_1^2)-2(1-x_1) \\         200(x_2-x_1^2)     \end{array} \right] = \underline{0}

練習: 計算 f(x_1, x_2) = 100(x_2-x_1^2)^2 + (1-x_1)^2 的最小值。

提示:這個問題就是前章介紹的多變量函數的最小值。除了使用指令直接求解外,也可以透過間接解非線性多變量聯立方程式的解,即對函數的各變量做偏微分並令其為零,其解可能是多變量函數的最小值解、最大值的解或什麼都不是。