
数值优化(本科版)
数值计算方法
Seung-Yim Yau
业精于勤,荒于嬉;行成于思,毁于随。
展开
-
数值计算·第四集:线性规划(Matlab版)
ps:线性规划,利用Matlab的优化工具进行求解。步骤:--- 1、手写:f、A、b、Aeq、b、ub、lb矩阵;--- 2、求解:[x,fval,exitflag,output] = linprog(f,A,b,Aeq,beq,lb,ub)例如: ...原创 2018-12-25 09:29:34 · 409 阅读 · 0 评论 -
数值计算·第十三集:共轭梯度法(Numpy版)
ps:这是按照自己的理解写的程序,代码比较糙。献丑了,望海涵!#FR method'''min f(x) = 2x1^2+x2^2A = [[4,0],[0,2]]'''#original function#x is col vectorimport numpy as npdef func(x,A): return 0.5*(x.T@A@x)def fun...原创 2019-10-30 15:53:13 · 1237 阅读 · 0 评论 -
数值计算·第十二集:梯度下降法(Numpy版)
ps:这是按照自己的理解写的程序,代码比较糙。献丑了,望海涵!#Gradient descent method'''min f(x) = 2x1^2+x2^2A = [[4,0],[0,2]]'''#x is col vectorimport numpy as npdef func(x,A): return 0.5*(x.T@A@x)def func_der(x...原创 2019-10-30 15:52:20 · 393 阅读 · 0 评论 -
数值计算·第十一集:SOR法(Numpy版)
ps:这是按照自己的理解写的程序,代码比较糙。献丑了,望海涵!#Successive Over Relaxation methodimport numpy as npimport sysdef SOR(x0,A,b,w): if A.shape[1] != x0.shape[0] and A.shape[0] != b.shape[0]: sys.e...原创 2019-10-30 15:51:14 · 852 阅读 · 0 评论 -
数值计算·第十集:高斯-赛德尔迭代法(Numpy版)
ps:这是按照自己的理解写的程序,代码比较糙。献丑了,望海涵!#GaussSeidelIteration interationimport numpy as npimport sysdef GaussSeidel(x0,A,b): if A.shape[1] != x0.shape[0] and A.shape[0] != b.shape[0]: s...原创 2019-10-30 15:49:14 · 635 阅读 · 2 评论 -
数值计算·第九集:雅可比迭代(Numpy版)
ps:这是按照自己的理解写的程序,代码比较糙。献丑了,望海涵!#Jacobi interationimport numpy as npimport sysdef Jacobi(x0,A,b): if A.shape[1] != x0.shape[0] and A.shape[0] != b.shape[0]: sys.exit('Please try...原创 2019-10-30 15:47:09 · 883 阅读 · 0 评论 -
数值计算·第八集:二阶锥规划(CVXPY版)
Second-order cone program(二阶锥规划)标准形式:-A second-order cone program (SOCP) is an optimization problem of the form:#SOCPimport cvxpy as cpimport numpy as np#problem datamm,n,p,n_i = 3,10,5,5np...原创 2019-08-25 13:27:24 · 3880 阅读 · 0 评论 -
数值计算·第七集:二次规划(CVXPY版)
Quadratic program(二次规划)标准形式:-A quadratic program is an optimization problem with a quadratic objective and affine equality and inequality constraints.import numpy as npimport cvxpy as cp#probl...原创 2019-08-25 13:13:51 · 3941 阅读 · 2 评论 -
数值计算·第六集:最小二乘问题(CVXPY版)
Least-squares(最小二乘)标准形式:-In a least-squares, or linear regression, problem, we have measurements and and seek a vector x∈Rn such that is close to . Closeness is defined as the sum of the squared...原创 2019-08-25 13:10:47 · 1783 阅读 · 0 评论 -
数值计算·第五集:线性规划(CVXPY版)
PS:为了计算一个优化问题,特地去学习cvxpy库。确实好用,推荐大家!Linear program(线性规划)标准形式:-A linear program is an optimization problem with a linear objective and affine inequality constraints.#Example -Linear programimpo...原创 2019-08-25 13:03:53 · 1731 阅读 · 0 评论 -
数值计算·第四集:求多项式(组)的根以及导数(Matlab版)
例1:解方程,并且求的导数fa = [8,0,0,0,0,0,17,0,-3,1];%降幂排列。每项的系数。xk = roots(fa);disp(xk);% 运行结果:% -0.9578 + 0.5907i% -0.9578 - 0.5907i% -0.0062 + 1.1577i% -0.0062 - 1.1577i% 0.9627 + 0.57...原创 2018-09-22 20:32:49 · 1775 阅读 · 0 评论 -
数值计算·第三集:求解方程(组)的根(Matlab版)
本集的数值案例如下: Example 1: syms p x r solve(p*sin(x) == r) %chooses 'x' as the unknown and returns ans = asin(r/p) pi - asin(r/p) Example 2: ...原创 2018-09-22 19:36:23 · 1032 阅读 · 0 评论 -
数值计算·第二集:矩阵的条件数(Matlab版)
条件数的倒数:rcond(A):A为矩阵,rcond(A)为A的1范数的条件数的倒数的 估计值。如果A的条件数越好,那么其值在1.0附近;反之,则在无穷小附近。%%矩阵的条件数A = [11,2,3,4; 7,-2,-3,-4; 0.1,0.2,0.3,0.5; 5,7,8,9];%1范数的条件数Ac1 = cond(A,1);%2范数的条件数Ac2 = c...原创 2018-09-20 23:31:56 · 7950 阅读 · 0 评论 -
数值计算·第一集:向量、矩阵的范数(Matlab版)
Tip:各种范数的定义。%%计算向量或者矩阵的一范数、二范数、无穷范数、p范数、F范数X = [1,-1,2,3] ;Y = [-0.5,89,0.06,-12]';A = [1,2,3,4;1,-2,-3,-4;0.1,0.2,0.3,0.5;5,7,8,9];%向量X的范数X1 = norm(X,1);X2 = norm(X);Xinf = norm(X,inf);%p...原创 2018-09-15 23:36:23 · 1379 阅读 · 0 评论