Jump to content

How great is the interest in some extra Math UDF's?


JSThePatriot
 Share

Math UDF's  

77 members have voted

  1. 1. Need additional Math UDF's?

    • Yes
      55
    • No
      4
    • Maybe
      14
    • I dont care
      4


Recommended Posts

Oh my God i can't belive i didnt notice this topic before! It is really cool. I will definiatly use all this stuff to cheat in math. :);) HAHa Lol. I was wondering if AutoIt can solve multistep equations Like

3x-23+25=4x-45+54x

And it would solve for the Variable

It would be really cool if it works

Thank you

code
Link to comment
Share on other sites

  • Replies 52
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

If $a = 0 then in the quadratic formula:

-b +- sqrt( (b^2) - (4*a*c))

2a

Then when you divide by 2a, are you not dividing by zero? thus undefined?

No, that is just blindly applying a formula when the formula doesn't apply. :)

If a = 0 then you have

0*x^2 + b*x +c = 0

therefore

b*x + c = 0

so, if b is not zero then

x = -c/b

which is what my modified version of your function returns.

You can argue that if a is zero then you haven't got a quadratic, which is true, it's just that if a is zero then anyone could work the answer out and to have a clever function say it hadn't got a clue what to do is a shame.

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

oh lol, I made mine in PHP when I was struggling to figure out some values

- I seriously have never seen anybody else mention it, was starting to wonder if anybody else knew about it.

Edit: I was trying to quote a reply to my post but the quote got garbled with data - eh.

Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Link to comment
Share on other sites

Do you know what would be really great? I mathematical expression parser, like this: _ParseExpression("58*Sin(90)")

Have been trying to make one myself several times but it just is to complex for me :)

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Probably the same thing as the quadratic functions listed but I made it looking at the equation a slightly different way.

If it looks the same or doesnt work any faster, that's okay - I just wanted to try to make one.

For Factoring or solving Trinomials where

ax^2 + bx +c =q

and a,b and c are defined

EDIT: Fixed operations when ($a=0 and $b=0) and when ($a=0 and $b=0 and $c!=$q)

Func _ComSqr($a=0,$b=0,$c=0,$q=0,$solve_for='x')

    ;$solve_for
    ;x    =  solve for x
    ;0    = solve for 0 (aka factor)
    ;      ^^^NOTICE: this MIGHT NOT produce integers
    ;ans = returns whether you have 0,1 or 2 answers, etc.

    ;    No Solution Returns ''
    ;    Infinite returns 'inf'
    
    Local $qq='',$result='',$sol1='',$sol2='', $ans=0,$z=0, $xinf=false
    If $a=0 Then
        ;bx+c=q  or  c=q
        $q-=$c
        If $b=0 Then
            $xinf=true ; 0x+c=0  X is infinite but you can still solve for 0 (0=0)
            If $q<>0 Then return '';  if  c=q then q-c=0
        Else
            If $b<>0 Then $q/=$b
        EndIf
        
    Else
        ;ax^2+bx+c=q
        $q-=$c
        $q/=$a
        $b/=$a
        $z=$b/2
        $q+=$z^2
        $c=$z
        If $q<0 then return $result
        
        $q=Sqrt($q)
        $qq=(-1*$q)-$c
        $q-=$c
    EndIf
    Switch $solve_for
        Case 'ans'
            If $xinf Then Return 'inf'
            If StringLen($q )>0 Then $ans+=1
            If StringLen($qq)>0 Then $ans+=1
            $result=$ans
        Case 'x'
            If $xinf Then Return 'inf'
            $result=$q&','&$qq
            If $q=$qq Then $result=$q
            If $q=='' Or $qq=='' Then $result=$q&$qq
        Case '0'
            If $xinf Then Return $q ; q, which is 0 :D
            $sol1='(x+'&(-1*$q)&')'
            $sol2='(x+'&(-1*$qq)&')'
            If $q=='' Then $sol1=''
            If $qq=='' Then $sol2=''
            $result=$sol1&$sol2
            If $sol1==$sol2 and StringLen($result)>0 Then $result=$sol1&'^2'
            $result=StringReplace(StringReplace(StringReplace($result,'+-','-'),'(x+0)','(x)'),'(x-0)','(x)')
    EndSwitch
    Return $result
EndFunc
Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Link to comment
Share on other sites

  • 1 month later...

Need some operations ABOVE exponentiation (really big / really small numbers?)

I wrote the following based upon the Wikipedia article on Iterated Powers of Tetration

_MultExp(2, 4) should solve for: (see image)

Posted Image

and

_IterExp(2, 2, 3) should solve for: (see image)

Posted Image

Func _MultExp($a, $n)
    ;Multilevel exponentiation
    ;- Example:  _MultExp(2, 4)==(2^(2^(2^(2))))
    If $n<0 Then
        $a=1/$a
        $n*=-1
    EndIf
    $b=1
    Select
        Case $n=1
            $b=$a
        Case $n>1
            $b=$a
            $exp=1
            For $i=1 To $n
                $b=$a^$exp
                $exp=$b
            Next
    EndSelect
    Return $b
EndFunc
Func _IterExp($a, $b, $n)
    ;Iterated Exponentiation
    ;- Examples:  _IterExp(1, 2, 3)==((((1)^2)^2)^2)==1^(2^3)
    ;             _IterExp(2, 2, 3)==((((2)^2)^2)^2)==2^(2^3)
    Return $a^($b^($n))
EndFunc

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Link to comment
Share on other sites

