# `quadprog` のウォーム スタート

この例では、大規模で密な二次問題の求解をウォーム スタート オブジェクトで高速化する方法を示します。`N` 個の変数と `10N` 個の線形不等式制約をもつ、スケール化した問題を作成します。`N` を 1000 に設定します。

```rng default % For reproducibility N = 1000; rng default A = randn([10*N,N]); b = 5*ones(size(A,1),1); f = sqrt(N)*rand(N,1); H = (4+N/10)*eye(N) + randn(N); H = H + H'; Aeq = []; beq = []; lb = -ones(N,1); ub = -lb;```

`quadprog` のために、ゼロから開始するウォーム スタート オブジェクトを作成します。

```opts = optimoptions('quadprog','Algorithm','active-set'); x0 = zeros(N,1); ws = optimwarmstart(x0,opts);```

```tic [ws1,fval1,eflag1,output1,lambda1] = quadprog(H,f,A,b,Aeq,beq,lb,ub,ws);```
```Minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance. <stopping criteria details> ```
`toc`
```Elapsed time is 9.221035 seconds. ```

`nnz(lambda1.ineqlin)`
```ans = 211 ```
`nnz(lambda1.lower)`
```ans = 0 ```
`nnz(lambda1.upper)`
```ans = 0 ```

`output1.iterations`
```ans = 216 ```

```idx = randi(N); f(idx) = 2*f(idx);```

```tic [ws2,fval2,eflag2,output2,lambda2] = quadprog(H,f,A,b,Aeq,beq,lb,ub,ws1);```
```Minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance. <stopping criteria details> ```
`toc`
```Elapsed time is 1.490214 seconds. ```

ソルバーが新しい問題を解く時間が大幅に短縮されています。

`nnz(lambda2.ineqlin)`
```ans = 214 ```
`nnz(lambda2.lower)`
```ans = 0 ```
`nnz(lambda2.upper)`
```ans = 0 ```

`norm(ws2.X - ws1.X)`
```ans = 0.0987 ```
`norm(ws2.X)`
```ans = 2.4229 ```

この速度差は、ソルバーで必要となる反復回数が大きく減少したことに大きく起因しています。

`output2.iterations`
```ans = 29 ```