generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: sqrt calculation failing..?

Previous Thread :: Next Thread 
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
06 Jun 2014 03:38 PM
--[[test stuff]]

function sqrt(N)
local HW = 0
Estimate = 1
for i = 1,10 do
HW = N / Estimate
Estimate = N + HW / 2
end
return Estimate
end

print(sqrt(20))
print(math.sqrt(20))

--Why does it not print the same result -_-
Report Abuse
Trioxide is not online. Trioxide
Joined: 29 Mar 2011
Total Posts: 32902
06 Jun 2014 03:43 PM
what is wrong with math.sqrt
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
06 Jun 2014 03:47 PM
Nothing, it is mine that won't work
Report Abuse
Trioxide is not online. Trioxide
Joined: 29 Mar 2011
Total Posts: 32902
06 Jun 2014 03:48 PM
that looks like you're trying to 'bruteforce' yourself an answer. add more loops
Report Abuse
sonicdiablo is not online. sonicdiablo
Joined: 05 Feb 2009
Total Posts: 1661
06 Jun 2014 03:49 PM
I don't get how you're trying to calculate a square root with this.
Report Abuse
Trioxide is not online. Trioxide
Joined: 29 Mar 2011
Total Posts: 32902
06 Jun 2014 03:49 PM
im with sonic
Report Abuse
sonicdiablo is not online. sonicdiablo
Joined: 05 Feb 2009
Total Posts: 1661
06 Jun 2014 03:50 PM
Adding more loops won't work.He'Ll probably just get the same result.
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
06 Jun 2014 03:50 PM
I'll try for I = 1,100 do brb
Report Abuse
VerifiedName is not online. VerifiedName
Joined: 26 Jul 2009
Total Posts: 4534
06 Jun 2014 03:50 PM
if there's nothing wrong with math.sqrt, why not just use that.
Report Abuse
L0cky2013 is not online. L0cky2013
Joined: 30 Jul 2012
Total Posts: 1446
06 Jun 2014 03:51 PM
return math.sqrt(N)
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
06 Jun 2014 03:52 PM
It's not working..
Report Abuse
VerifiedName is not online. VerifiedName
Joined: 26 Jul 2009
Total Posts: 4534
06 Jun 2014 03:52 PM
math.sqrt?

Report Abuse
sonicdiablo is not online. sonicdiablo
Joined: 05 Feb 2009
Total Posts: 1661
06 Jun 2014 03:53 PM
If my input is 15, here's what his loop will do

15
22.5
0.66666666666667
15.333333333333
15
22.5
0.66666666666667
15.333333333333
0.97826086956522
15.489130434783
0.96842105263158
15.484210526316
0.96872875594833
15.484364377974
0.96871913072111
15.484359565361
0.96871943180368
15.484359715902
0.96871942238565
15.484359711193
0.96871942268025
15.48435971134
Report Abuse
L0cky2013 is not online. L0cky2013
Joined: 30 Jul 2012
Total Posts: 1446
06 Jun 2014 03:53 PM
um

>function sqrt(N) return math.sqrt(N) end print(sqrt(4))
>2
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
06 Jun 2014 03:54 PM
@ver


I'm going to make a new one that can deal with sqrt(-N)


Yes that is possible.

Apparently math.sqrt can't deal with negative numbers in Rblx.Lua OR standard Lua
Report Abuse
VerifiedName is not online. VerifiedName
Joined: 26 Jul 2009
Total Posts: 4534
06 Jun 2014 03:55 PM
nothing can deal with square root of negative numbers?



Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
06 Jun 2014 03:55 PM
@ver

No looping 100 instead of 10

math.sqrt works
Report Abuse
sonicdiablo is not online. sonicdiablo
Joined: 05 Feb 2009
Total Posts: 1661
06 Jun 2014 03:56 PM
Did you read my post?It easily shows how your square root calculation does not work.
Report Abuse
VerifiedName is not online. VerifiedName
Joined: 26 Jul 2009
Total Posts: 4534
06 Jun 2014 03:59 PM
yeah war, stop wasting you time.
you cant find the square root of negative numbers, think about it .-.

Report Abuse
L0cky2013 is not online. L0cky2013
Joined: 30 Jul 2012
Total Posts: 1446
06 Jun 2014 04:04 PM
yep
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
06 Jun 2014 04:05 PM
Ver I understand your thinking.

Since the square root of N has to equal N when multiplied by itself, it is always gonna result positive, since two positives equal positive and two negatives equal positive. So

NSqrt = X^2

No number can substitute X and equal a negative, right?


But yes it IS possible, and I'm not getting into an advanced math argument on this. Just go research it :P
Report Abuse
JoshuaKempfert is not online. JoshuaKempfert
Joined: 16 Feb 2013
Total Posts: 2407
06 Jun 2014 04:05 PM
--pfft its easy to calculate square root
function s(...)
local Numbers = {...}
print(table.concat(Numbers, ","))
local SquareRoots = {}
for i,v in pairs(Numbers) do
if v > 0 then
table.insert(SquareRoots, v^.5)
else
table.insert(SquareRoots, nil)
end
end
return unpack(SquareRoots)
end

print(s(25, 64, 144))
Report Abuse
VerifiedName is not online. VerifiedName
Joined: 26 Jul 2009
Total Posts: 4534
06 Jun 2014 04:07 PM
yes i know, stuff to do with imaginary numbers and stuff.
but please, let's actually go into this advanced math argument, i want to hear how you plan on doing this.

Report Abuse
Trioxide is not online. Trioxide
Joined: 29 Mar 2011
Total Posts: 32902
06 Jun 2014 04:09 PM
verifiedname +1
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
06 Jun 2014 04:09 PM
I'm trying to use the Babylonian Method



Guess Divide Find average
10 20/10 = 2 average 10 and 2 to give new guess of 6
6 20/6 = 3.333 average 3.333 and 6 gives 4.6666
4.666 20/4.666= 4.1414 average 4.666,4.1414= 4.4048
4.4048 20/4.4048=4.5454 average = 4.4700
4.4700 20/4.4700=4.4742 average = 4.4721
4.4721 20/4.4721=4.47217 average = 4.47214
This is already to 4 decimal places
4.47214 20/4.47214=4.472132 average =4.472135
4.472135 20/4.472135=4.472137 average = 4.472136




--From a commenter on some math site
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image