Maths

Discuss other useful utilities, general computing tips & tricks, Internet resources, etc.
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

Re: Maths

31 Oct 2013, 09:20

@nnnik
done :)
John ... you working ?
User avatar
Avi
Posts: 193
Joined: 30 Sep 2013, 09:51
Location: India
Contact:

Re: Maths

01 Nov 2013, 07:47

Sum of first N natural numbers, sum of their squares/cubes....till power 10
Pretty scary stuff :shock: . great find smorgasboard
Writes at Dev Letters

Clipjump Clipboard Manager : More Scripts (updated 2019)

Image
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

Re: Maths

01 Nov 2013, 07:58

@Avi
mm.. dont know what to say.
it is pretty easy once you check that links in the post.
Also i dont find any use of them, though till power 3 OR 4 is fine. rest i guess is redundant.

But thanks for linking it :) I mean "great find"
John ... you working ?
User avatar
Avi
Posts: 193
Joined: 30 Sep 2013, 09:51
Location: India
Contact:

Re: Maths

01 Nov 2013, 08:02

These are the base-2-base conversion functions I wrote one time . Maybe someone finds it interesting.

Code: Select all

;Base to Number and Number to Base conversion
;Base = 16 for HexaDecimal , 2 for Binary, 8 for Octal and 10 for our own number system

number := 10241212
msgbox % t := Number2Base(number, 16)
msgbox % Base2Number(t, 16)

Number2Base(N, base=16){
        loop % baseLen:=base<10?Ceil((10/base)*Strlen(N)):Strlen(N)
                D:=Floor(N/(T:=base**(baseLen-A_index))),H.=!D?0:(D>9?Chr(D+87):D),N:=N-D*T
        return Ltrim(H,"0")
}

Base2Number(H, base=16){
        S:=Strlen(H),N:=0
        loop,parse,H
                N+=((A_LoopField*1="")?Asc(A_LoopField)-87:A_LoopField)*base**(S-A_index)
        return N
}
Writes at Dev Letters

Clipjump Clipboard Manager : More Scripts (updated 2019)

Image
User avatar
Avi
Posts: 193
Joined: 30 Sep 2013, 09:51
Location: India
Contact:

Re: Maths

01 Nov 2013, 08:13

smorgasbord wrote:rest i guess is redundant.
That might have required some great thinking. :Hats Off:
Writes at Dev Letters

Clipjump Clipboard Manager : More Scripts (updated 2019)

Image
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

Re: Maths

01 Nov 2013, 10:18

"These are the base-2-base conversion functions I wrote one time . Maybe someone finds it interesting."
It surely is :)
but i doubt the guys who reach till here will be few and far in between (at my pace)
thanks for posting that :)
John ... you working ?
User avatar
Avi
Posts: 193
Joined: 30 Sep 2013, 09:51
Location: India
Contact:

Re: Maths

02 Nov 2013, 03:23

smorgasbord wrote:but i doubt the guys who reach till here will be few and far in between (at my pace)
OK , then I will start a new topic hosting the code, OR you can simply link it in the OP. This topic deserves to be in Scripts and Functions, if you too feel so please contact a moderator.
Writes at Dev Letters

Clipjump Clipboard Manager : More Scripts (updated 2019)

Image
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

Re: Maths

02 Nov 2013, 05:22

link it in the OP?
what does that mean?
:(
Also do start a new topic hosting the code for sure where in all the conversions are there. that must be helpful for people for sure.
John ... you working ?
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

Re: Maths

10 Nov 2013, 00:31

Extremely large factorial calculator added, dont know the limit how large, if time permits will make the current limit increased further to that limit raised to the same limit.
John ... you working ?
User avatar
Avi
Posts: 193
Joined: 30 Sep 2013, 09:51
Location: India
Contact:

Re: Maths

10 Nov 2013, 00:59

smorgasbord wrote:Extremely large factorial calculator added, dont know the limit how large, if time permits will make the current limit increased further to that limit raised to the same limit.
Good work and I feel it should work till infinity. ( much like SM_Fact() )
However Clipboard := line should be

Code: Select all

Clipboard := "" final
so that the large number is not converted (rounded off) into AHKs max limit 9223372036854775807 .

Try factorial 40 in your code and see the output on Clipboard.
Writes at Dev Letters

Clipjump Clipboard Manager : More Scripts (updated 2019)

Image
User avatar
Avi
Posts: 193
Joined: 30 Sep 2013, 09:51
Location: India
Contact:

Re: Maths

10 Nov 2013, 01:04

Maybe its offtopic with respect to the stuff posted in this topic but I would like to highlight SpeQ Mathematics @ http://www.portablefreeware.com/index.php?id=883 which is a very light, simple code-like interfaced calculator , grapher and a great Mathematics tool. I downloaded it yesterday and like it very much and that's the only reason why I am posting about it.
Writes at Dev Letters

Clipjump Clipboard Manager : More Scripts (updated 2019)

Image
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

Re: Maths

10 Nov 2013, 01:24

Avi
That is so much very helpful . thanks
mm.. see pm for the second last post lol
John ... you working ?
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

Re: Maths

12 Nov 2013, 10:54

Sum Of N terms of Arithmetic Progression or Geometric Progression by entering three values and N
added
John ... you working ?
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

Re: Maths

02 Dec 2013, 10:33

Solving Polynomial of any integral Degree to get the nearest roots. (under construction)
Feel free to tweak the code for improvements



added :)
upgrading found a bug!
updated
John ... you working ?
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

Re: Maths

02 Dec 2013, 21:09

updated
John ... you working ?
User avatar
Avi
Posts: 193
Joined: 30 Sep 2013, 09:51
Location: India
Contact:

Re: Maths

03 Dec 2013, 04:33

