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

Dividing Paper Puzzle

When I was young, I would fold a sheet of letter paper in half, for origami projects. It occurred to me that the two halves looked almost the same as the whole sheet of paper - except they were smaller. I could see they weren't exactly the same shape; they were off by a little bit. But the idea stuck in my head. You can use a pen, instead of scissors, to halve the paper. Those rectangles all have the same shape, but are different sizes. One night when I was 12, I thought about my idea. I wondered if it was possible to have a sheet of paper that could be cut in half, resulting in 2 smaller versions of the same paper. That would be neat, to be able to cut a paper in half and get 2 papers that had the same exact shape. If that were possible, then you could cut  those  papers, too; and the resulting papers would have the same shape as all the other papers. You could keep cutting in half forever, and each paper, no matter how small, would have the same shape as all the others. I HAD to

Pluto No Longer on the Horizon

This morning, New Horizons became the first spacecraft to make a flyby observation of the Pluto system. During the mission, the spacecraft captured the most detailed photographs of Pluto's surface we've ever had, and possibly ever will have. It also found many new properties including size, mass, atmosphere, and surface composition. In a period of a few hours, we discovered more about Pluto than we've found in the 85 years since Clyde Tombaugh captured its first photograph. Before After  (images credit: NASA) To complete this mission, the spacecraft flew for more than 9 years through the emptiness of space. This may sound like a long time, but it's actually amazingly quick. In fact, New Horizons set the record for the fastest speed at launch, and during the flyby, the spacecraft was moving at a rate of over 30,000 mph, or roughly 50 times the speed of sound. Picture an object twice as heavy as a grand piano moving 25 times faster than a bullet from a gun. Yikes. The man

Gravity

Imagine the universe is filled with water. Instead of empty space, every inch of it contains pure water. No planets, no stars, only water. What happens? And what would happen if an air bubble formed? The answer to this question requires a basic understanding of gravity. Gravity is very important. It helps hold matter together, bends light, and distorts space-time (which, incidentally, is how it bends light). It also makes it possible to play football, and as Americans are big football fans, they would certainly agree that we couldn't live without it. Unfortunately, many Americans don't understand how gravity works. Admittedly, scientists haven't figured out a lot of things, but we do understand it well enough to make predictions and model physical events. One of the important things about gravity is that its strength is proportional to the inverse of the square of the distance. In other words, it gets weaker as you get farther away, based on the equation: F = c/d 2 where c