Can I use logarithms in math equations?

Can I use logarithms in math equations?
And where in the world are the free resorces to look at other dictionaries? Everything costs money!!!

A bit as UNIX and you solve your issue. BASH script as follows

set TheNumber to 100
set TheLog to (do shell script ("echo 'l(" & (TheNumber as string) & ")' | bc -l")) as real
display dialog TheLog as string
do shell script "man -t bc | open -f -a /Applications/Preview.app"

The square root, cos, sin and other

Basic UNIX is here
http://www.ss64.com/osx/index.html

Advanced UNIX is here
http://developer.apple.com/documentation/Darwin/Reference/ManPages/index.html#//apple_ref/doc/framework/manpages

This seems to only allow natural logarithms to the base ā€œeā€. Iā€™m looking for the common logarithm to the base ā€œ10.ā€ I didnā€™t see such an option in the pdf file. Is the common logarithm not a part of unix?

log10 is part of math library and is on Apple Developer site above and you can get a ā€˜manā€™ on it

do shell script "man -t log10 | open -f -a /Applications/Preview.app"

I donā€™t know how to load math library to run log10, maybe someone smarter at UNIX would know.

Have Fun

Thereā€™s lots of free stuff. Check out Satimage osax:

http://www.satimage.fr/software/en/downloads_osaxen.html

gl,

If all you can get is the natural log, then a little math converts that to the base 10 log
with this equationā€¦ log(x) = ln(x) / ln(10)

log10(100)

on log10(TheNumber)
	set natural_log to (do shell script ("echo 'l(" & (TheNumber as string) & ")' | bc -l")) as real
	set natural_log_of_10 to (do shell script ("echo 'l(10)' | bc -l")) as real
	set common_log to natural_log / natural_log_of_10
	return common_log
end log10

Deivy has a set of editable/readable math functions posted in ScriptBuilders called ā€œMatematica3ā€ that do not (as I recall) use shell calls to get the answers.

Still no built in support for this in AS?

Here is a log function I wrote using this paper on log algorithms.

https://www.ams.org/journals/mcom/1954-08-046/S0025-5718-1954-0061464-9/S0025-5718-1954-0061464-9.pdf

on logb(base, x)
	local i, n, p, q, ln, ln1, pln, pq, pp, ppq, ppp, tmp
	set ln1 to 0
	repeat while (base ^ ln1) ā‰¤ x
		set ln1 to ln1 + 1
	end repeat
	set ln1 to ln1 - 1
	set x to x / (base ^ ln1)
	if x > 1 then
		set pln to x
		set fr to true -- fr is First Run (a boolean)
		repeat
			set n to 0
			repeat while (x ^ n) < base
				set n to n + 1
			end repeat
			set n to n - 1
			set tmp to x
			set x to base / (x ^ n)
			set base to tmp
			if fr then -- check if First Run
				set p to 1
				set q to n
				set ppp to 0
				set ppq to 1
				set fr to false
			else
				set p to ppp + n * pp
				set q to ppq + n * pq
				set ppp to pp
				set ppq to pq
			end if
			set pp to p
			set pq to q
			set ln to p / q
			set tmp to ln - pln
			if tmp < 0 then set tmp to -tmp
			if tmp < 1.0E-20 then
				exit repeat
			end if
			set pln to ln
		end repeat
	else
		set ln to 0
	end if
	return ln + ln1
end logb

here is a natural log function

on ln(x) -- https://www.codeproject.com/tips/311714/natural-logarithms-and-exponent
	local N, P, L, R, A, E
	set E to "2.71828182845904523536" as real --2.718281828459
	set P to x
	set N to 0
	repeat while P ā‰„ E
		set P to P / E
		set N to N + 1
	end repeat
	set N to N + (P / E)
	set P to x
	repeat
		set A to N
		set L to (P / (E ^ (N - 1.0)))
		set R to (N - 1.0) * E
		set N to (L + R) / E
		if N = A then exit repeat
	end repeat
	return N
end ln

or fastest so far is using the equation log(x) = ln(x) / ln(10) ā€“ for any base

on logb(base, x)
	script L
		property E : "2.71828182845904523536" as real
		on ln(x) -- https://www.codeproject.com/tips/311714/natural-logarithms-and-exponent
			local N, P, L, R, A
			set P to x
			set N to 0
			repeat while P ā‰„ E
				set P to P / E
				set N to N + 1
			end repeat
			set N to N + (P / E)
			set P to x
			repeat
				set A to N
				set L to (P / (E ^ (N - 1.0)))
				set R to (N - 1.0) * E
				set N to (L + R) / E
				if N = A then exit repeat
			end repeat
			return N
		end ln
	end script
	return (L's ln(x)) / (L's ln(base))
end logb
1 Like