Jump to content

Something like the SQRT function


jaenster
 Share

Recommended Posts

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)

endif

The last consolewrite i dont understand.

-jaenster

Link to comment
Share on other sites

  • Replies 41
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

The last consolewrite i dont understand.

Which part?

$number^.5

same as ^(1/2)

Square root = (multiply the number with itself two times) = 2/1

Raised to the power (^), always the inverse of the root = 1/2

1/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

Which part?

$number^.5

same as ^(1/2)

Square root = (multiply the number with itself two times) = 2/1

Raised to the power (^), always the inverse of the root = 1/2

1/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

ah.. y i see ^^

-jaenster

Link to comment
Share on other sites

Cubed root = $x*$x*$x = (multiply the number with itself three times) = 3/1 = ^1/3 = cube root calculation

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 = $y

ie

$x^3 = $y

therefore

($x^3)^(1/3) = $y^(1/3)

but since ($x ^n)^p = $x ^(n*p), then ($x^3)^(1/3) = $x^1 = $x

3/1 = three and nothing else

^1/3 is not a cube root calculation

A 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

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 = $y

ie

$x^3 = $y

therefore

($x^3)^(1/3) = $y^(1/3)

but since ($x ^n)^p = $x ^(n*p), then ($x^3)^(1/3) = $x^1 = $x

3/1 = three and nothing else

^1/3 is not a cube root calculation

A 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

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.

Link to comment
Share on other sites

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 9

If you try 27^(1/3) you will get 3

Try this

MsgBox(0,'root 16 is',16^1/2)

Have you tried it?

Who is talking nonsense?

But what I said was nonsense was this

Cubed root = $x*$x*$x = (multiply the number with itself three times) = 3/1 = ^1/3 = cube root calculation

I 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

; 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..

Edited by Manadar
Link to comment
Share on other sites

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 9

If you try 27^(1/3) you will get 3

Try this

MsgBox(0,'root 16 is',16^1/2)

Have you tried it?

Who is talking nonsense?

But what I said was nonsense was this

I 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.

Explaination

Cubed root = $x*$x*$x = (multiply the number with itself three times) = 3/1 = ^1/3 = cube root calculation

This 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 by 1905russell
Link to comment
Share on other sites

; 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 by 1905russell
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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:

post-19097-1185186934_thumb.png

Link to comment
Share on other sites

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

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

@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

@Manadar

Can 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:

Posted Image

Or simpler said:

Posted Image

Edited by Manadar
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...