Saturday, April 22, 2006

Calculating logarithms





After reading how Napier and Briggs calculated some values for the first log tables,
I decided to follow the procedure and post a summary
The method I used was explained on mathforum.org in these two posts but I decided to
limit the calculations to 7 decimal places

http://mathforum.org/library/drmath/view/51432.html
http://mathforum.org/library/drmath/view/55600.html



01. let x = 8th root of ten, which will give us a
number close to 1.01

x = 10^2^-8
x = sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(sqrt(10))))))))
1 2 3 4 5 6 7 8

from a 4 function calculator take sqrt(10) 8 times

sqrt01 sqrt(10) = 3.1622776
sqrt02 sqrt(3.1622776) = 1.7782793
sqrt03 sqrt(1.7782793) = 1.3335213
sqrt04 sqrt(1.3335213) = 1.1547819
sqrt05 sqrt(1.1547819) = 1.0746077
sqrt06 sqrt(1.0746077) = 1.0366328
sqrt07 sqrt(1.0366328) = 1.0181516
sqrt08 sqrt(1.0181516) = 1.0090349


02. log(10^2^-8) = 2^-8*log(10) = 2^-8

2^-8 is the same as 1/2^8 or 1/256

log(10^2^-8) = log(1.0090349) = 1/256
from a 4 function calculator 1/256 = 0.0039062


03. assume that log is continous and can be approximated
by a straight line near 1 in the interval from
1 to 1.009... and 1.01
what the formula says below is that the slope of the lhs
is approximately equal to the slope of the rhs


log(x2) - log(1) log(x1) - log(1)
-------------------- =~ ---------------------
x2 - 1 x1 - 1


log(1.01) - log(1) log(10^2^-8) - log(1)
-------------------- =~ -----------------------
1.01 - 1 1.0090349 - 1


x2 - 1
log(x2) =~ ------ * log(x1) since log(1) = 0
x1 - 1


1.01 - 1
log(1.01) =~ -------------- * 0.0039062
1.0090349 - 1


0.01
log(1.01) =~ --------- * 0.0039602 = 0.0043235
0.0090349

or in pari/gp terms
log(1.01) =~ (1/100)/( 10^2^-8 - 1) * 1/256


04. Here the rules for exponents, and correspondingly
logarithms are used to find log(2)

log(2^10/10^3) = log(1024/1000) = log(1.024)

The lhs becomes 10*log(2) - 3*log(10) and since
log(10) = 1 is 10*log(2) -3

log(1.024) = 10*log(2) - 3


05. A linear approximation is applied for log(1.024)


log(1.024) - log(1) log(1.01) - log(1)
------------------- =~ -------------------
1.024 - 1 1.01 - 1


0.024 0.024
log(1.024) =~ ------- * log(1.01) = ------- * 0.0043235
0.01 0.01


log(1.024) =~ 2.4 * 0.004325 = 0.0103764

log(1.024) = 10*log(2) - 3 = 0.0103764

10*log(2) = 3.013764

log(2) = 0.3010376


06. Use pari/gp to look at the accuracy of the estimate

log(2)/log(10) - (3 + 2.4*(1/100)/( 10^2^-8 -1) * 1/256)/10

The log base 10 value for log(2) to 7 dec places

0.3010299 versus the above approximation 0.3010376
good to 5 decimal places.




Monday, April 17, 2006

mingw build gnuplot on winxp

Looking into building gnuplot on windows, the prerequisites were zlib, jpeg, libpng, gd, libiconv and gnuplot. It is probable that some of these prerequisites are not absolutely necessary but I definitely wanted png output.

mingw build consist of mingw3.1.0, minimal system 1.0.10 and msys developer kit 1.0.1
editor is vim. 7-zip used for unzipping and untarring. HelpWorkshop is needed for compiling the help file. The gnuplot makefile mentions the microsoft SDK but isnt necessary if you have the help compiler.
It also has a line for sort.exe which I ignored.



01. download zlib-1.2.3.tar.gz from www.zlib.net scroll down to the link
gunzip and untar (7-zip) or MSYS shell

from an MSYS shell
./configure
make
make -n install -n shows where the files would be installed
make install


