Skip to main content
gamedev.net
🔒 Locked

How to define Error function ?

Started by Alam 5 replies 700+ views
Original Post
Alam
Alam
Hello; I want to define an error function . Its graph is like a well. It is zero in between certain limit and very large outside. \............./ \.........../ \........./ \_______/ C1 C2 F(x) = 0 if x lies between C1 & C2. F(x) = Infinity(very large or increasing) if x C2 I took the approximation as F(x) = (x-C1)*(x-C1) * (C2-x)*(C2-x) It gives F(C1)=F(C2) = 0; But it is increasing between C1 & C2. If C1 & c2 are very closer to each other then it is ok. I want F to be 0 0r less than .00001 btween C1 & C2. How i can relate x, C1, C2 and (C2-C1) to proper F(x) Thanks Alam -- Learning never ends -- [edited by - alam on April 20, 2002 7:54:48 AM] [edited by - alam on April 20, 2002 7:56:55 AM] [edited by - Alam on April 20, 2002 7:59:44 AM]
Alam-- Learning never ends --
Cedric
Cedric
Well, your function should be defined into parts (sorry if that''s not the correct term in English). I can think of two ways to accomplish what you want:

1. Even if it''s not defined into parts, you can emulate this with rounding. For example, 10 * [|x|] is a well, and you can scale and move to fit your needs

2. f(x) = lim[n->inf] x ^ (2*n) is also a well, centered at 0, with the walls at -1 and +1. If you are unfamiliar with limits, know that
f(x) = x ^ n
should work as long as n is very large, and n is even.

Cédric
smilydon
smilydon
How about F(x)=m^(y) with y=(x-C1)*(x-c2) and m positive.

The y is less than zero in the interval between C1 and C2 and larger than zero outside. This makes that F(x)is between 0 and 1 in the interval and F(C1)=F(C2)=1. If m has a high value than the value of F(x) changes very fast from almost zero to very high around C1 and C2.

[edited by - smilydon on April 20, 2002 1:13:31 PM]
Alam
Alam
My required error function must possitive and minimum in the region between C1 & C2. I have to minimize the error function by search or by any method.

Yes F(X) = |X| is well but it is only zero at X=0. I want some range where F should be zero. Similarly X*X is more sharp well and is also zero at X=0.

As F(X) = m ^ (X-C1)*(X-C2) is concerned, I modified it as:

1: F(X) = m ^ (X-C1)*(X-C2) - 1 with m=2
It is zero at X=C1=C2. But it is negative between C1 & C2. The minimum value of this function is more negative as difference |C1-C2| increases.

2: F(X) = Square[m ^ (X-C1)*(X-C2) - 1]
Now the F is +ve. But it is greater than zero inside the well. There are two minimas at X=C1 & X=C2. If |C1-C2| is smaller it is acceptle for my case because whole range inside well will be approaching to zero.

Any suggestion that Error function must be possitive. Secondly it must be very very small (less that .0001) inside the well.
Note: |C1-C2| varies from 0.1-to-2.



Alam
-- Learning never ends --
Alam-- Learning never ends --
Cedric
Cedric
I didn't say |x|; I said |[x]|. I mean,

y = fabs(((int)((x - min) / (max - min))) * 1000.0f)

This will be 0 from min to max and at least 1000 elsewhere.

And the other solution could be
y = ((x - min - 1) / (max - min) * 2) ^ 20000

Cédric

Edit: Forgot fabs()

[edited by - cedricl on April 21, 2002 11:48:49 AM]
LilBudyWizer
LilBudyWizer
I think generally you would use the heavyside function. It is f(x)=x>0?1:0. So if you wanted it to be 2000 outside the interval (x1,x2) then f(x1-x)*2000+f(x-x2)*2000. x1-x is positive as long as x is less than x1 and zero of negative otherwise. The second term is positive as long as x is greater than x2. Between x1 and x2 both terms are zero or negative so the function returns zero. Within a C program though you would normally just use if (xx2) 2000 else 0. Even within mathematics you would generally use a piecewise defined function, i.e. define the function to be differant functions based upon the range of the parameter. You use the heavyside function in cases such as Laplace transforms when you have a definition that tells you what to do with the heavyside function.
Keys to success: Ability, ambition and opportunity.
Alam
Alam
Thanks to all for nice suggestions.

I don''t want to use piecewise function.

Thanks Cédric. I got idea from ur formulation.
F(x) = square[ {(|X-C1|+ |X-C2|)/|C2-C1|} - 1 ]
This function is showing good curve. It is perfectly zero inside and increasing outside.


Alam
-- Learning never ends --
Alam-- Learning never ends --

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.