Skip to main content

Posts

Showing posts with the label math

Jelly Ball

One thing I enjoy when programming is to make weird interactive computer-generated objects. In this post, I'm showing you... a blob. To see the blob, simply click on the black box. The blob will immediately appear. Once you have the blob, you can drag it around with your mouse - just press down and move it around. When you let go, the blob will snap back with a little jiggle. Click here! There are a few things I'd like to point out about the blob: First, when you stretch it, it actually gets narrower. When I designed this, I wanted it to shrink enough to look realistic, but not far enough that it looked weird. Second, notice that it drags faster depending on how far you stretch it. The speed at which it drags is proportional to the square of the distance stretched. I found that this was much more realistic than making it directly proportional to the stretch. Also, if you only stretch it slightly, it doesn't drag at all (this simulates static friction). Finally, the...

How to Find an Algorithm

For some reason I felt like this was relevant Happy Pi Day! The digits of the date - 3.14 - contain the first couple digits of π. But that's not all. If you add the year to get 3.14.16, you have the first 5 rounded digits of π. This is better than last year's version (3.14.15), which contained a truncated version of π. Today's date contains the more accurate rounded version. In this post, I'll describe the process of finding an algorithm to approximate the number π. There are three main types of algorithms. The first type converges very quickly to the correct solution; we use algorithms of this type in computers and calculators. The second type converges slowly, but is interesting to think about; we take this type of algorithm to mathematics conferences. The third type is slow to converge, and is boring to think about; these are pretty much useless so we get rid of them. This may be interesting to know, but I wasn't too worried about it when I wrote my Pi Day post l...

Efficient Acceleration

Here's a simple physics puzzle: suppose you're launching a model rocket. You want the rocket to go as high as possible. Is it better to design the rocket to: A. Use all of its fuel very quickly, and then use its momentum to travel high B. Use the fuel gradually over the whole duration of the flight In other words, what is the fuel consumption rate that will maximize the height of the flight path? For this problem, we can assume that the thrust is proportional to the fuel consumption rate. I'll try to post a solution to the problem in the future. New posts every month - subscribe for free !

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 ...

Ski Lift

Keystone on opening day Keystone Ski Resort just opened for the ski season on Friday. I went up to the resort that same day. There was only one run open (not including the beginner area at the top of the mountain), but it was awesome nevertheless! One of the main downsides to skiing on opening day is the number of people. There must have been about 2500 people on the mountain at the same time as me (not including the people snacking in the lodge). To keep the lines moving, the lift attendants made sure that the lift was completely full, with 4 people per chair. Even so, the wait to get on the lift took a long time. At one point when I was standing in line, a thought came to mind: the line was constantly being filled with more and more people, but it never got longer because the chair lift was carrying the people away at the same rate. So what would happen if the lift attendants only put 3 people on each chair, instead of 4? This would disrupt the balance: the inflow of skiers would be ...

CGI Sphere

Over my fall break (which lasted 1 day), I wrote a JavaScript program that would render a sphere. I thought it would be a fun way to practice math and programming skills simultaneously. As usual, I used my FireTools.js library to help with graphics as well as some other functions. To render the sphere, I wanted to take every pixel on the screen, and calculate the color of the pixel. The color would vary depending on which part of the sphere the pixel was displaying. If the part of the sphere was facing the light source, it would need to be brighter than a part of the sphere facing away from the light source. To find the brightness of each point on the surface, I first calculated the XYZ coordinates of that part of the sphere. This is also equal to the normal vector at that point. I took the dot product between the light source's direction and the normal vector. This is a mathematical operation that tells me whether the surface is aligned with the light source, as well as the percen...

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 fo...

5 Methods for Approximating Pi

Happy super-π day! π-day falls on March 14 every year, because the month-day combination results in 3-14, which are the first 3 digits of π. But this π-day is particularly special: include the year, and you get 3-14-15, the first 5 digits of π. We won't get another π-day like this for another 100 years, so you better enjoy this one! A particularly special time will be at 9:26:53 PM tonight, when we'll get 3-14-15 9:26:53, or the first 10 digits of π. In honor of the occasion, I'm going to post 5 simple methods for approximating the value of π. 1. String and Tape Measure Draw a circle with a diameter of 1 foot and put a piece of string around the edge. Cut the string until it's the right length, and then measure it with a tape measure. The string should be about π feet long. This can be implemented more accurately using a computer program: take the arc length of √ (1 - x 2 ) on the interval (-1, 1). The result should be π. var pi = 0; var step = 0.0001; var previous = 0...

