Waves and slope

Physics, Math(s), Biology, Chemistry, Space, Earth, History and other related questions

Waves and slope

Postby ulillillia » Tue Sep 01, 2009 7:38 pm

I need to figure out the slope of a wave. The wave is nothing more than a cosine curve with a wavelength of 128 pixels and a height of 16 pixels. For a given pixel across the wavelength, what is the slope? The far edge of the very first pixel is the highest point of the wave with the far left of pixel number 64 being the trough (the lowest point). The steepest slope should be at pixel 31, 32, 95, and 96. How do I find out what the slope is for this case?
High elevation is the best elevation - the higher, the better the view!
User avatar
ulillillia
 
Posts: 124
Joined: Sat May 16, 2009 9:08 pm
Location: USA

Re: Waves and slope

Postby drew » Tue Sep 01, 2009 10:40 pm

ulillillia wrote:I need to figure out the slope of a wave. The wave is nothing more than a cosine curve with a wavelength of 128 pixels and a height of 16 pixels. For a given pixel across the wavelength, what is the slope? The far edge of the very first pixel is the highest point of the wave with the far left of pixel number 64 being the trough (the lowest point). The steepest slope should be at pixel 31, 32, 95, and 96. How do I find out what the slope is for this case?

Assuming the amplitude is 8 pixels (16 from peak to trough), then the equation for your wave is:

y = 8*cos(2*pi/128 * x)

The slope is the derivative of this curve:

y' = -16*pi/128 * sin(2*pi/128 * x)

which reduces to:

y' = -pi/8 * sin(pi/64 * x)

So the extrema for the slope are -pi/8 and pi/8.

Drew
drew
 
Posts: 283
Joined: Thu May 21, 2009 12:31 am

Re: Waves and slope

Postby ulillillia » Wed Sep 02, 2009 7:17 pm

The only question mark I have with your response that I can tell is the angle units. Will the result be in degrees or radians? I don't see any reference to this. Given your "pi/8" case, I'm guessing it's radians since a half of a degree doesn't make sense but 20 or so degrees does.

Edit: Something isn't right. If I reduce the amplitude, the slope should be more gentle. If I reduce the wavelength, the slope should get steeper. That's not what I'm getting. In my Excel spreadsheet, I have this as the formula:

=MOD(PI()/(O71/2) * SIN(PI()/(N71/2)*G71)*180/PI()+360, 360)

This, in a way, becomes:

Result = mod(pi/(HeightPixels/2) * sin(pi/(WaveLength/2)*PixelNumber)*180/pi+360, 360)

HeightPixels would be the 16 I gave and WaveLength would be the 128. Since I want the result to be expressed in degrees, I have this shown. With the original values used and pixel number 32, I get 22.5. If I cut wavelength to 64 and use pixel 16, I get the same result of 22.5 but it should be significantly steeper. With wavelength at 128 and a Wave Height of 32, using pixel 32, I get 11.25. With a greater height over the same wavelength, it would be logical for the slope to be steeper, not gentler. Did I copy the formula incorrectly or is there something else?
High elevation is the best elevation - the higher, the better the view!
User avatar
ulillillia
 
Posts: 124
Joined: Sat May 16, 2009 9:08 pm
Location: USA

Re: Waves and slope

Postby Major Tom » Wed Sep 02, 2009 9:33 pm

The slope will be in units of (y pixels) / (x pixels), so for example, if you have the line:
y = 2x
Its slope is 2, because for every x unit it changes by two y units.

If you need an angle, do arctan to the result.

Major T.
Major Tom
 
Posts: 318
Joined: Sun Jun 28, 2009 8:58 am
Location: Medford, MA

Re: Waves and slope

Postby ulillillia » Wed Sep 02, 2009 10:40 pm

If it was based on slope in the y:x format, then where is drew getting the pi/8 case? A slope of 0.393 makes sense here, but only in this example instance. Change the wave height to 32 instead of 16 (for an amplitude of 16 instead of 8) and the slope decreases which can't be right. If I change the wave length, stretching it out, the slope shouldn't stay the same at the steepest point.
High elevation is the best elevation - the higher, the better the view!
User avatar
ulillillia
 
Posts: 124
Joined: Sat May 16, 2009 9:08 pm
Location: USA

Re: Waves and slope

Postby Major Tom » Wed Sep 02, 2009 10:52 pm

If you have cosine wave going from +A to -A with a wavelength of L, then the wave is:
y = A * cos(2*pi * x / L)
And its slope is:
y' = -2*pi*A / L * sin(2*pi * x / L)
Major Tom
 