02. download jpegsrc.v6b.tar.gz from http://www.ijg.org/files/
gunzip and untar (7-zip) or MSYS shell

from an MSYS shell
./configure
make
skip the make install as it doesn't install the include file and libraries

copy to /usr/local/include/
jconfig.h, jerror.h, jpeglib.h, jmorecfg.h

copy to /usr/local/lib libjpeg.a

03. download libpng-1.2.9.tar.bz2 from sourceforge you can link from the home page
http://www.libpng.org/pub/png/libpng.html
gunzip and untar (7-zip) or MSYS shell

edit scripts/makefile.mingw
line 44 change prefix=/usr to prefix=/usr/local
lines 50,51 to the location of zlib include and lib directories
ZLIBLIB= /usr/lib to ZLIBLIB=/usr/local/lib
ZLIBINC= to ZLIBINC=/usr/local/include

from an MSYS shell
cd back to the main directory out of the scripts subdirectory
make -f scripts/makefile.mingw
once again make install doesnt work so files have to be copied
manually

copy to /usr/local/include png.h pngconf.h
copy to /usr/local/lib libpng.a libpng.dll.a


04. download from http://www.mingw.org/download.shtml
libiconv-1.9.2-mingwPORT.tar.bz2
then download
http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.9.2.tar.gz

gunzip and untar (7-zip) or MSYS shell
first libiconv-1.9.2.tar.gz then libiconv-1.9.2-mingwPORT.tar.bz2

from an MSYS shell
cd to the mingwPORT subdirectory

./mingwPORT.sh

Download file? (Yes) no
Unarchive file? (Yes) no
Source path? (/usr/src/libiconv-1.9.2) /d/prog/devl/temp/libiconv-1.9.2
Installation Directory? (/mingw) /usr/local
CFLAGS (-O3 -s -mms-bitfields -march=-686)

The mingwPORT.sh shell script will then compile the source code
and install the files in /usr/local.
I should mention that libiconv is probably not necessary to compile
gnuplot but since I already had it installed, it needed to be worked
into the process and documented.

05. download from http://www.boutell.com/gd/ scroll to the bottom
for the link to the download

http://www.boutell.com/gd/http/gd-2.0.33.tar.gz

gunzip and untar (7-zip) or MSYS shell

Preliminary steps before compiling gd

cd /usr/local/include -- depending on where you installed msys
could be c:\pathtomsys\msys\1.0\local\include

edit file jmorecfg.h and comment out lines 160-162 due to
confliting types with /MinGW/include/basetsd.h
use c comments /* something */

in the gd subdirectory edit gd-2.0.33/gkanji.c
comment out line 24 typedef void *iconv_t due to a
conflict with libiconv

from an MSYS shell
cd /gd-2.0.33
run configure like this
CFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib ./configure

edit Makefile line 233 from -- to
DEFS = -DHAVE_CONFIG_H
DEFS = -DHAVE_CONFIG_H -DBGDWIN32 -UNONDLL

make
make install

I would like to recognize my source for the makefile change and gd.h patch

http://mailman.lyra.org/pipermail/viewcvs/2005q3/003747.html

Also although the configure completed and flagged that it couldnt find
zlib, it didnt occur to me to use CFLAGS andLDFLAGS until I saw an
email that mentioned

gdparttopng.c needs the function named gdImageCreateFromGd2Part which is
supposed to be found at the shared library named libgd.so. The object
file named gd_gd2.o provides this function for libgd.so. However, the
function gdImageCreateFromGd2Part is only defined in gd_gd2.o if you
have zlib installed.






06. download from ftp://ftp.gnuplot.info/pub/gnuplot/
ftp://ftp.gnuplot.info/pub/gnuplot/gnuplot-4.0.0.tar.gz

gunzip and untar (7-zip) or MSYS shell

Preliminary steps before compiling gnuplot
Apply the following patch to gd.h which should be located in
/usr/local/include

--- ./gd.h Sat Oct 30 12:54:58 2004
+++ ./gd.h Wed Aug 24 12:18:09 2005
@@ -22,9 +22,9 @@
#ifndef WIN32
#define NONDLL 1
#endif /* WIN32 */
-
+#define NONDLL
#ifdef NONDLL
-#define BGD_DECLARE(rt) extern rt
+#define BGD_DECLARE(rt) extern rt _stdcall
#else
#ifdef BGDWIN32
#define BGD_DECLARE(rt) __declspec(dllexport) rt __stdcall


