Math Is Fun Forum

  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2006-01-21 11:17:57

nikad
Member
Registered: 2006-01-21
Posts: 3

A formula driving me crazy, need help please!

I have the following:

a-b=X

I need one single formula (that uses only addition, substraction, multiplication or division) where if X is a positive number the result will be 1 and if X is a negative number the result will be -1 or 0

Is this possible?

Thanx in advance!
nikwave

Offline

#2 2006-01-21 11:57:16

mathsyperson
Moderator
Registered: 2005-06-22
Posts: 4,900

Re: A formula driving me crazy, need help please!

How about |X| ÷ X?

That formula will give 1 if X is positive, -1 if X is negative and won't work if X is 0.

Edit: |X| abs (X). But you figured that out anyway. smile


Why did the vector cross the road?
It wanted to be normal.

Offline

#3 2006-01-21 12:04:09

nikad
Member
Registered: 2006-01-21
Posts: 3

Re: A formula driving me crazy, need help please!

mathsyperson wrote:

How about |X| ÷ X?

That formula will give 1 if X is positive, -1 if X is negative and won't work if X is 0.

Excuse my ignorance, but if i do X ÷ X I get 1 if X is positive, but if X is negative I still get 1, unless |X| means absolute value which I am not sure it will be recognized on a computer.
I appreciate your help
nik

Last edited by nikad (2006-01-21 12:07:02)

Offline

#4 2006-01-21 12:07:48

nikad
Member
Registered: 2006-01-21
Posts: 3

Re: A formula driving me crazy, need help please!

I will try to compute the absolute value somehow, you ruuuuuuuuuuuuuule!
nik

Offline

#5 2006-01-21 12:41:10

irspow
Member
Registered: 2005-11-24
Posts: 1,055

Re: A formula driving me crazy, need help please!

Here you go:

x³ / ((x²)^9)^(1/6)

That will work but I don't know how you would do it in computer language.

x³ / √(x^6)

That might be easier.


I am at an age where I have forgotten more than I remember, but I still pretend to know it all.

Offline

#6 2006-01-21 12:59:52

mathsyperson
Moderator
Registered: 2005-06-22
Posts: 4,900

Re: A formula driving me crazy, need help please!

Wouldn't it be simpler to just have x/√x² if you're doing it that way?


Why did the vector cross the road?
It wanted to be normal.

Offline

#7 2006-01-21 13:02:09

irspow
Member
Registered: 2005-11-24
Posts: 1,055

Re: A formula driving me crazy, need help please!

Some people......just kidding.  Of course it would, but I am not the sharpest knife in the drawer you know?


I am at an age where I have forgotten more than I remember, but I still pretend to know it all.

Offline

#8 2006-01-21 13:05:16

mathsyperson
Moderator
Registered: 2005-06-22
Posts: 4,900

Re: A formula driving me crazy, need help please!

Hehe, sorry. I'll try to go easy on you from now on. smile


Why did the vector cross the road?
It wanted to be normal.

Offline

#9 2006-01-21 13:08:26

irspow
Member
Registered: 2005-11-24
Posts: 1,055

Re: A formula driving me crazy, need help please!

Pour it on.  I am a glutton for punishment.  That is why I keep posting answers when I know that I will be corrected eventually.


I am at an age where I have forgotten more than I remember, but I still pretend to know it all.

Offline

#10 2006-01-21 19:51:55

kempos
Member
Registered: 2006-01-07
Posts: 77

Re: A formula driving me crazy, need help please!

[x+abs(x)]/2x

positive = 1
negative = 0

Offline

#11 2006-01-21 20:33:39

Ricky
Moderator
Registered: 2005-12-04
Posts: 3,791

Re: A formula driving me crazy, need help please!

Assuming that you are programming this...

unless |X| means absolute value which I am not sure it will be recognized on a computer.

Absolute value is extremely easy to do on a computer.  All it requires is to switch the very first bit of a signed number and then subtract that from the highest possible signed value.  Most languages support an abs() function, but it also works if you just do: x = (unsigned int) x or something similar.

But if you're on a computer, the above isn't needed.

if (X < 0) return -1; return 1;

x³ / ((x²)^9)^(1/6)

That will work but I don't know how you would do it in computer language.

Pretty easy actually:

(x*x*x) / pow((pow(x, 18)), 1/6)

If your language doesn't support a power function, you can write it yourself, although doing non integral powers is a bit tricky.  But, as I said, you don't need to do all this.

Last edited by Ricky (2006-01-21 20:35:20)


"In the real world, this would be a problem.  But in mathematics, we can just define a place where this problem doesn't exist.  So we'll go ahead and do that now..."

Offline

Board footer

Powered by FluxBB