"Solving Polynomial of any integral Degree to get the nearest roots."
I wrote something like that ( funcname: Roots() ) a while ago ( https://github.com/avi-aryan/autohotkey ... ctions.ahk ) , I am sure this function can be more optimized so I will like to see how your function performs.
Writes at Dev Letters

Clipjump Clipboard Manager : More Scripts (updated 2019)

Image
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

Re: Maths

03 Dec 2013, 07:44

@avi
thanks for response

my net is kaput presently

posting from cyber cafe,

the scripts splits the string based on + OR - sign and the checks for all values from - limiter to + limiter that user enters after comma, The increment is 0.1 which can be changed ( line 82) may be

and returns the nearest values

:)

it can be further optimised to a large extent.

feel free to edit it :)
John ... you working ?
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

Re: Maths

03 Dec 2013, 08:52

related to solving polynomial of any degree

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
FileDelete, result.txt
InputBox, k, Any degree polynomial solver, Enter (Inegral) `coefficients of X in decreading orders of (Integral) power of X with + or - sign as the case may be`n`nThe last coefficient shall be the coefficient of x raised to power 0`n`nFor Eg.`nIF Equation: 5X^2+1=0 and  the limit you want is -10 to 10`nEnter +5+0+1COMMA10`nPut this script in a separate folder`nExtract nearest roots from first few lines of sort.txt file`n`n`under testing., , 640, 640
StringSplit, m, k, `,
check := 0-m2
limit := 2 * abs(check)
result := 0
k := m1

NUMBERS := RegExReplace(k, "-", "+")
StringSplit, N, numbers, +

SIGNS := RegExReplace(k, "\d+", "|")
StringSplit, S, SIGNS, |

Loop % 2 * (s0-1)
{
	omg := mod(A_index, 2)
	if ( omg == 0 ) ; even
	{
		index := floor(A_index/2) + 1
		k%A_index% := n%index%
		index =
	}
	else                             ; odd
	{
		index := floor( (A_index + 1) / 2 )
		k%A_index% := s%index%
			index =
	}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Power := s0 - 1
;MsgBox power is %power%
Loop
	
{
	
	if ( check > m2 + 1 )
		break
	

	Loop, % power 
	{
	o1 := 2 * A_index - 1 ; 1,3,5,7,9..signs
	e := 2 * A_index ; 2,4,6,8, coefficients
	;MsgBox %check% is check
      o1 := k%o1%
	 ; MsgBox %o1% must be +
	if ( o1 = "+" )
	{
		
		result := result + k%e% * ( check ** (Power-1) )
		;MsgBox %result% for +
		if ( abs(check) = 0 )
					result := 0 + k%n0%
				
	}
	else
	{
		result := result - k%e% * ( check ** (Power-1) )
		;MsgBox %result% for -
		if ( abs(check) = 0 )
		
									result := 0 - k%n0%
				
	}
;	MsgBox % result "power is" power - 1 
			power --
	
    }
			;MsgBox %result% for check %check%
	;MsgBox % result " again"
	absolute := abs(result)
	FileAppend, %absolute% is absolute value for comparison & result is %result% for x %check% `n, result.txt
	;Power := floor(k0/2)
	Power := s0 - 1
	result := 0
	check := check + 0.1
	
}
FileRead, Contents, result.txt
if not ErrorLevel  ; Successfully loaded.
{
    Sort, Contents
    FileDelete, sort.txt
    FileAppend, %Contents%, sort.txt
    Contents =  ; Free the memory.
}
;MsgBox check Sort file in the folder of the script is located

loop, % power - 1
	
{	
	filereadline, ans_, sort.txt, A_index
	StringSplit, ans, ans_, %A_space%
	;MsgBox % ans0
	if ( abs(ans1) = 0 )
		final .= ans1 " for x " ans13 . ans14 . " Real Root" . "`n"
else
	final .= ans1 " for x " ans13 . ans14 . " Not exact AND/OR non-real root" . "`n"
	 
	
}
MsgBox %final% `nThe script so far cannot evaluate imaginery roots `n`nAnd as such they need to be ruled out on your own.








ExitApp
esc::exitapp
John ... you working ?
User avatar
Avi
Posts: 193
Joined: 30 Sep 2013, 09:51
Location: India
Contact:

Re: Maths

04 Dec 2013, 02:44

smorgasbord wrote:the scripts splits the string based on + OR - sign and the checks for all values from - limiter to + limiter that user enters after comma, The increment is 0.1 which can be changed ( line 82) may be
and returns the nearest values

1. I think you should detect the limit automatically and not ask user for it. In my Roots() function , I sum all the Abs ( coefficients ) to generate upper and lower limits . For eg >

1,5,6 (x(sq) + 5x + 6) has limits as +- (1+5+6) i.e -12 to +12 .

What do you think about this hypothesis . I feel in the polynomial scenario , the roots will always lie between these limits.
This is because the above function can be written as (x+3)*(x+2) = f(x) and so if any roots exist , it will always be less than
the abs sum of the coefficients which you can get by multiplying the above expression.

2. If you keep the increment 0.1 , you may face unnecessary slow results . To boost the process, I recommend auto-adjusting the limits . You can keep the increment as 1 and then when you see that the result of the expression toggles its sign (like +0.23 to -0.12), you will know there is a root in between and you can rewind back and slow the increment for more accurate results. I will not write more on this point as I not sure how your function actually works . :mrgreen:
Writes at Dev Letters

Clipjump Clipboard Manager : More Scripts (updated 2019)

Image
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

Re: Maths

04 Dec 2013, 12:07

@avi :) seems very significant info..
will reply in 10 days '
:)
some important stuff:)
cya all
John ... you working ?

Return to “Other Utilities & Resources”

Who is online

Users browsing this forum: No registered users and 58 guests