Posts: 318
Joined: Sun Jun 28, 2009 8:58 am
Location: Medford, MA

Re: Waves and slope

Postby ulillillia » Wed Sep 02, 2009 11:15 pm

Thanks, now it's working. This is my result (based on the center of the pixel:

=ATAN(-2*PI()*(O71/2) * SIN(2*PI()*(G71+0.5)/N71)/N71)*180/PI()

With spreadsheet cell references adjusted, it's, instead this:

SlopeDegrees = atan(-2*pi*(WaveHeight/2) * SIN(2*pi*(PixelNumber+0.5)/WaveLength)/WaveLength)*180/pi

Thanks!
High elevation is the best elevation - the higher, the better the view!
User avatar
ulillillia
 
Posts: 124
Joined: Sat May 16, 2009 9:08 pm
Location: USA

Re: Waves and slope

Postby drew » Thu Sep 03, 2009 12:39 am

ulillillia wrote:Thanks, now it's working. This is my result (based on the center of the pixel:

=ATAN(-2*PI()*(O71/2) * SIN(2*PI()*(G71+0.5)/N71)/N71)*180/PI()

With spreadsheet cell references adjusted, it's, instead this:

SlopeDegrees = atan(-2*pi*(WaveHeight/2) * SIN(2*pi*(PixelNumber+0.5)/WaveLength)/WaveLength)*180/pi

Thanks!

I see Major Tom got here before I did...thanks for filling in.

Nick, you can see I had 128 in two places in the equation before I reduced. I should have included a step where I left the variables in so you'd see how to make those adjustments.

Drew
drew
 
Posts: 283
Joined: Thu May 21, 2009 12:31 am

Re: Waves and slope

Postby drew » Sat Sep 05, 2009 8:18 pm

ulillillia wrote:I need to figure out the slope of a wave. The wave is nothing more than a cosine curve with a wavelength of 128 pixels and a height of 16 pixels. For a given pixel across the wavelength, what is the slope? The far edge of the very first pixel is the highest point of the wave with the far left of pixel number 64 being the trough (the lowest point). The steepest slope should be at pixel 31, 32, 95, and 96. How do I find out what the slope is for this case?

Hey Nick,

It occurred to me that I passed up on a good opportunity when I replied to your question. It turns out that the solution to this question is an extremely useful mathematical tool...and I'd like to explain how it's solved.

Let's look at the following graph of your problem. This is the equation of your wave, y=8*cos(2*pi*x/128)
derivative.png

Now, I've drawn lines to represent the values x=32 and f(32)=8*cos(2*pi*32/128)=0.

Now let's say we increment x by a small amount, which we'll call 'h'. We can evaluate the function at (x+h) to find the average slope between x and x+h.

So, the slope of the equation is "rise/run". Calculating the rise (assuming f(x) is your function 8*cos(2*pi*x/128) ):

rise = f(x+h) - f(x)

Now the run:

run = (x+h) - x = h

So now the average slope between x and x+h is the following:

Code: Select all
f(x+h)-f(x)
-----------
     h


Now, keep in mind that this is the *average* slope between x and x+h. Since the cosine curve isn't a straight line, the slope between x and x+h isn't the exact slope at x. We can get around this by making h very, very small. As your increment decreases, it more closely approximates a straight line.

Furthermore, there are methods to take the 'limit' of a function as h approaches zero. We would then say that the slope of your curve at x is:

Code: Select all
     f(x+h)-f(x)
lim  -----------
h->0      h


You can use a cell in Excel to calculate the above expression as a function of x and h. Make x equal 32, and make h equal 1, then progressively reduce h and see the value converge to the result that we calculated earlier. Let me know how that works.

You can use the same procedure to find the slope of any continuous function, provided it doesn't have a sharp bend (only curves).

Please let me know if you understand all of this. I'd like to continue further once you've looked at this.
You do not have the required permissions to view the files attached to this post.
drew
 
Posts: 283
Joined: Thu May 21, 2009 12:31 am

Re: Waves and slope

Postby Major Tom » Mon Sep 07, 2009 9:45 am

drew wrote:You can use the same procedure to find the slope of any continuous function, provided it doesn't have a sharp bend (only curves).

Shame on you, Drew! What about:
y = x * sin(1/x)
At x = 0?

That said, good explanation. :)

Major T.
Major Tom
 
Posts: 318
Joined: Sun Jun 28, 2009 8:58 am
Location: Medford, MA

Next

Return to Science

Who is online

Users browsing this forum: No registered users and 1 guest