AutoHotkey Community

It is currently May 27th, 2012, 4:53 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 43 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject:
PostPosted: April 6th, 2010, 4:39 pm 
Offline

Joined: March 20th, 2010, 9:49 am
Posts: 224
its completely rewritten

check it out


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 6th, 2010, 11:29 pm 
Offline

Joined: February 10th, 2007, 5:18 am
Posts: 92
the index of the treeview is unique from computer to computer and so would not work properly for all users of the script

Also, your additions (cubic and quartic) still don't solve for complex solutions. In addition, they are sometimes even flat out wrong. For example, quartic solutions should have 4 results in total. For example, x^4+1=0 should ONLY have complex solutions as no real number would satisfy the equation, but your script gives 4 results (2 unique results), all of which are real (which we know to be wrong)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 7th, 2010, 1:45 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
maximo3491 wrote:
even flat out wrong
This could be the problem with the quartic function I adapted to AHK. I found and fixed several problems, but a few could have remained. Please post wrong results so I could debug the public code.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 7th, 2010, 2:48 am 
Offline

Joined: February 10th, 2007, 5:18 am
Posts: 92
Laszlo, just try a simple case of x^4+1=0

Doing simple algebra we would get that x = 4th root of -1. This can only be a complex solution. The quartic function returns real solutions, which is impossible.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 7th, 2010, 2:50 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
I found the bug: the quartic solver misses the handling of the special bi-quadratic case (after depression u**4 + p*u**4 + r = 0). It is disturbing that the quartic solver source codes, which Google finds first, all have serious bugs.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 7th, 2010, 4:14 am 
Offline

Joined: February 10th, 2007, 5:18 am
Posts: 92
I added a polynomial solver function that solves for virtually any polynomial order. I uploaded it here. I think its much easier to use than cubic and quartic solutions.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 7th, 2010, 5:41 am 
Try adding:

Code:
 
x:=TV_GetSelection()
;msgbox %x%

TV_GetText(Selected, x)

