im retarded in math

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

im retarded in math

Post by brandonb »

i have 16% of 8k words left and was wondering if you guys knew a work around for this equasion--> new pressure/old pressure= then square root it and times that by old flowrate
new pressure = 30
old pressure =20
flowrate =10
30/20=1.5 squared its 1.2247 *10=12.24 flowrate
with decibals in equasions for pic i just multiply number by 100 then use division and mod to get to variables to put together, thats not a problem i was wondering if there is another easy way that i could do a square root other than using the function and be able to use it with ulong numbers varible :arrow: or another way of doing this equasion with out doing any kind of square root at all

DannyBerry
Posts: 29
Joined: Tue Aug 30, 2011 9:20 pm
Has thanked: 11 times
Been thanked: 1 time
Contact:

Re: im retarded in math

Post by DannyBerry »

Brandon,
To clarify what your saying in the math formula: the old flowrate divided by the new flowrate gives a ratio number. 30/20=1.5 , Then you take the squareroot of that number: squareroot of 1.5=1.2247. Then you multiply 1.2247 x 100=12.24. In affect what your saying is that there was a 22.47% increase in flowrate due to the pressure increase from 20 to 30 psi.

I'm not sure what to tell you about the squareroot in flowcode....but remember working backwards: that a number squared or another way of saying it is: a number multiplyed by itself gives the larger number you are getting the sqaureroot of: example 10 squared =100, and 5 squared 25. So......Square roots are 10 and 5 respectively. See what I mean?

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: im retarded in math

Post by brandonb »

yes but if you divide a number by its self you always get one not the square root, then if multiplying the number 100 times the answer is the same with the square root, i can do it in my head but the micro is a different story because i dont have enough memory for floating numbers or the root function

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Re: im retarded in math

Post by JohnCrow »

Hi
Square roots can be calculated by successive approximations using this formula.



SR = 1/2((x/y)+y)

SR = Square Root
x= the number whose root is requires
y = your first guess at the root.

calculate as above then use the value returned as SR to replace y and calculate again

keep doing this until you get 2 successive answers almost equal.

Trouble is this will need to use floats and a lot of memory.
Don't know any other way apart then a square root is the same as raising to the power (1/2).

Could you do it using a lookup table?
1 in 10 people understand binary, the other one doesn't !

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: im retarded in math

Post by brandonb »

thanks for looking into this john, i thought of that also but the formula would be in accurate, reason of posting was i figured i may have overlooked something easy since math is something i havent played with in great detail, i just filled the memory of the chip with another feature so all is well

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 63 times
Been thanked: 290 times
Contact:

Re: im retarded in math

Post by JonnyW »

Hi. First, by the way, best subject title ever.

Depending on your scales and required accuracy you can use Johns method but avoid using floating point by using fixed point:

Code: Select all

  x = some integer value stored in a signed long
  x = x << 8     // Convert value to 8-bit fixed point
  y = x >> 2     // Guess square root as 1/4 X
  ylast = x      // Previous Y, uninitialised
  while ((y - ylast) < 1 || (ylast - y) < 1)
    ylast = y
    y = ((x << 7) / y) + (y >> 1)
Here is a demo showing both fixed and floating point, hope it is of use:
sqrt.fcf
(15 KiB) Downloaded 311 times
Cheers,

Jonny

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: im retarded in math

Post by medelec35 »

Hi Brandon,

Not a maths person myself either, I have gone with the most simple of approach!

Basically, Count starts off at 1.
Loop
Is Count * Count > number to be squared?
If no then add 1 to count: go to Loop
If yes then result = Count -1: End
Square roots without Float.fcf
(12.5 KiB) Downloaded 317 times
Although only whole numbers are derived, no floats are used so keeps program small.
For the range of square roots, best to stick with numbers less than 23767

There has also been discussion on square roots here:
http://www.matrixmultimedia.com/mmforum ... =29&t=8508

Martin
Attachments
Sqrt no float.png
(99.45 KiB) Downloaded 3814 times
Martin

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: im retarded in math

Post by brandonb »

very interesting, i'll play around with this concept, but i think im gonna have to use floating numbers to get the accuracy that im looking for since the other side of the decimbal is import on this equasion, on that version i'll use a 18f2685 which shouldnt be effected by a measely 8kb for one calculation :D :D thanks for the quick replies, it gives me something to think about

Post Reply