Trying to solve equation in xojo code

Hope I posted in the correct place :smiley:

I have an algebra equation that is used at work and while I can sit down and figure out the result I’m just having a hard time getting my brain to transfer it to xojo code.

The equation is basically Q*R * sqrt(P+14.7 /14.7) * sqrt(530 /T + 460)
(sorry not sure how to enter all the correct symbols to make it easier to read)

So with the numbers I have it would be .17 * 36.02 * sqrt(87 + 14.7 / 14.7) * sqrt(530 / 69 + 460)

I had this in xojo code: qd101_corr_flow_150 = (6.1234 * sqrt(fqd101_pressure_150value * 1 + 14.7 / 14.7) * sqrt(530 / (fqd101_temp_150value * 1) + 460)) but obviously it is not correct

How do you solve sqrt( 87 + 14.7 / 14.7 )?
1.- sqrt ( 101.7 / 14.7 )
2.- sqrt ( 87 + 1 )

If 1, maybe your code should be:

 Q * R * sqrt( (P+14.7) / 14.7) * sqrt( 530 / T + 460 ) 

Note: Dave’s answer is more complete. We think you have missing ( )

dim q as double =0.17
dim r as double =36.02
dim p as double = 87
dim t as double = 69
dim answer as double
answer=Q*R*sqrt(p+14.7/14.7)*sqrt(530/t+460)
  • replace q, r, p and t with other variable names if you wish

I think your issue may have to do with precedence … that is when there are no () , which gets calcuated first

sqrt(p+14.7/14.7) might need to be sqrt((p+14.7)/14.7) otherwise it ends up (p+1)

Thanks for the replies everyone :smiley:

When I do the equation in a calculator I get 16.1057 but in Xojo I’m getting 1242.25 :confused: (not saying it’s Xojo as I know it is me)

When I run the equation in my Calc I get 16.1057 but in Xojo using the code:

dim q as double =0.17 dim r as double =36.02 dim p as double = 87 dim t as double = 69 dim answer as double answer=Q*R*sqrt(p+14.7/14.7)*sqrt(530/t+460)

I get 1242.25 and I did try changing sqrt(p+14.7/14.7) might need to be sqrt((p+14.7)/14.7) but it was off also

Maybe I’m tired :stuck_out_tongue:

Well someone is making a mistake then.

answer=Q*R*sqrt((p+14.7)/14.7)*sqrt(530/(t+460))

gives me 16.12147
which while closer to your 16.1057 than 1242 is, it is still not the “same” answer
but it it the only combination that even comes close…

Dave…

I’m sure it is me making a mistake and thank you for letting me know your result

Appreciate the help and I will take a break and come back to it after some fresh air

[quote=373788:@brian franco]Dave…

I’m sure it is me making a mistake and thank you for letting me know your result

Appreciate the help and I will take a break and come back to it after some fresh air[/quote]
are you SURE of your answer of 16.1057? because I can find NO combination of that equation that renders that.

Dave,

Just triple checked everything and you are right…the answer is 16.12147 ( I messed up when calculating)

Just tried Xojo code again and found my () mistake and whola… 16.12147 !! :smiley:

Thanks Dave the help is much appreciated