! Illustrating numerical integration in LINGO;
! Keywords: Integration, Definite integral, Numerical integration;
! Here we input some data to be used anywhere in a LINGO model;
DATA:
a0 = 5;
a1 = 12;
a2 = 3;
a3 = 2;
xl = 1;
xu = 4;
ENDDATA
! A procedure is a set of code we can call anywhere
in a CALC section;
PROCEDURE FOF:
y = a0 + a1*x + a2*x^2 + a3*x^3;
ENDPROCEDURE
CALC:
! Compute the integral over xl <= x <= xu,
where the value of y as a function of x is given by the procedure FOF;
@SET('TERSEO',2); ! Set default output level to super terse;
yint = @INTEGRAL( FOF, x, xl, xu, y);
@WRITE(' The integral of ',a0,' + ',a1,'*x + ',a2,'*x^2 + ',a3,'*x^3',@NEWLINE(1));
@WRITE('over the interval ',xl,' <= x <= ',xu,', is ', yint, @NEWLINE(1));
ENDCALC
|