Started by Jun 14 2012 09:14 AM

,
9 replies to this topic

Posted 14 June 2012 - 09:14 AM

Given X a number from -1 to 1...

I need a formula that returns me Y, also in the -1 to 1 range, but with the following pattern

with the matches of

when x = -1 then y = -1

when x = -0.5 then y = -0.5

when x = 0 then y = 0

when x = 0.5 then y = 0.5

when x = 1 then y = 1

everything in between those values must follow the pattern

thanks in advance and regards,

Winsrp

I need a formula that returns me Y, also in the -1 to 1 range, but with the following pattern

with the matches of

when x = -1 then y = -1

when x = -0.5 then y = -0.5

when x = 0 then y = 0

when x = 0.5 then y = 0.5

when x = 1 then y = 1

everything in between those values must follow the pattern

thanks in advance and regards,

Winsrp

Posted 14 June 2012 - 09:23 AM

Without any particular constraint on the values (except the few selected points) other than it should follow the pattern, then y=x-A*sin(x*pi*2) gives a close match. The points match exactly, and tweak the constant A to match the desired curvature.

Posted 14 June 2012 - 09:48 AM

holy crap, that was fast!!, let me test it out a bit, and I'll let you know.

Posted 14 June 2012 - 09:53 AM

uhhh great results, using A from 0 to 0.17 it gives me great variation... THANKS A LOT!!!

Posted 14 June 2012 - 12:05 PM

@Brother Bob

Fascinating! I'd be quite interested to learn how you've managed to derive the formula from the OP's data. Could you perhaps elaborate a little?

Fascinating! I'd be quite interested to learn how you've managed to derive the formula from the OP's data. Could you perhaps elaborate a little?

Posted 14 June 2012 - 12:37 PM

Without any particular constraint on the values (except the few selected points) other than it should follow the pattern, then y=x-A*sin(x*pi*2) gives a close match. The points match exactly, and tweak the constant A to match the desired curvature.

How did you come up with this so fast? O__o

Posted 14 June 2012 - 12:38 PM

It's a mostly linear function on the form y=x. If you remove the linear component you have some periodic oscillating residual, which is close to a sine wave. The points where he constrained the curve just happened to coincide with the zero-crossing points of a sine wave; zero at x=-1, x=-0.5 and x=0.

**Edited by Brother Bob, 14 June 2012 - 12:39 PM.**

Posted 14 June 2012 - 12:38 PM

Tristan

its not too hard to know why he got it. I was thinking along the lines of xsin(2*pi*x) but that didnt match at all (don't know why that sprang). by having -Asin(2*pi*x) it will be 0 at +- .5 and 1 (since sin(pi) and sin(2*pi) is 0 leaving x + 0, in Bobs original equation

when it is between 0 and .5 it will minus off in a sinusoidal fashion, the same as it does adding between .5 and 1

its not too hard to know why he got it. I was thinking along the lines of xsin(2*pi*x) but that didnt match at all (don't know why that sprang). by having -Asin(2*pi*x) it will be 0 at +- .5 and 1 (since sin(pi) and sin(2*pi) is 0 leaving x + 0, in Bobs original equation

when it is between 0 and .5 it will minus off in a sinusoidal fashion, the same as it does adding between .5 and 1

Always improve, never quit.

Posted 14 June 2012 - 12:41 PM

May I?

The OP:s graph looks like a wave. That means sine/cosine functions may be usable. But that is not going upwards. You can make in go upwards if you add a function that goes upward. Like a simple linear function. According to the OP's graph, an y=x graph would definitely go through all the points the OP wants.

So what if we add the y=x function to a sine function?

There's a problem with that, a sine function y=x won't intersect the points where the OP wants.

BUT: The frequency of a sine function can be controlled by it's argument. A greater multiplier of x as the argument means bigger frequency (or less wavelength), smaller means smaller.

The wavelength of a sine function is 2*PI.

So to decrease it to the desired 1 unit of wavelength (wavelength is the up and down of a wave, that's repeated), we have to increase the argument's multiplier. That means we have to use 2*PI. (If you use a calculator, you can see that if you insert the appropriate x coordinates, you get the desired zeros for the sine, and the desired points in the final function).

One problem remains. Sine goes up first, not down. So, we can multiply the sine part of the final function with -1.

So, you got your equation.

Sorry, a drunk post

Anyway, manipulating sine/cosine function is quite easy to visualize.

If you multiple sine/cosine with a function, the "signed height of the bumps" will touch the function you multiply sine/cosine with.

If you add a function to sine/cosine, it's like sine/cosine sits on top of the function.

I hope that's clear, and sorry for posting drunk..

The OP:s graph looks like a wave. That means sine/cosine functions may be usable. But that is not going upwards. You can make in go upwards if you add a function that goes upward. Like a simple linear function. According to the OP's graph, an y=x graph would definitely go through all the points the OP wants.

So what if we add the y=x function to a sine function?

There's a problem with that, a sine function y=x won't intersect the points where the OP wants.

BUT: The frequency of a sine function can be controlled by it's argument. A greater multiplier of x as the argument means bigger frequency (or less wavelength), smaller means smaller.

The wavelength of a sine function is 2*PI.

So to decrease it to the desired 1 unit of wavelength (wavelength is the up and down of a wave, that's repeated), we have to increase the argument's multiplier. That means we have to use 2*PI. (If you use a calculator, you can see that if you insert the appropriate x coordinates, you get the desired zeros for the sine, and the desired points in the final function).

One problem remains. Sine goes up first, not down. So, we can multiply the sine part of the final function with -1.

So, you got your equation.

Sorry, a drunk post

Anyway, manipulating sine/cosine function is quite easy to visualize.

If you multiple sine/cosine with a function, the "signed height of the bumps" will touch the function you multiply sine/cosine with.

If you add a function to sine/cosine, it's like sine/cosine sits on top of the function.

I hope that's clear, and sorry for posting drunk..

**Edited by szecs, 14 June 2012 - 12:54 PM.**

Posted 14 June 2012 - 01:31 PM

Thank you all for these elaborate and insightful replies. (Whether they were written down whilst being intoxicated or not.)