You are on page 1of 3

Help with absolute value functions

Given
There are two absolute value functions. One where (a) is positive, the other negative. The two values of (a) are different. The functions intersect in a way that they form a quadrilateral.

Find
The perimeter of the quadrilateral. One way is to calculate the position of every corner, then calculate the distances between points. Is there a faster way?

Solution
Intersection Points Suppose one function has vertex (x1, y1) and slope m1. Suppose the other has vertex (x2, y2) and slope m2. If y1 > y2, the right side point of intersection (xr, yr) can be calculated from
In[1]:=

r1 = Solve@8yr - y1 == - m1 Hxr - x1L, yr - y2 m2 Hxr - x2L<, 8xr, yr<D@@1DD Simplify :xr m1 x1 + m2 x2 + y1 - y2 m1 + m2 , yr m2 y1 + m1 Hm2 Hx1 - x2L + y2L m1 + m2 >

Out[1]=

Similarly, the left side point of intersection (xl, yl) can be calculated from
In[2]:=

r2 = Solve@8yl - y1 == m1 Hxl - x1L, yl - y2 - m2 Hxl - x2L<, 8xl, yl<D@@1DD Simplify :xl m1 x1 + m2 x2 - y1 + y2 m1 + m2 , yl m2 y1 + m1 Hm2 H- x1 + x2L + y2L m1 + m2 >

Out[2]=

Line Segment Lengths The difference in x coordinates of these points is


In[3]:=

xdif = Simplify@Hxr - xlL . r1 . r2D 2 Hy1 - y2L

Out[3]=

m1 + m2

Now, we know by the Pythagorean theorem that the length of a line of slope m over a horizontal distance of 1 will be
In[4]:=

len@m_D :=

1 + m2

AbsoluteValue.nb

Consider the length of a pair of segments whose slope changes from m to -m at some point. It is the same as the length of one segment covering the same horizontal distance and having slope m.

Out[5]=

Perimeter So, the perimeter of our figure is the product of the horizontal distance and the sum of the lengths len[m1] and len[m2].
In[6]:=

perimeter@y1_, y2_, m1_, m2_D :=

2 Hy1 - y2L m1 + m2

Hlen@m1D + len@m2DL

Example
Suppose we have two absolute value functions as follows. One has vertex (1, 1) and slope 1. The other has vertext (-1, -5) and slope 2.
In[7]:=

88x1, y1<, m1< = 881, 1<, 1<; 88x2, y2<, m2< = 88- 1, - 5<, 2<;

Using the equations above, we can compute the right and left side points of intersection.
In[9]:=

8xr, yr< = 8xr, yr< . r1 5 1 : , > 3 3 8xl, yl< = 8xl, yl< . r2 :7 3 ,7 3 >

Out[9]=

In[10]:=

Out[10]=

AbsoluteValue.nb

For ease of manipulation, we will define the points as p1..p4 clockwise from (x1, y1).
In[11]:=

8p1, p2, p3, p4< = 88x1, y1<, 8xr, yr<, 8x2, y2<, 8xl, yl<<;

Here is a plot of the quadrilateral.


1

-2

-1

-1

Out[12]=

-2

-3

-4

-5

The lengths of the various segments will be


In[13]:=

segmentLengths = Norm 8p2 - p1, p3 - p2, p4 - p3, p1 - p4< : 2 3 2 , 8 3 5 , 4 3 5 , 10 3 2 >

Out[13]=

The sum of the segment lengths is the perimeter.


In[14]:=

perimeterHardWay = Total@segmentLengthsD Simplify 4J 2 + 5N

Out[14]=

We also know that we can compute the perimeter from the vertex position and slopes.
In[15]:=

perimeterEasyWay = perimeter@y1, y2, m1, m2D 4J 2 + 5N

Out[15]= In[16]:=

perimeterHardWay perimeterEasyWay True

Out[16]=

You might also like