# 基于问题的锥规划最小化分段线性质量-弹簧系统的能量

### 数学表示

$Energy\left(i\right)=\frac{k\left(i\right)\left(‖x\left(i\right)-x\left(i-1\right)‖-l\left(i\right){\right)}^{2}}{2}$.

`$t\left(i\right)=\sqrt{\frac{k\left(i\right)\left(‖x\left(i\right)-x\left(i-1\right)‖-l\left(i\right){\right)}^{2}}{2}}.$`

$e$ 为单位列向量 $\left[\genfrac{}{}{0}{}{0}{1}\right]$。则 ${x}_{2}\left(i\right)={e}^{T}x\left(i\right)$。问题变成了

$\underset{x,t}{\mathrm{min}}\left(\sum _{i}gm\left(i\right){e}^{T}x\left(i\right)+‖t{‖}^{2}\right).$ (1)

$‖x\left(i\right)-x\left(i-1\right)‖-l\left(i\right)\le \sqrt{\frac{2}{k\left(i\right)}}t\left(i\right).$ (2)

$‖\left[\genfrac{}{}{0}{}{2t}{1-y}\right]‖\le 1+y$.(3)

$\underset{x,t,y}{\mathrm{min}}\left(\sum _{i}gm\left(i\right){e}^{T}x\left(i\right)+y\right)$ (4)

### MATLAB® 表示

```k = 40*(1:6); l = [1 1/2 1 2 1 1/2]; m = [2 1 3 2 1]; g = 9.807;```

```nmass = length(m) + 2; % k and l have nmass-1 elements % m has nmass - 2 elements x = optimvar('x',[nmass,2]); t = optimvar('t',nmass-1,'LowerBound',0); y = optimvar('y','LowerBound',0);```

```prob = optimproblem; obj = dot(x(2:(end-1),2),m)*g + y; prob.Objective = obj;```

```conecons = optimineq(nmass - 1); for ii = 1:(nmass-1) conecons(ii) = norm(x(ii+1,:) - x(ii,:)) - l(ii) <= sqrt(2/k(ii))*t(ii); end prob.Constraints.conecons = conecons;```

```anchor0 = [0 5]; anchorn = [5 4]; anchorcons = optimeq(2,2); anchorcons(1,:) = x(1,:) == anchor0; anchorcons(2,:) = x(end,:) == anchorn; prob.Constraints.anchorcons = anchorcons;```

```ycone = norm([2*t;(1-y)]) <= 1 + y; prob.Constraints.ycone = ycone;```

### 求解问题

`[sol,fval,eflag,output] = solve(prob);`
```Solving problem using coneprog. Optimal solution found. ```

```plot(sol.x(2:(nmass-1),1),sol.x(2:(nmass-1),2),'ro') hold on plot([sol.x(1,1),sol.x(end,1)],[sol.x(1,2),sol.x(end,2)],'ks') plot(sol.x(:,1),sol.x(:,2),'b--') legend('Calculated points','Anchor points','Springs','Location',"best") xlim([sol.x(1,1)-0.5,sol.x(end,1)+0.5]) ylim([min(sol.x(:,2))-0.5,max(sol.x(:,2))+0.5]) hold off```

### 参考资料

[1] Lobo, Miguel Sousa, Lieven Vandenberghe, Stephen Boyd, and Hervé Lebret.“Applications of Second-Order Cone Programming.”Linear Algebra and Its Applications 284, no. 1–3 (November 1998):193–228. `https://doi.org/10.1016/S0024-3795(98)10032-0`.