Perlin Noise

Today I finished a JavaScript program that will generate random numbers, and then use those numbers to generate Perlin noise. Perlin noise is like a sort of organic randomness. First I'll explain randomness with regards to computing. Randomness is very important in the computer industry. Computers use randomness for all kinds of applications, including encryption, artificial intelligence, and computer graphics. When a human wants to generate a random number, they usually pick whatever pops into their head. It turns out that most people aren't very good at picking random numbers - I once did a small survey and quickly found that certain numbers were more popular than others. Hence, most people must flip quarters or roll dice to find truly random numbers. It's like that for computers, too. Computers are completely mechanical, and cannot calculate perfectly random numbers on their own. Devices exist that will "flip" virtual quarters (basically read a noisy signal),...

Fourier Series Grapher

Here's a simple JavaScript + HTML program I wrote. It will graph a given number of terms of a Fourier series. To graph a Fourier series, type the appropriate expressions into the text fields and click "Update." The text fields support JavaScript, so you can write a whole function in there if you need to. I also added some functions. even(x)  - returns true if x is even, false otherwise. odd(x)  - returns true if x is odd, false otherwise. power(x, a)  - returns x a . Some examples of input to try: odd(k)?(2/k):0 even(k)?(4/k/PI):0 odd(k)?(4/(k+PI)/k):0 The default Fourier series is equal to sin(2.5x) on (-π, π). Enjoy! Fourier Series Grapher Min x: Max x: Min y: Max y: *sin(k*x) *cos(k*x) Terms: '> To receive updates, subscribe now!

Euler Spiral

I was reading a calculus textbook when I noticed it said that cos( x 2 ) doesn't have an elementary antiderivative. Elementary antiderivative? Clearly, they were hiding something. They didn't say it didn't have an antiderivative; they said it didn't have an elementary  antiderivative. Of course, I wanted to know what the antiderivative was. If it wasn't elementary, it had to be really awesome. I looked up the integral of sin( x 2 ). Turns out, the integral cannot be expressed as anything other than itself. It's known as the Fresnel S integral, is written as S( x ), and is defined as the integral of sin( x 2 ). There's another Fresnel integral known as the Fresnel C integral which is written as C( x ) and defined as the integral of cos( x 2 ). I also saw some graphs of the integrals. One really cool graph involved the parametric equations x  = C( t ) and y  = S( t ), and was called the "Euler spiral." It had a cool spirally shape, and I immediately...

5 Common Pi Myths

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 16.1527897 pixels, which is approximately π * π + π + π. This is the second post, for π-day; for the first, go to  http://greatmst.blogspot.com/2014/03/pi-month-pi-day-post-1.html . In this post, I will list 5 common myths about π, and explain why they're wrong. 1. Pi is wrong Actually, π is defined as the ratio between the circumference of a circle and its diameter. There really isn't anything about this ratio that could possibly be wrong, because a ratio is a ratio - just like an orange is an orange or a piano is a piano. You can...

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...

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 ot...

Sine and Cosine

Trigonometry is the study of the relationship between the angles and sides of triangles. The two most essential parts of trig are the functions  sine and cosine . Both take an angle, and return a number. The way they work is really quite simple. A diagram showing sine (abbreviated sin) and cosine (cos) To find the sine of the angle θ , draw a circle with radius 1 on a graph, and put the circle's center at the origin of a graph. Find a point on the edge of the circle. The point makes an angle with the center of the circle; make sure that the angle is  θ . Sine of  θ  is the point's y-coordinate. Cosine is the point's x-coordinate. (See the picture to the right.) Sine and cosine are very useful for calculating heights and distances. For example, let's say somebody needs to know the height of a sky scraper, but isn't able to measure it physically with a tape. If he walks a certain distance away from it, and looks at the angle it subtends in the sky, he can us...