minimize energy of piecewise linear mass-凯发k8网页登录
this example shows how to use the problem-based approach to find the equilibrium position of a mass-spring system hanging from two anchor points. the springs have piecewise linear tensile forces. the system consists of masses in two dimensions. mass is connected to springs and . springs and are also connected to separate anchor points. in this case, the zero-force length of spring is a positive length , and the spring generates force when stretched to length . the problem is to find the minimum potential energy configuration of the masses, where potential energy comes from the force of gravity and from stretching the nonlinear springs. the equilibrium occurs at the minimum energy configuration.
this illustration shows five springs and four masses suspended from two anchor points.
the potential energy of a mass at height is , where is the gravitational constant on earth. also, the potential energy of an ideal linear spring with the spring constant stretched to length is . in the current model, the spring is not ideal, but it has a nonzero resting length .
the mathematical basis of this example comes from lobo, vandenberghe, boyd, and lebret . for a solver-based version of this example, see .
mathematical formulation
the location of mass is , with the horizontal coordinate and vertical coordinate . mass has potential energy due to gravity of . the potential energy in spring is , where is the length of the spring between mass and mass . take anchor point 1 as the position of mass 0, and anchor point 2 as the position of mass . the preceding energy calculation shows that the potential energy of spring is
.
reformulating this potential energy problem as a second-order cone programming problem requires the introduction of some new variables, as described in lobo . create variables equal to the square root of the term .
let be the unit column vector . then . the problem becomes
(1)
now consider as a free vector variable, not given by the previous equation for . incorporate the relationship between and in the new set of cone constraints
(2)
the objective function is not yet linear in its variables, as required for coneprog
. introduce a new scalar variable . notice that the inequality is equivalent to the inequality
. (3)
now the problem is to minimize
(4)
subject to the cone constraints on and listed in (2) and the additional cone constraint (3). cone constraint (3) ensures that . therefore, problem (4) is equivalent to problem (1).
the objective function and cone constraints in problem (4) are suitable for solution with coneprog
.
matlab® formulation
define six spring constants , six length constants , and five masses .
k = 40*(1:6); l = [1 1/2 1 2 1 1/2]; m = [2 1 3 2 1]; g = 9.807;
define optimization variables corresponding to the mathematical problem variables. for simplicity, set the anchor points as two virtual mass points x(1,:)
and x(end,:)
. this formulation allows each spring to stretch between two masses.
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);
create an optimization problem and set the objective function to the expression in (4).
prob = optimproblem; obj = dot(x(2:(end-1),2),m)*g y; prob.objective = obj;
create the cone constraints corresponding to expression (2).
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;
specify the anchor points anchor0
and anchorn
. create equality constraints specifying that the two virtual end masses are located at the anchor points.
anchor0 = [0 5]; anchorn = [5 4]; anchorcons = optimeq(2,2); anchorcons(1,:) = x(1,:) == anchor0; anchorcons(2,:) = x(end,:) == anchorn; prob.constraints.anchorcons = anchorcons;
create the cone constraint corresponding to expression (3).
ycone = norm([2*t;(1-y)]) <= 1 y; prob.constraints.ycone = ycone;
solve problem
the problem formulation is complete. solve the problem by calling solve
.
[sol,fval,eflag,output] = solve(prob);
solving problem using coneprog. optimal solution found.
plot the solution points and the anchors.
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
you can change the values of the parameters m
, l
, and k
to see how they affect the solution. you can also change the number of masses; the code takes the number of masses from the data you supply.
references
[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. .