Is there such an equation where n=0 returns value t=0 or otherwise returns a constant, such as t=1? t = n/n works, but 0/0 results in a divsion by zero problem. Is there an equation to get the same result without division by zero?
Printable View
Is there such an equation where n=0 returns value t=0 or otherwise returns a constant, such as t=1? t = n/n works, but 0/0 results in a divsion by zero problem. Is there an equation to get the same result without division by zero?
y=x
x=1; y=1
x=0; y=0
No division by zero needed :)
Did you mean to return the same constant every time?
Return the same value for t no matter what n is, except when n is zero.
t = the equation of n
(I can't get the spacing to match up, but you see the point.)VB Code:
n = 1 t = 1 n = 0.00000000000001 t = 1 n = 958.54 t = 1 n = 65487 t = 1 n = -1 t = 1 n = -0.6598 t = 1 n = -9999 t = 1 n = -456.78 t = 1 n = 0 t = 0
i dont know y u dont want to use an if then statement but:
VB Code:
t = Abs(n <> 0)
This begs the question. What is the mathematical equation to determine n <> 0?Quote:
Originally posted by dis1411
i dont know y u dont want to use an if then statement but:
VB Code:
t = Abs(n <> 0)
what exactly r u trying to do?
youre not going to get it much simpler than what i gave
I guess I am asking for the mathematical equation for NOT. How can you manually calculate that something is NOT something? Specifically, that something is NOT zero? How can I take any n and trun it to 1, unless n = 0? Is there a formula for n <> 0. Or is there NOT?
WorkHorse: n <> 0 is a mathematical inequality, not an equality
as for this: t=|sgn n|Quote:
Originally posted by WorkHorse
Is there such an equation where n=0 returns value t=0 or otherwise returns a constant, such as t=1? t = n/n works, but 0/0 results in a divsion by zero problem. Is there an equation to get the same result without division by zero?
Does that mean t = n <> 0 cannot be expessed more simplicity? The equation operator NOT is what it is by definition and cannot be difined by another equation?Quote:
Originally posted by kedaman
WorkHorse: n <> 0 is a mathematical inequality, not an equality
Brilliant. That's the ticket. Thank you.Quote:
Originally posted by kedaman
as for this: t=|sgn n|
well, not is a boolean operator, and you should distinguish between boolean and aritmetic algebra
ooops i was thinking in VB
Here's a little trick i used in something recently:
Note that when n =0, fraction = 0*(-1)!/0! = 0Code:n*(n-1)!
----------
n!
and for all else the fraciton = 1;
I think there may be a slight problem though, as factorials aren't defined for all numbers (n must be a non-negative integer or .5 less than a non-negative integer), but i believe there is a general factorial function, which would provide what is needed.
For possibly simplifying n <> 0, the CPU's arithmetic and logic unit handles that by comparing the two numbers logically instead of using some arithmetic operations, so you'd have to find a function that happens to do what sql_lall's does to use the arithmetic method that you're after. BTW, that's pretty clever!
There is a small problem
n*(n-1)!
----------
n!
will fail if n or (n-1) is a negative number as factorial of negative number is not defined....
-1! is not defined...
so we can use abs for that....
just a little modification :
|n|*|(n-1)|!
----------
|n|!