MatMod logo

A simple modeling example (example1)

Run LPL Code  ,  PDF Document

Problem

My bother and I are together 20 years old. My brother is 2 years younger than I am. What is our age?

Modeling Steps

How to solve this problem? A first method is “trying”. Just guess! So suppose I am 10, then my brother must be 10 too, but the difference then is 0. If I am 12, my brother must be 8, the difference is 4, it doesn’t match either. Well, in between might work: 11 and 9 is 20 and the difference is 2. Bingo!

Another method is to look systematically through all possibilities…

A systematical way is to use math: Let x and y be positive numbers representing my age and my brother’s age. Then we have

x + y = 20   and   y = x - 2

insert y into the first equation: x + x 2 = 20, so: x = 11.

Listing 1: The Complete Model implemented in LPL [2]

model exercise1 "A simple modeling example"; 
  variable x    "my age"; 
           y    "my brother's age"; 
  constraint 
    A: y = x-2  "y is two less than x"; 
    B: x+y = 20 "x and y together is twenty"; 
  solve; 
  Write('My age is : %2d' n', x); 
  Write('My brothr' 's age is: %2d' n', y); 
  Draw.Scale(10,-10); 
  Draw.Arrow(0,0,22,0); Draw.Text('x',19,-1); 
  Draw.Text('11',10.2,-1.5); 
  Draw.Arrow(0,0,0,22); Draw.Text('y',-1,19); 
  Draw.Text('9',-1.5,8.5); 
  {i in 1..20} Draw.Line(i,0,i,0.5); 
  {i in 1..20} Draw.Line(0,i,0.5,i); 
  Draw.Line(20.5,-.5,-.5,20.5,3); 
  Draw.Line(1.5,-.5,14,12,3); 
  Draw.DefLine('line.dash',18,7); 
  Draw.Line('#dash',-.5,9,15,9); 
  Draw.Line('#dash',11,-.5,11,15); 
end

References

[1]   MatMod. Homepage for Learning Mathematical Modeling :  https://matmod.ch.

[2]   Hürlimann T. Reference Manual for the LPL Modeling Language, most recent version. https://matmod.ch/lpl/doc/manual.pdf.