二次方程优化
Posted Mr.ZeroW
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了二次方程优化相关的知识,希望对你有一定的参考价值。
在本文中,我们初步讨论一下二次方程的最优化,先贴出结论,感兴趣的同学可以继续往下看推论的过程,不想看推论的可以直接跳到最后看例子如何应用
对于最小化方程
解是
最小值是
发现matlab中没有LDU分解的函数,只有LU分解,先贴上LDU分解的代码,需要的同学可以复制下来。然后help 一下,有说明和例子。关于原理,这里就不赘述了,都是初等行变换
之后会稍微用到这个函数,不过喜欢手算的同学可以跳过这个
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % -------------------------- %INPUT %A: matrix; %-------------------------- %OUTPUT %L: lower triangular matrix %D: diagonal matrix %U: upper triangular matrix %-------------------------- %Example 1 %A = [4 -1 -3/2; -1 3 1]; %ldu(A) % %Example 2 %syms a b c d e f %ldu([a b c; b d e; c e f]) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function ldu(A) nn = size(A); n = nn(1); A = [A, eye(n)]; r = 0; for j = 1:(n - 1) r = r + 1; for i = (j + 1) : n A(i, :) = A(i, :) - A(i, j)/A(r, j)*A(r, :); end end L = inv(A(1 :n, (n+1) : 2*n)) D = diag(diag(A)) U = D\\A(1: n , 1: n) end
下面进入正题
贴上代码和运行结果
syms a b c ldu([a b; b c]);
所以方程变成
以上是关于二次方程优化的主要内容,如果未能解决你的问题,请参考以下文章