copy the above text to some file name example: gd_h.patch

copy from /usr/local/include to /gnuplot-4.0.0/term/

gd.h
gdfx.h
gd_io.h
and the patch file gd_h.patch

from an MSYS shell
cd gnuplot-4.0.0/term

apply the patch file

patch -p0 < gd_h.patch note that -p0 is -pzero

copy /gnuplot-4.0.0/config/makefile.mgw to
/gnuplot-4.0.0/src/

edit makefile.mgw

makefile edits

DESTDIR
DESTDIR = d:/prog/devl/gnuplot-test
GCCPATH
GCCPATH = d:/prog/devl/MinGW/bin
HCWPATH
HCWPATH = d:/nonfree/HelpWorkshop-sa
MSSDK
MSSDK = d:/Program Files/Microsoft SDK
GNUSORT
GNUSORT = d:/cygwin/bin/sort.exe
FREETYPE=1 comment out this line

if you have helpworkshop installed the location of mssdk, is bypassed

cd /gnuplot-4.0.0/src
CFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib make -f makefile.mgw

assuming all the above was done you should have wgnuplot.exe in you source directory
I didnt run make install yet so details on that later

Wednesday, April 12, 2006

winxp mingw build abiword and bonecho

Visted my brother in law and used his dsl line to download several large files.

abiword-2.4.2.tar.gz gunzipped and untared it is 106MB somewhat of a strange build in that you only use make, which the notes refer to as a diving make? Anyway only a couple of problems were encountered.

01. had to copy zlib.h and zconf.h to libpng from zlib

02. had to comment out #define NOGDI from

\abiword-2.4.2\abi\src\af\util\win
\abiword-2.4.2\abi\src\af\xap\win

03. had to create a directory
\abiword-2.4.2\libs\zlib\lib containing libzdll.a
or more simply everything in the lib subdirectory from
zlib123-dll.zip

This last step was trialed until the link completed the error being cannot find -lzdll

Later I will try to edit the makefile but without configure, this seems the more practical solution


**********

Details in an earlier post but cygwin compiled the firefox bonecho source without incident. The binary chokes on some web pages and dumps but I was able to use nightly tester tools to install all my favorite extensions.
I have been using it every day and except for some bookmark problems and the same slow scrolling using the up and down scroll buttons, it is the same as the cygwin build for firefox 1.5

Sunday, April 09, 2006

math tool pari/gp

Although linux is my platform of choice, I work extensively on windows. Open source and free compilers determine the applications. One of my favorite math tools is pari/gp. The website url is http://pari.math.u-bordeaux.fr/
If you want to compile the source code use the download link and have a fairly complete installation of cygwin on your development system.

The cygwin dll's required to run the application are cygcrypt-0.dll, cygncurses-8.dll,
cygperl5_8_5.dll, cygreadline5.dll and cygwin1.dll.

Here is an example of solving a system of linear equations using pari/gp
via two methods.

The example problem is a 3 x 3 matrix a and a column matrix b such that
a * x = b where x is the solution

Using pari/gp, begin by defining matrix a and column vector b

gp > a = [ 1, 2, 1 ; 3, -1, -3; 2, 3, 1 ]
a is a 3 x 3 matrix where each row is separated by a semicolon ;

gp > b = [ 3; -1; 4 ]
b is a 3 x 1 column vector or matrix

To solve the system of linear equations we can use the function matsolve(a,b)
c = matsolve(a, b) and the result is the column vector [ 3; -2; 4 ]

another method is to use the inverse matrix of a
inva = 1/a

since inva * a = identity matrix then inva * a * x = inva * b
so x = inva * b

x = (1/a)* b

a third method is to use the adjoint matrix of a and the determinant of a
which is the same as calculating the inverse of a

adja = matadjoint(a)
deta = matdet(a)

inva = adja / deta

x = inva * b


Later I will provide more information about the adjoint and inverse of a
square matrix