[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
Solved

# javascript complicated math function formula!!!

Posted on 2007-10-17
Medium Priority
211 Views
Hi All,

Got a mind boggler,

I'm trying to build a function that returns x when it's fed with z.  Here's the formula:

180 = (((x-1)/x)/((1/z)*((x-1)/x)*(x*(19/(x*(x-1))))))

Anyone got a clue? is it even possible?

Many thanks
Jon
0
Question by:jondanger
• 4
• 4
• 3
• +2

LVL 9

Expert Comment

ID: 20091509
Hi,

Is this a question on Excel or Javascript ?

Regards,
Felix
0

LVL 75

Expert Comment

ID: 20091514
Do you not need to have
x=.........z............../180

in that formula?
0

LVL 14

Expert Comment

ID: 20091526
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<title>Untitled</title>
<script>
function getX(z){
for(x=0; x<1000; x++){
if(180 == (((x-1)/x)/((1/z)*((x-1)/x)*(x*(19/(x*(x-1))))))){
return 'x = ' + x;
break;
}
}
}
</script>
<body>
<form>
Value for Z:<input type="text" id="z"/>
</form>
</body>
</html>
0

LVL 9

Expert Comment

ID: 20091567
My suggestion is to place values for Z and X in two cells (say Z in B24 and X in C24) and put the result in say D24.

Now in D24 put the formula "= (((C24-1)/C24)/((1/B24)*((C24-1)/C24)*(C24*(19/(C24*(C24-1))))))"

Don't worry if the above formula gives an error result like "#Div/0"

Feed in the input value for Z in B24, and then go to Tools -> Goal Seek
Set Cell = D24  (As you have stored the result in D24)
To Value = 180 (as this is your expected result for the formula)
By Changing Cell = C24 (As this cell contains the value of X which you are searching for.

If you have your values in other cells, change the cell addresses accordingly.
0

LVL 75

Expert Comment

ID: 20091575
@cesar:
<form>
Value for Z:<input type="text" NAME="z"/>
</form>
0

Author Comment

ID: 20091617
Hi guys, thanks for the quick replies,

Felix: ultimately javascript, but if you can get it into excel i'm sure i could port it.

mplungian: "x=.........z............../180" yes, exactly.  At present i've got no way of finding X other than trial and error.

cezarF: that's pretty much how i've been calculating X already using trial and error in excel.

I calculated some sample values using the formula above hoping to clarify things further:

if z = 200 then x = 18.1
if z = 400 then x = 9.55
if z = 600 then x = 6.7
if z = 800 then x = 5.275
0

Author Comment

ID: 20091663
felix: that's a very useful little tool, which i assume uses trial and error to brute forces itself a result.  I'm sure i could write some javascript to do the same stopping at a certain number of decimal places.

However logic says to me that if i have a formula i can work backward from, then it must be possible to re-arrange the formula so i can work forwards to get X from just Z.

ps. z is always an integer and can be between 1 and 2000.
0

LVL 14

Assisted Solution

cezarF earned 160 total points
ID: 20091830
@jondanger: did a minor enhancement to my previous post. now its working however, you need a browser that supports "toFixed".  if not, implement a prototype like..

if (!Number.toFixed) {
Number.prototype.toFixed=function(x) {
var temp=this;
temp=Math.round(temp*Math.pow(10,x))/Math.pow(10,x);
return temp;
};
}

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<title>Untitled</title>
<script>
function getX(z){
var n = 0.0
for(y=1.0; y<100.0; y+=0.001){
x = y.toFixed(3);
n = (((x-1)/x)/((1/z)*((x-1)/x)*(x*(19/(x*(x-1))))))
n.toFixed(3)
window.status = 'x = ' + x + '; n = ' + n
if(180 == n){
return 'x = ' + x;
break;
}
}
}
</script>
<body>
<form>
Value for Z:<input type="text" name="z"/>
</form>
</body>
</html>
0

LVL 9

Accepted Solution

felixdsouza earned 1360 total points
ID: 20091838
Hi Jon,

Just use the formula :

z = 3420 /  ( x - 1 )
or
z = (19 * 180) / ( x - 1 )
0

LVL 16

Assisted Solution

gnoon earned 320 total points
ID: 20091895
180 = (((x-1)/x)/((1/z)*((x-1)/x)*(x*(19/(x*(x-1))))))

equals to

x = (3420/z) + 1
0

LVL 16

Expert Comment

ID: 20091898
oops! didn't refresh
0

LVL 75

Assisted Solution

Michel Plungjan earned 160 total points
ID: 20091932

x = (3420/z) + 1

seems a better version, if correct no?
function getVal(z) {
return (3420/z) + 1;
}

(no points to me)
0

Author Comment

ID: 20091960
that's brilliant felix! thank you very much!

i've got 8 sheets of paper covered in algebra trying to simplify it, i think i was getting there :)

now all i need is the X on the left on it's own and i can get it into javascript!

0

Author Comment

ID: 20091983
"gnoon: oops! didn't refresh" whoops! did the same.

This is absolutely brilliant, thanks guys.

Is Everyone ok with the following split?
Felix (340) Accepted
gnoon (80)
mplungjan:(40)
cezarF (40)
0

LVL 9

Expert Comment

ID: 20091996
Sorry, I inadvertently left Z on the left of the equation.

Others have provided you with the correct formula for you to use:

x = (3420 / z) + 1
0

LVL 16

Expert Comment

ID: 20092036
jondanger, let's you design. I would happy.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Aerodynamic noise is the cause of the majority of the noise produced by helicopters. The inordinate amount of noise helicopters produce is a major problem in the both a military and civilian setting. To remedy this problem the use of an aerogel coatâ€¦
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, tâ€¦
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
###### Suggested Courses
Course of the Month17 days, 14 hours left to enroll