Script Function:
    Tests if a number is even or odd.
    Returns 1 - If the number is even.
    Returns 2 - If the number is odd.
#ce ----------------------------------------------------------------------------
Func _IsEven($eVal)
    Local $a = $eVal / 2
    Select
        Case Round($a, 0) = $a
            Return 1
        Case Round($a, 0) <> $a
            Return 0
    EndSelect
EndFunc
It looks to me like it returns 0 if it's odd, and 1 if it's even, not 1 and 2 for even and odd...

and it would be simpler to use:

Func _IsEven($eVal)
  Return Not BitAND($eVal,1)
EndFunc

this returns false (0) if it's odd, and true (1) if it's even, just like yours appears to :)

Also, this will work with decimal numbers; if I'm not mistaken, 5280.3 is considered even (though not whole), but your function would return that it's odd.

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110
Link to comment
Share on other sites

  • 6 months later...

Anyone post something like this yet?

ConsoleWrite( 'Pi = ' & SumPi( 0, 9 ) & @LF ); only 14 decimal places anyway...

Func SumPi( $iMin, $iMax)
    Local $Sum = 0
    For $k = $iMin To $iMax
        $Sum += 1/16^$k * ( 4/(8*$k+1) - 2/(8*$k+4) - 1/(8*$k+5) - 1/(8*$k+6) )
    Next
    Return $Sum
EndFunc

From:

Posted Image

EDIT: it is also said you can use part of it to extract binary/hexadecimal digits from Pi (not decimal,) but I can't figure it out.

Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Link to comment
Share on other sites

  • 3 weeks later...

Dunno if this will help any of you, but here's a formula that solves a quadratic given the values for a, b, c, and the array in which to put the two solutions. Always returns 1, but changes values in input array into the solution values. It also works for quadratics with imaginary roots! (form a + bi)

CODE
Func QuadraticFormula($a, $b, $c, ByRef $Array)

If $b ^ 2 - 4 * $a * $c < 0 Then ; Negative discriminant

$disc = -1 * ($b ^ 2 - 4 * $a * $c)

$imaginary_part = $disc / (2 * $a)

$imaginary_coefficient = $imaginary_part & "i"

$real_coefficient = (-1 * $:mellow: / (2 * $a)

$ans_1 = $real_coefficient & " + " & $imaginary_coefficient

$ans_2 = $real_coefficient & " - " & $imaginary_coefficient

Else

$disc = $b ^ 2 - 4 * $a * $c ; Positive discriminant

$ans_1 = (-1 * $b + Sqrt($disc)) / (2 * $a)

$ans_2 = (-1 * $b - Sqrt($disc)) / (2 * $a)

EndIf

If $ans_1 = $ans_2 Then

$stat = 1 ; number of distinct solutions

Else

$stat = 2 ; number of distinct solutions

EndIf

$Array[0] = $stat

$Array[1] = $ans_1

$Array[2] = $ans_2

Return (1)

EndFunc ;==>QuadraticFormula

Link to comment
Share on other sites

Dunno if this will help any of you, but here's a formula that solves a quadratic given the values for a, b, c, and the array in which to put the two solutions. Always returns 1, but changes values in input array into the solution values. It also works for quadratics with imaginary roots! (form a + bi)

This is pretty good, clarinetmeister. It does return a complex number solution when called for.

Here is a working example with your QuadraticFormula() function to save people time checking it out.

#include <array.au3>

Local $Array[3] ; for results

;quadratic equation  2x^2 + 3x + 7 = 0
QuadraticFormula(2, 3, 7, $Array)
_ArrayDisplay($Array, "2x^2 + 3x + 7 = 0") ; Display results

Local $Array[3] ; for results
;quadratic equation  x^2 - 8x + 16 = 0
QuadraticFormula(1, -8, 16, $Array)
_ArrayDisplay($Array, "x^2 - 8x + 16 = 0") ; Display results


Func QuadraticFormula($a, $b, $c, ByRef $Array)
    Local $stat
    If $b ^ 2 - 4 * $a * $c < 0 Then ; Negative discriminant
        $disc = -1 * ($b ^ 2 - 4 * $a * $c)
        $imaginary_part = $disc / (2 * $a)
        $imaginary_coefficient = $imaginary_part & "i"
        $real_coefficient = (-1 * $b) / (2 * $a)
        $ans_1 = $real_coefficient & " + " & $imaginary_coefficient
        $ans_2 = $real_coefficient & " - " & $imaginary_coefficient
    Else
        $disc = $b ^ 2 - 4 * $a * $c ; Positive discriminant
        $ans_1 = (-1 * $b + Sqrt($disc)) / (2 * $a)
        $ans_2 = (-1 * $b - Sqrt($disc)) / (2 * $a)
    EndIf

    If $ans_1 = $ans_2 Then
        $stat = 1 ; number of distinct solutions
    Else
        $stat = 2 ; number of distinct solutions
    EndIf

    $Array[0] = $stat
    $Array[1] = $ans_1
    $Array[2] = $ans_2

    Return (1)

EndFunc   ;==>QuadraticFormula
Link to comment
Share on other sites

  • 1 month later...

_LCM (lowest common multiple)

_HCF (highest common factor)

_IsPrime

well, as for that and lots of other math functions please try my _Primes.au3 UDF.

i made them with highest precision and best optimization.

cheers j.

as for LCM and HCF, there is an ancient algorithm called Euclidean Algorithm (though probably invented before Euclid). its efficiency is unbeatable.

Edited by jennico
Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

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