Page 1 of 1
im retarded in math
Posted: Sun Apr 01, 2012 2:55 am
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

or another way of doing this equasion with out doing any kind of square root at all
Re: im retarded in math
Posted: Sun Apr 01, 2012 3:50 am
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?
Re: im retarded in math
Posted: Sun Apr 01, 2012 5:57 am
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
Re: im retarded in math
Posted: Sun Apr 01, 2012 9:36 am
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?
Re: im retarded in math
Posted: Sun Apr 01, 2012 10:52 am
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
Re: im retarded in math
Posted: Sun Apr 01, 2012 10:55 am
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:
Cheers,
Jonny
Re: im retarded in math
Posted: Sun Apr 01, 2012 12:24 pm
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
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
Re: im retarded in math
Posted: Sun Apr 01, 2012 1:13 pm
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

thanks for the quick replies, it gives me something to think about