Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Need help solving a non-linear equation for a script

Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
04-12-2007 02:52
I'm using some numbers from a fractal generated by hand and I'm trying to get the recursive function for the fractal, but I'm being thrown for a loop as to how to construct the equation.

t is my iteration number (time) in this case it allows for both negative and positive values


X=2^t


value chart for Xn and Yn


CODE

X_____Y
4.000|189.12500
2.000|187.62500
1.000|188.37500
0.500|188.00000
0.250|188.18750
0.125|188.09375


I know that Yn - Y(n-1) follows this pattern:

-1.5
.75
-.375
.1875
-.09375


that is, the difference between two y values is the negative half the previous y value (.75 is -1.5/-2, -.375 is .75/-2)


I'm just at a blank as to how to construct this into an equation which I can then feed into my script.
_____________________
My SLExchange shop

Typos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not.


The function is working perfectly fine. It's just not working the way you wanted it to work.
Ged Larsen
thwarted by quaternions
Join date: 4 Dec 2006
Posts: 294
04-12-2007 06:49
Sorry I can't help you -- don't know anything about fractals -- but the puzzle seems interesting. For a non-fractal knowledgeable person, could you explain just what you are trying to solve for?

Your value chart seems to be for values of t ranging from 2 to -3, for the X values anyhow. Do you mean Xt? Or is n something different? What are the Y values coming from?

Are you trying to come up with an equationthat will give you what you call Yn - Y(n-1)?

If so, your alternating + and - signs will mean that you'll want to start that equation with:

(-1)^n times something

The "something" seems to be exponentially decaying by a factor of 2, so: divide by 2^n

So, if I even understand what you're trying to get, would it be:

3.0 * [ (-1)^n ] / [ 2^n ]

That would seem to give you your Yn - Y(n-1), if ranging n from 1 incrementing upwards by 1 each time.

Or am I lost?
_____________________
- LoopRez, flexi prim skirt generating tool
- LinkRez, a necklace chain generator
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
04-12-2007 07:03
From: Ged Larsen
Sorry I can't help you -- don't know anything about fractals -- but the puzzle seems interesting. For a non-fractal knowledgeable person, could you explain just what you are trying to solve for?


The raw numbers for Y are the position along the X axis for each piece in the iteration, and the values for X is a multiplier for the size of the prim I'm using. both the X and Z coordinates for each prim follow this rule of behaviour (the way the Y value changes), with only a constant difference between them. The resulting fractal resembles a butterlfly of sorts.

From: someone

Your value chart seems to be for values of t ranging from 2 to -3, for the X values anyhow. Do you mean Xt? Or is n something different? What are the Y values coming from?


t is actually ranging from 2 to -3. X will always be a power of 2 (negative powers are decimals, positive powers will resemble the familiar 1,2,4,8,16,32,64 ... sequence, negative values for t produces x being 1/2, 1/4, 1/8, 1/16, etc...). The Y values is the x coordinate for each piece.

From: someone

Are you trying to come up with an equation that will give you what you call Yn - Y(n-1)?
no, this is just one of the steps I recall from my classes in solving a geometric formula. I could be wrong since it's been years since my last mathematics class of any kind.


From: someone

If so, your alternating + and - signs will mean that you'll want to start that equation with:

(-1)^n times something

The "something" seems to be exponentially decaying by a factor of 2, so: divide by 2^n

So, if I even understand what you're trying to get, would it be:

3.0 * [ (-1)^n ] / [ 2^n ]

That would seem to give you your Yn - Y(n-1), if ranging n from 1 incrementing upwards by 1 each time.

Or am I lost?


You're essentially on the right track. ultimately I need an equation that when I put in the X value for the T chart it spits out the Y value. I've a feeling it's going to be something like:

Y=a*-2^(b*2^t)+c

which I don't remember how to set up the series of equations to solve for a,b, and c respectively since it's a nonlinear (exponential) equation; a simple matrix solution will not render a correct result
_____________________
My SLExchange shop

Typos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not.


The function is working perfectly fine. It's just not working the way you wanted it to work.
Ged Larsen
thwarted by quaternions
Join date: 4 Dec 2006
Posts: 294
04-12-2007 07:44
I see, and nope, this is beyond my abilities :)

Good luck!
_____________________
- LoopRez, flexi prim skirt generating tool
- LinkRez, a necklace chain generator
Ee Maculate
Owner of Fourmile Castle
Join date: 11 Jan 2007
Posts: 919
04-12-2007 08:12
OK.. think I've transferred this from back of envelope to forum correctly...

treating your first term as term 0 (i.e. y(0) ) then what you have is

y(n) = 188.125 + (-1)^n * (1/2)^n

and

x(n) = 4 * (1/2)^n

giving

y(n) = 188.125 + (-1)^n * x(n)/4

This still involves that (-1)^n term which is a pain, but you can retrieve n from x(n) by taking logs:

n = log( x(n)/4)) / log (1/2)

but since you only care if n is even or odd you can use

log(x(n)) / log (1/2)

So finally your equation is

y = 188.125 + (-1)^[log(x)/log(0.5)] * 0.25* x

Plug in your x value and it should correctly give you your y value (unless I've made a mistake somewhere). I'll let you test it to make sure it works! :)
Ee Maculate
Owner of Fourmile Castle
Join date: 11 Jan 2007
Posts: 919
04-12-2007 08:20
P.S. Technically the problem you were solving was a linear one....

2*y(n) - y(n-1) - y(n-2) = 0

x(n) -0.5 x(n-1) =0
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
04-12-2007 09:26
From: Ee Maculate
OK.. think I've transferred this from back of envelope to forum correctly...

treating your first term as term 0 (i.e. y(0) ) then what you have is

y(n) = 188.125 + (-1)^n * (1/2)^n

and

x(n) = 4 * (1/2)^n

giving

y(n) = 188.125 + (-1)^n * x(n)/4

This still involves that (-1)^n term which is a pain, but you can retrieve n from x(n) by taking logs:

n = log( x(n)/4)) / log (1/2)

but since you only care if n is even or odd you can use

log(x(n)) / log (1/2)

So finally your equation is

y = 188.125 + (-1)^[log(x)/log(0.5)] * 0.25* x

Plug in your x value and it should correctly give you your y value (unless I've made a mistake somewhere). I'll let you test it to make sure it works! :)


I don't have acess to SL right now, but it looks like it's working from some quick numbers I plugged in. thanks a heap :D
_____________________
My SLExchange shop

Typos are forgiven; desecrating the english language with reckless abandon and necrophilic acts is not.


The function is working perfectly fine. It's just not working the way you wanted it to work.
Ee Maculate
Owner of Fourmile Castle
Join date: 11 Jan 2007
Posts: 919
04-12-2007 11:22
No probs.

:)