Skip to main content

Overview of Functions

Imagine you have a blender. To your blender, you add a couple scoops of ice cream and some milk. Then you press the buttons on the blender. Soon, you have a delicious vanilla milkshake. Next, you add strawberries and press buttons again. The result is even better than before: a strawberry milkshake.


Input
Output
Of course, strawberries aren't the only option. Suppose that, instead of strawberries, you added cocoa powder and avocado. The result is a chocolate-avocado milkshake. Or you could have added some mint leaves, for a mint milkshake. Or some peaches, for a peach milkshake.

In each of these cases, you pick the ingredient, and get a different milkshake. Whatever ingredient you pick, the result is always a milkshake. In other words, the blender took your ingredients, and returned a flavor of milkshake.

The blender is like a function.


In math, a function takes a number, and follows a set of rules to do something to that number. No matter what the number is, the function always follows the same rules.

Here's an example of a mathematical function:
f(x) = 2x + 3


Let me explain how this works. This function is being represented by the letter f. Any other letter would work, but I picked the letter f for this function. The function is going to take a number, multiply it by 2, and then add 3.

We can replace the x with any number. I'll try 4:
f(4) = 2(4) + 3 = 11


So f(4) is equal to 11.

Here's another example of a function:
g(x) = f(x + 1)


In this case, the function g is defined using another function f. We'll assume that this f is the same as the f I mentioned a little while ago. So what is g(4)? I'll work it out:
g(4) = f(4 + 1)
= f(5)
= 2(5) + 3
= 13


So g(4) = 13.



It is often helpful to visualize data from a function. One way of doing this is by listing values of f for different values of x in a table:

x f(x)
0 3
1 5
2 7
3 9
4 11
5 13
6 15

Tables can be very useful for organizing data.

Another method for visualizing data from a function is to graph it:
Parametric Plot
Min x: Max x:
Min y: Max y:

y(x) =
Other functions:
Step size:
Above, you can see a graphing application I wrote that will graph a function y(x). The whole graph is divided into a grid; at a given point on the graph, the x-value is the distance from the left side of the graph, and the value for y(x) is the distance from the bottom.

The default function being graphed is y(x) = 2x + 3.

Using a graph, we can find a value of y(x) for any value of x. To find y(3), start at the lower left corner, and move 3 units to the right. Then, move up until you get to the line. You'll have to go up 9 units to get to the line. Thus, y(3) = 9.

We can find y(1) by moving 1 unit to the right, and then moving up 5 units to the line: y(1) = 5. And we can find y(0) by starting all the way at the left, and moving up 3 units to the line.


Now how are functions useful?


Suppose you need to figure out how much to charge for a pizza (in dollars) based on the diameter (in inches). You could use the following function:
p(s) = s


So a 10" pizza would cost p(10) = $10, and a 14" pizza would cost $14. In other words, the pizza costs a dollar per inch.

But that doesn't make sense, mathematically. Nobody cares how wide the pizza is - they care how much there is. Instead of charging by the diameter, you should charge by the area. How about $0.10 per square inch? You'll need to use the formula for the area of a circle (remember that radius is half the diameter):
p(s) = π(s/2)2*0.10


In this case, a 10" pizza would cost π*25*0.10 ≈ 3.14*25*0.10 ≈ $7.85, and a 14" pizza would cost $15.39. These prices make much more sense.

You can also use the function the other way around. If you can calculate the price per square inch of a small pizza, you can determine the pizza-pricing function. Then you can use the function to calculate the optimum prices of other sizes of pizza (relative to the small pizza). Then check whether your calculated prices match the actual prices. Interestingly, large pizzas are usually cheaper (by area).

By using functions, you might actually be able to save money.

So math isn't only for programmers and physicists. It can be used by everyone else too.


Take Calculus for example...
But that'll have to wait.


New posts every month - subscribe for free!


Comments

Popular posts from this blog

Should Tau Replace Pi?

The digits of π, organized in a very new way Happy π-day! And happy π-month! Today's month and day - that is, March 14 or 3.14 - includes the first 3 digits of π. And today's month and year - March 2014 or 3.14 - also includes the first 3 digits of π. We won't have another double-day for π for the next 100 years, so enjoy this one! For the special occasion, I'm posting two π-related posts - one for π-month, and the other for π-day. In both posts, I'm setting the font size to approximately π * π + π + π. This is the first post, for π-month; to see the second, go to http://greatmst.blogspot.com/2014/03/pi-month-pi-day-post-2-5-common-pi-myths.html . In this post, I am including an essay I wrote about whether π or τ is the more superior constant. This was written for people who know very little about math, so the basic idea should be easy to understand even for people who are not mathematically inclined. Should Tau Replace Pi? A constant is any number or value that ne...

The Geminids

The Geminid meteor shower is coming up! At 2:00 AM, on December 14 (that's Thursday night, or Friday morning), you can see anywhere from 100 to 150 meteors per hour - depending on the sky and weather conditions. That's more than 1 meteor per minute! This particular meteor shower comes from a 5.1 km wide asteroid called 3200 Phaethon. Flecks of debris fall off this asteroid in a trail around the sun. These bits are called meteoroids . Every year, in December, Earth passes through this stream of meteoroids; when one of them enters Earth's atmosphere, it burns up and we see a meteor. If the meteor is brighter than Venus, it's called a fireball. Fireballs are much less common than meteors. This year, viewing conditions will be especially good; the peak occurs only 1 day past new moon. If you live in an area with lots of light pollution, you will definitely want to drive into the country. If you think the weather will be bad, go out a day or two before or after the peak. Kee...

Which Hurts More?

212° F Let's play a little game. I'll list a bunch of possible actions. Each action will have 2 variations, (a) and (b). You choose either (a) or (b), depending on which would be safer (or less painful). Each of the questions will involve an oven hot enough to bake a cake (350° F), and a pot of boiling water (assume we're at sea level). So... would you rather: 1.     (a) Stick your hand in the oven     (b) Stick your hand in the boiling water   ... for a period of 10 seconds 2.     (a) Leave a fork in the oven     (b) Leave a fork in boiling water   ... for a period of 15 minutes. Then hold the fork tight with your bare hand. 3. Fill a jar to the top with cool tap water. Then:    (a) Place the jar in the oven    (b) Place the jar in the boiling water   ... for a specific, but unknown, period of time. Then remove the jar and put your hand in it. First see if you can figure these out yourself. They shouldn't be too...