jaenster Posted July 22, 2007 Author Share Posted July 22, 2007 Don't forget the first line of a square root script is always.If $number < 0 Then ConsoleWrite("Can't square root a negative number")else ConsoleWrite(($number ^ .5) & @CRLF)endifThe last consolewrite i dont understand. -jaenster Link to comment Share on other sites More sharing options...
1905russell Posted July 22, 2007 Share Posted July 22, 2007 The last consolewrite i dont understand.Which part?$number^.5same as ^(1/2)Square root = (multiply the number with itself two times) = 2/1Raised to the power (^), always the inverse of the root = 1/21/2 = .5$number^.5 = square root of number. Prove it with logs.Cubed root = $x*$x*$x = (multiply the number with itself three times) = 3/1 = ^1/3 = cube root calculation Link to comment Share on other sites More sharing options...
jaenster Posted July 22, 2007 Author Share Posted July 22, 2007 Which part?$number^.5same as ^(1/2)Square root = (multiply the number with itself two times) = 2/1Raised to the power (^), always the inverse of the root = 1/21/2 = .5$number^.5 = square root of number. Prove it with logs.Cubed root = $x*$x*$x = (multiply the number with itself three times) = 3/1 = ^1/3 = cube root calculationah.. y i see ^^ -jaenster Link to comment Share on other sites More sharing options...
martin Posted July 22, 2007 Share Posted July 22, 2007 Cubed root = $x*$x*$x = (multiply the number with itself three times) = 3/1 = ^1/3 = cube root calculationThat's nonsense the way you've written it. I think that what you you were trying to put across was that if $x is the cubed root of $y then$x*$x*$x = $yie$x^3 = $ytherefore($x^3)^(1/3) = $y^(1/3)but since ($x ^n)^p = $x ^(n*p), then ($x^3)^(1/3) = $x^1 = $x3/1 = three and nothing else^1/3 is not a cube root calculationA cube root is $x^(1/3)$x^1/3 = $x/3 which is only the same as $x^(1/3) when $x = 27^0.5 Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
1905russell Posted July 22, 2007 Share Posted July 22, 2007 That's nonsense the way you've written it. I think that what you you were trying to put across was that if $x is the cubed root of $y then$x*$x*$x = $yie$x^3 = $ytherefore($x^3)^(1/3) = $y^(1/3)but since ($x ^n)^p = $x ^(n*p), then ($x^3)^(1/3) = $x^1 = $x3/1 = three and nothing else^1/3 is not a cube root calculationA cube root is $x^(1/3)$x^1/3 = $x/3 which is only the same as $x^(1/3) when $x = 27^0.5I wrote it the way I thought jaenster would understand it and it seems it was understood.You are wrong saying $x^1/3 = $x/3 (this is truly nonsense) To cube root a number you ^1/3 or ^(1/3) its the same thing. To square root a number you ^1/2 or ^(1/2) its the same thing.It was understood - yours is nonsense not mine. Link to comment Share on other sites More sharing options...
martin Posted July 22, 2007 Share Posted July 22, 2007 I wrote it the way I thought jaenster would understand it and it seems it was understood.You are wrong saying $x^1/3 = $x/3 (this is truly nonsense) To cube root a number you ^1/3 or ^(1/3) its the same thing. To square root a number you ^1/2 or ^(1/2) its the same thing.It was understood - yours is nonsense not mine.OK, then I didn't understand, but you should check what you are saying and I know you haven't.You think that $x^1/3 = $x/3 is nonsense, but you haven't tried it have you?^ has higher precedence than / so when the string is parsed the value calculated after ^ will end as soon as an operator of lower precedence is met.If you try 27^1/3 you will get 9If you try 27^(1/3) you will get 3Try thisMsgBox(0,'root 16 is',16^1/2)Have you tried it?Who is talking nonsense?But what I said was nonsense was thisCubed root = $x*$x*$x = (multiply the number with itself three times) = 3/1 = ^1/3 = cube root calculationI think you have a hard job in front of you persuading me that isn't nonsense. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
jvanegmond Posted July 22, 2007 Share Posted July 22, 2007 (edited) ; This will calculate the square root of any number.. $Number = 12345 MsgBox(0, "Babylonian Square Root", SqrtBabylonian($Number) ) MsgBox(0, "Bakhshali Square Root", SqrtBakhshali($Number) ) Func SqrtBabylonian($S) Dim $X = 3^StringLen($S) While 1 $newX = 0.5 * ($x + ($S/$x) ) If $newX = $X Then ExitLoop Else $X = $newX EndIf WEnd Return $X EndFunc Func SqrtBakhshali($S) Dim $N = 0 While 1 $N += 1 If $S - ($N^2) < 1 Then ;bad practice.. but it works ExitLoop EndIf WEnd $d = $S - $N^2 $P = $d / (2*$N) $A = $N + $P Return $A - ( ($P^2) / ( 2*$A) ) EndFuncJust playing.Edit: Full time to make: 12 minutes.By the way, I'll post Taylor Series for those interested later.. Edited July 23, 2007 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
1905russell Posted July 23, 2007 Share Posted July 23, 2007 (edited) OK, then I didn't understand, but you should check what you are saying and I know you haven't.You think that $x^1/3 = $x/3 is nonsense, but you haven't tried it have you?^ has higher precedence than / so when the string is parsed the value calculated after ^ will end as soon as an operator of lower precedence is met.If you try 27^1/3 you will get 9If you try 27^(1/3) you will get 3Try thisMsgBox(0,'root 16 is',16^1/2)Have you tried it?Who is talking nonsense?But what I said was nonsense was thisI think you have a hard job in front of you persuading me that isn't nonsense.Okay I checked ^(1/3) and ^1/3 and you are right I know () has precedent over ^ (Bedmas) and I see written this way (not raised) makes a difference. ExplainationCubed root = $x*$x*$x = (multiply the number with itself three times) = 3/1 = ^1/3 = cube root calculationThis meant if the root is a number timesing itself 3 times (ie $x*$x*$x) then take 3 = 3/1 and inverse it = 1/3 and use ^(1/3) to calculate cube root. Edited July 23, 2007 by 1905russell Link to comment Share on other sites More sharing options...
1905russell Posted July 23, 2007 Share Posted July 23, 2007 (edited) ; This will calculate the square root of any number.. $Number = 12345 MsgBox(0, "Babylonian Square Root", SqrtBabylonian($Number) ) MsgBox(0, "Bakhshali Square Root", SqrtBakhshali($Number) ) Func SqrtBabylonian($S) Dim $X = 3^StringLen($S) While 1 $newX = 0.5 * ($x + ($S/$x) ) If $newX = $X Then ExitLoop Else $X = $newX EndIf WEnd Return $X EndFunc Func SqrtBakhshali($S) Dim $N = 0 While 1 $N += 1 If $S - ($N^2) < 1 Then ;bad practice.. but it works ExitLoop EndIf WEnd $d = $S - $N^2 $P = $d / (2*$N) $A = $N + $P Return $A - ( ($P^2) / ( 2*$A) ) EndFunc Just playing. Edit: Full time to make: 12 minutes. By the way, I'll post Taylor Series for those interested later.. Incredible what you did, but why would you do it these ways when simple $Number^(1/2) does the same thing? It's okay I know the answer. Edited July 23, 2007 by 1905russell Link to comment Share on other sites More sharing options...
lokster Posted July 23, 2007 Share Posted July 23, 2007 @1905russell, I think the simple answer to your question is "because some people like to ask the question 'WHY'". WHY 3^2=9? WHY Sqrt(9)=3? Without the "WHY" the life is meaningless... Link to comment Share on other sites More sharing options...
jvanegmond Posted July 23, 2007 Share Posted July 23, 2007 Incredible what you did, but why would you do it these ways when simple $Number^(1/2) does the same thing?It's okay I know the answer.Thanks for that. I'm still going to give you an answer why.$Number^(1/2) is exactly the same as Sqrt($Number). Even in mathematics that is another way of writing. The functions I show you are a way of using multiplication and addition to calculate a root. A root could not be calculated the way jaenster wrote it, as it would be too time consuming to calculate the root of a really big number, like 8124746273, and it also does not calculates roots that are more accurate then integers.@lokster, "why 3^2 = 9"? Because it is an easier form when you have to write 5*5*5*5*5, you just use 5^5."Why 9^0.5 = 3"? follows out of notation used here before. This is just convenient when using higher functions. github.com/jvanegmond Link to comment Share on other sites More sharing options...
martin Posted July 23, 2007 Share Posted July 23, 2007 Thanks for that. I'm still going to give you an answer why.$Number^(1/2) is exactly the same as Sqrt($Number). Even in mathematics that is another way of writing. The functions I show you are a way of using multiplication and addition to calculate a root. A root could not be calculated the way jaenster wrote it, as it would be too time consuming to calculate the root of a really big number, like 8124746273, and it also does not calculates roots that are more accurate then integers.@lokster, "why 3^2 = 9"? Because it is an easier form when you have to write 5*5*5*5*5, you just use 5^5."Why 9^0.5 = 3"? follows out of notation used here before. This is just convenient when using higher functions.The Babylonian one is best, and most accurate and fast. The other one isn't even as good as my method. Tell us about the Taylor series.I don't think lokster meant what you thought, I think he knows about ^ etc, he was just saying (I think) it's good to ask why. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
jaenster Posted July 23, 2007 Author Share Posted July 23, 2007 Can somebody explain how you get the power of .5? How to calulate it? -jaenster Link to comment Share on other sites More sharing options...
tmo Posted July 23, 2007 Share Posted July 23, 2007 Can somebody explain how you get the power of .5? How to calulate it? if the result is a rational number, you just somehow know it due to experience. if the result is a irrational number, you can use an iterational method like Newton: f(x) = x^2 - a = 0 <-- the solution is a^0.5 f'(x) = 2x now u can use the following iteration: Link to comment Share on other sites More sharing options...
jvanegmond Posted July 23, 2007 Share Posted July 23, 2007 Can somebody explain how you get the power of .5? How to calulate it?I don't understand.To the power of .5 is the same as square root. It is just a different notation.Why would you first provide the answer, and then ask the question? github.com/jvanegmond Link to comment Share on other sites More sharing options...
jaenster Posted July 23, 2007 Author Share Posted July 23, 2007 I don't understand.To the power of .5 is the same as square root. It is just a different notation.Why would you first provide the answer, and then ask the question?oh ok now understand, So ^ (1/3) is the cube root ? -jaenster Link to comment Share on other sites More sharing options...
RazerM Posted July 23, 2007 Share Posted July 23, 2007 Yes, x^(a/B) = b root(x^a) My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop. Link to comment Share on other sites More sharing options...
martin Posted July 23, 2007 Share Posted July 23, 2007 @Manadar Can you tell me what the Taylor series is? Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
jaenster Posted July 24, 2007 Author Share Posted July 24, 2007 But the topic, Do somebody like my function? -jaenster Link to comment Share on other sites More sharing options...
jvanegmond Posted July 24, 2007 Share Posted July 24, 2007 (edited) @ManadarCan you tell me what the Taylor series is?Wikipedia says this about the Taylor series:The Taylor series is a representation of a function as an infinite sum of terms calculated from the values of its derivatives at a single point.What it comes down to is, that the formula for the square root is:Or simpler said: Edited July 24, 2007 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now