(!******************************************************* Mosel Example Problems ====================== file sosquad.mos ```````````````` Approximation of a nonlinear function in two variables by two SOS-2. (c) 2002 Dash Associates author: S. Heipcke *******************************************************!) model "sosquad" parameters NX=10 NY=10 end-parameters declarations RX=1..NX RY=1..NY DX: array(RX) of real DY: array(RY) of real FXY: array(RX,RY) of real end-declarations ! Sample data: a 10x10 grid to interpolate a quadratic function. forall(i in RX) DX(i):=i forall(j in RY) DY(j):=j forall(i in RX, j in RY) FXY(i,j) := (i-5)*(j-5) writeln(FXY) declarations lx: array(RX) of mpvar ! Weight on x co-ordinate ly: array(RY) of mpvar ! Weight on y co-ordinate lxy: array(RX,RY) of mpvar ! Weight on (x,y) co-ordinates x,y,f: mpvar end-declarations ! Definition of SOS sum(i in RX) DX(i)*lx(i) is_sos2 sum(j in RY) DY(j)*ly(j) is_sos2 ! Constraints forall(i in RX) sum(j in RY) lxy(i,j) = lx(i) forall(j in RY) sum(i in RX) lxy(i,j) = ly(j) sum(i in RX) lx(i) = 1 sum(j in RY) ly(j) = 1 ! Then x, y and f can be calculated using x = sum(i in RX) DX(i)*lx(i) y = sum(j in RY) DY(j)*ly(j) f = sum(i in RX,j in RY) FXY(i,j)*lxy(i,j) ! But of course there is a fair amount of degeneracy in the ! representation of P=(x,y) by the four points Q. end-model