tags:

views:

100

answers:

1

In Excel I have:

=(((SQRT(40))($E$8/C16))^2)1.1

Which is like:

(((SQRT(40)) * (7.695 / 0.200) ) ^2) *1.1;

I can't get it working in Javascript!

I have:

answer = (Math.exp(((Math.sqrt(40)) * (7.695 / 0.200))) *1.1);

I am getting something like: 5.265317066795887e+105

When I expect to get something like: 65168

Can anyone help see my error?

+12  A: 

Math.exp(x) is not x^2 but according to the docs e^x. You want to use Math.pow(x,y) (doc) which means x^y instead. Use this expression:

answer = Math.pow(Math.sqrt(40) * (7.695 / 0.200), 2)*1.1;
theomega
The multiplication by `1.1` should be outside of `Math.pow`.
Lukáš Lalinský
You're right, thanks for the hint, fixed this
theomega
+1, although this might run faster? `answer = Math.sqrt(40) * 7.695 / 0.200; answer = 1.1 * answer * answer;`
MarkJ
I know old topic, but I accidentially got here, and realized that you were doing `sqrt(40) ^ 2`.. So a lot faster would be `answer = 44 * Math.pow( 7.695 / 0.200, 2 );`.
poke