|
| 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
|
  |
| Joined: 29 Mar 2011 |
| Total Posts: 32902 |
|
|
| 06 Jun 2014 03:43 PM |
| what is wrong with math.sqrt |
|
|
| Report Abuse |
|
|
|
| 06 Jun 2014 03:47 PM |
| Nothing, it is mine that won't work |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 06 Jun 2014 03:49 PM |
| I don't get how you're trying to calculate a square root with this. |
|
|
| Report Abuse |
|
|
Trioxide
|
  |
| Joined: 29 Mar 2011 |
| Total Posts: 32902 |
|
| |
|
|
| 06 Jun 2014 03:50 PM |
| Adding more loops won't work.He'Ll probably just get the same result. |
|
|
| Report Abuse |
|
|
|
| 06 Jun 2014 03:50 PM |
| I'll try for I = 1,100 do brb |
|
|
| Report Abuse |
|
|
|
| 06 Jun 2014 03:50 PM |
| if there's nothing wrong with math.sqrt, why not just use that. |
|
|
| Report Abuse |
|
|
L0cky2013
|
  |
| Joined: 30 Jul 2012 |
| Total Posts: 1446 |
|
| |
|
| |
|
| |
|
|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 06 Jun 2014 03:55 PM |
nothing can deal with square root of negative numbers?
|
|
|
| Report Abuse |
|
|
|
| 06 Jun 2014 03:55 PM |
@ver
No looping 100 instead of 10
math.sqrt works |
|
|
| Report Abuse |
|
|
|
| 06 Jun 2014 03:56 PM |
| Did you read my post?It easily shows how your square root calculation does not work. |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| Joined: 30 Jul 2012 |
| Total Posts: 1446 |
|
| |
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| Joined: 29 Mar 2011 |
| Total Posts: 32902 |
|
| |
|
|
| 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 |
|
|