top of page
Writer's pictureAdisorn O.

Example: Solving nonlinear constraint optimization problem using Lagrange Multiplier



The solution is L1 = 3.33 m, L2 = 6.67 m with Lambda = -0.5547.

The value of lambda is negative in this problem.


The F90 code is shown below


program main


real :: u,L1,L2, lambda, denom1, denom2

integer :: maxiter

real,allocatable :: a(:,:)

real,allocatable :: b(:)



! Problem statement

! Assume the top pole locations are at (0,0,10) and (x2,y2,5)

! where x2,y2 are user's defined constant

! The constraint are

! x2**2+y2**2+25 = 100 (distance between poles are 10 m)


! Objective function

u(L1,L2) = SQRT(25.0+L1**2)+SQRT(100.+L2**2)+lambda*(L1+L2-10.0)



allocate(a(3,3))

allocate (b(3))

maxiter = 5

L1 = 5.0 ; L2 = 5.0 ; lambda = 1.

do i = 1,maxiter

denom1 = SQRT(25.0+L1**2)

denom2 = SQRT(100.0+L2**2)

a(1,1) = (denom1-L1**2/denom1)/denom1**2; a(1,2) = 0. ;a(1,3) = 1.

a(2,1) =0.; a(2,2) = (denom2-L2**2/denom2)/denom2**2; a(2,3) = 1.0

a(3,1) = 1.0; a(3,2) = 1.0; a(3,3) = 0.0

b(1) = -(L1/denom1 + lambda)

b(2) = -(L2/denom2+lambda)

b(3) = -(L1+L2-10.)

! solve for delta_L1, delta_L2, delta_lambda

! from GaussElimination subroutine, the solution is store in b vector

CALL GaussElimination(a, b, 3)

L1 = L1 + b(1)

L2 = L2 + b(2)

lambda = lambda + b(3)

print*,'L1=',L1,'L2=',L2,'lambda=',lambda,'U=',u(L1,L2)

end do


end program





8 views
bottom of page