all: Error.png Integral.png

Error.png: Out.data.txt Makefile
	echo '\
	set term png;\
	set out "$@";\
	set title "Plain montecarlo integration error";\
	set xlabel "number of sampling points";\
	set ylabel "error";\
	a=1; f(n) = a/sqrt(n);\
	fit f(x) "$<" using 1:4 via a;\
	plot \
	 "$<" u 1:3 with lines title "statistical estimate of the error"\
	,"$<" u 1:4 with linespoints title "actual error"\
	,f(x) with lines title "1/sqrt(n) fit to actual error"\
	'| gnuplot

Integral.png: Out.data.txt Makefile
	echo '\
	set term png;\
	set out "$@";\
	set xlabel "number of points";\
	set ylabel "value of the integral";\
	plot \
	 "$<" with linespoints title "montecarlo integration"\
	,pi/4 with lines title "exact"\
	'| gnuplot

Out.data.txt: main.exe
	>$@
	for N in $$(seq 200 200 10000);\
	do echo $$N; mono $< $$N >> $@;\
	done
main.exe: main.cs matlib.dll
	mcs -target:exe -reference:matlib.dll $<

matlib.dll: ../../matlib/matrix/vector.cs
	mcs -target:library -out:$@ $<
