Formula for the midpoint of a line segment

I am taking pre-calculus at my school. We are required to use Mathematica. We have been doing simple stuff to get used to this program. Before this, I have never have used it.

Here what I have been inputting:

x1 = 2; y = 3; x2 = 4; y2 = 6;

For the slope I input

(y2 - y1) / (x2 - x1)

and evaluate with shift-enter. I get 1.5 on the next line.

I am trying to figure out how to compute the midpoint, I know the formula is

(x1 + x1/2), (y1 + y2/2)

I want the midpoint as coordinates, (x,y)

How can I make this computation?

• see Mean in the docs.
– kglr
Mar 3 '17 at 20:27
• I want to thank everyone who contributed to this post. Thanks again Goldberg and Stork for helping me out. I will be sure to return here for my questions! Mar 6 '17 at 17:36

Defining a function for midpoint, as D. G. Stork suggests, is good idea, but maybe too advanced for where you are in your Mathematica experience. So let's save function definition for the future and keep things simple.

A point in the xy-plane can be represented in Mathematica by list of two elements written as {x, y}. Lists can be added and subtracted just like individual numbers. Starting with the coordinates you give

x1 = 2; y2 = 3; x2 = 4; y2 = 6;

we can define two points, pt1 and pt2.

pt1 = {x1, y1}; pt2 = {x2, y2};

It is known from coordinate geometry that the midpoint of line segment bounded by two points, pt1 and pt2, is the mean point between p1 and p2, where "mean" is another word for average. So your midpoint is just

(pt1 + pt2)/2

{3, 9/2}

Mathematica can do symbolic as well as numerical computation. We can use this capability to generate the midpoint formula from the geometric definition.

The symbols used in symbolic computation must be value-free, that is, not have numbers assigned to them. The function Clear makes symbols value-free.

Clear[x1, y1, x2, y2]
pt1 = {x1, y1}; pt2 = {x2, y2};
(pt1 + pt2)/2

{(x1 + x2)/2, (y1 + y2)/2}

You have a typo in your formula for the mid-point.

When fixed, then use:

midPoint[x1_,x2_,y1_,y2_]:= {(x1+x2)/2, (y1+y2)/2}

midPoint[2,4,3,6]

*)

{3, 9/2}

*)