;Linear
if (Selected = "Linear") {
; ...


to get the treeview to respond. If you're only going to have one category though, a listbox or listview might suffice.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 7th, 2010, 12:00 pm 
Offline

Joined: April 22nd, 2009, 6:04 am
Posts: 29
treelicious wrote:
Try adding:

Code:
 
x:=TV_GetSelection()
;msgbox %x%

TV_GetText(Selected, x)

;Linear
if (Selected = "Linear") {
; ...


to get the treeview to respond. If you're only going to have one category though, a listbox or listview might suffice.

Code:
TV_GetText(Selected, TV_GetSelection())
;Linear
if (Selected = "Linear") {
; ...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 7th, 2010, 1:37 pm 
Offline

Joined: March 20th, 2010, 9:49 am
Posts: 224
thx for the treeview solutin


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 7th, 2010, 1:41 pm 
Offline

Joined: March 20th, 2010, 9:49 am
Posts: 224
oh well

maximo has done it

i guess i shud discontinue this one :cry:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 7th, 2010, 2:00 pm 
Offline

Joined: February 10th, 2007, 5:18 am
Posts: 92
You could make the gui to go with the function


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 7th, 2010, 3:43 pm 
Offline

Joined: March 20th, 2010, 9:49 am
Posts: 224
really ?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 7th, 2010, 4:36 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
...in any case, here is a quick and dirty fix for the quartic solver. During the bug hunt I changed almost everything, so it is faster now than the original was, and solved all the examples I fed into it. Among 1 million random equations solved (took less than an hour) there was 1 with larger max error than |maxroot|*1.e-6 (~1.3e-5), and 3 with relative errors around 1.e-7. All others solutions were more accurate.
Code:
cbrt(x) { ; signed real cubic root
   Static z = 0.33333333333333333
   Return x<0 ? -(-x)**z : x**z
}

Max3(a,b,c) {
   Return a < b ? (b > c ? b : c) : (a > c ? a : c)
}

;----------------------------------------------------------------
; C-idea http://van-der-waals.pc.uni-koeln.de/quartic/quintic_C.c
;----------------------------------------------------------------

cubicX(A3,A2,A1,A0, ByRef X) {         ; X <- Max Real root of cubic, require X >= 0
    Static eps = 1.e-99, o6 = .16666666666666667, p23 = 2.09439510239319549 ; 2pi/3
    if (A3 != 0) { ; cubic
        W := A2/A3/3
        P := A1/A3/3 - W*W, P *= -P*P  ; make P >= 0
        Q := (A1*W-A0)/A3/2 - W*W*W
        DIS := Q*Q - P
        if (DIS >= 0)                  ; DIS > 0: one real solution
            D := sqrt(DIS), X := cbrt(Q+D) + cbrt(Q-D) - W
        if (DIS < 0 || X < 0) {        ; three real solutions, X<0: ROUNDING ERROR!!!
            PHI := acos(Q/sqrt(P)) / 3
            X := 2*P**o6 * Max3( cos(PHI), cos(PHI+p23), cos(PHI+2*p23)) - W
        }
    }
    else if (A2 != 0)                  ; QUADRATIC
        P := A1/A2/2,  X := sqrt(abs(P*P-A0/A2)) - P
    else                               ; LINEAR equation
        X := A0/A1

    X := X < 0 ? 0 : X                 ; X < 0: ROUNDING ERROR!!!

    y := A1+X*(2*A2+X*3*A3)            ; p'(X) = denominator in Newton iteration
    z := A0+X*(A1+X*(A2+X*A3))         ; p(X)
    U := X - z/y                       ; Newton iteration, if reduces rounding errors
    if (abs(y) > eps  &&  abs(A0+U*(A1+U*(A2+U*A3))) < abs(z)  &&  U >= 0)
        X := U
}

quartic(a,b,c,d,f, ByRef x0,ByRef xi0, ByRef x1,ByRef xi1, ByRef x2,ByRef xi2, ByRef x3,ByRef xi3, ByRef Nsol) {
    Static eps = 1.e-99
    Nsol := 0
    b := b/a/4, c := c/a, d := d/a, f := f/a, bb := b*b

    p :=-6*bb + c
    q := 8*b*bb - 2*b*c + d
    r :=-3*bb*bb + bb*c - b*d + f
                                       ; biquadratic u^4 + p*u^2 + r = 0: CHEAT (small error: "a" normalized to 1)
    q := abs(q)>1.e-13 ? q : q<0 ? -1.e-13 : 1.e-13

    cubicX(1,2*p,p*p-4*r,-q*q, z0)     ; Max real root z0 >= 0
    z0 := z0<eps ? eps : z0            ; NO division by 0 !

    xK  := sqrt(z0)
    xL  := q/2/xK
    sqm := 4*xL - 2*p - z0
    sqp := sqm - 8*xL
    xi0 := xi1 := xi2 := xi3 := 0.0

    if (sqp >= 0 && sqm >= 0) {
        x0 := ( xK + sqrt(sqp))/2
        x1 :=   xK - x0
        x2 := (-xK + sqrt(sqm))/2
        x3 :=  -xK - x2
        Nsol := 4
    }
    else if (sqp >= 0 && sqm < 0) {
        x0 := (xK + sqrt(sqp))/2
        x1 :=  xK - x0
        x2 := x3 := -xK/2
        xi3:=-xi2:= sqrt(-sqm/4)
        Nsol := 2
    }
    else if (sqp < 0 && sqm >= 0) {
        x0 := (sqrt(sqm)-xK)/2
        x1 := -x0-xK
        x2 := x3 := xK/2
        xi3:=-xi2:= sqrt(-sqp/4)
        Nsol := 2
    }
    else if (sqp < 0 && sqm < 0) {
        x2 := x3 := xK/2
        x0 := x1 := -x2
        xi1:=-xi0:= sqrt(-sqm/4)
        xi3:=-xi2:= sqrt(-sqp/4)
        Nsol := 0
    }

    x0 -= b, x1 -= b, x2 -= b, x3 -= b
}


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 43 posts ]  Go to page Previous  1, 2, 3

All times are UTC [ DST ]


Who is online

Users browsing this forum: Yahoo [Bot] and 13 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group