answer to formula = NaN?

Get help using Construct 2

Post » Fri Jan 10, 2014 10:53 am

Either I'm asking way too much of Construct2, or I'm just really bad at translating formulas.

So what I'm trying to do is get these formulas into C2:



But when I insert the values for q and z through variables the formula returns NaN (not a number), which is strange because the formula as I've put into C2 should consist only of numbers. Even when I manually change all z's and q's to numbers the outcome stays NaN.

So I might just have put in the formulas the wrong way, or I'm pushing C2 beyond it's limits.

Here are the formulas as I've entered them in C2:

formula for a:
abs((-6*z+((6*q*z)/(q-100)-sqrt((16*((q^2)*(z^2)-((100*q*z)^2)-((7500*z)^2))))))/2/(-6+((8*q)/(q-100))-(((6*q)^2)/((q-100)^2))))

formula for b:
abs(-(-6*z+((6*q*z)/(q-100)-sqrt((16*((q^2)*(z^2)-((100*q*z)^2)-((7500*z)^2))))))/2/(-6+((8*q)/(q-100))-(((6*q)^2)/((q-100)^2)))*q/(q-100))

any advise would be appreciated.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Jan 10, 2014 11:21 am

NaN is the correct answer if you do something like divide by zero, which would happen if q is 100.
Scirra Founder
B
395
S
231
G
88
Posts: 24,367
Reputation: 193,684

Post » Fri Jan 10, 2014 11:24 am

I understand that, but:
q is always larger than 50 and smaller than 100
z is always larger than 0
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Jan 10, 2014 11:26 am

could you break it down and see if construct is any happier in smaller chunks

a=-6*z
b=(6*q*z)
c=q-100

etc

and stitch it all back together ?

August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,832

Post » Fri Jan 10, 2014 11:28 am

@RamPackWobble

I guess that's worth a try, I was thinking of that but hoped it wouldn't be necessary, because it means adding a lot of local variables, but well..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Jan 10, 2014 11:33 am

I copied your formula into Excel, and replaced Q and Z with numbers. Although Excel accepts the various functions, it came back with a NAME$ error.
B
17
S
5
Posts: 9
Reputation: 1,222

Post » Fri Jan 10, 2014 11:39 am

removed post as already suggested/done aboveRamPackWobble2014-01-10 11:42:14
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,832

Post » Fri Jan 10, 2014 11:40 am

Yep.. somewhere, somehow, there must have been a translation-error..

bah.. humbug..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Jan 10, 2014 11:49 am

Yeah with a quick look over the main thing you missed was adding a "-" inside the sqrt. Without it you're calculating the sqrt of a negative number which is NAN. I can look over it better tomorrow.

What's the formula calculate?
B
92
S
32
G
106
Posts: 5,272
Reputation: 69,455

Post » Fri Jan 10, 2014 12:06 pm

Rereading the formula I missed a lot, haha..
But it all seems to go wrong with the square root.
Working on it!


The formulas are a bit of pseudo-code to calculate the major axis and minor axis of an ellips from it's perimeter.

z is the perimeter divided by pi and q is a percentage so a+b always add up to 100%LittleStain2014-01-10 12:07:59
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Next

Return to How do I....?

Who is online

Users browsing this forum: plinkie and 16 guests