all:A.svg B.txt C.svg

A.svg: out.data Makefile
	rm fit.log
	echo '\
	set term svg font "Arial,20";\
	set out "$@";\
	set title "Rutherford and Soddy experiment";\
	set xlabel "Time in Days";\
	set ylabel "Per-cent Activity";\
	a=100;b=0.2;c=1;\
	f(x)=a*exp(-b*x)+c;\
	fit f(x) "$<" u 1:2:3 yerrors via a,b,c;\
	plot "$<" with errorbars title "experimental data"\
	,"$<" index 1 with lines title "exponential fit"\
	,f(x) with lines title "gnuplot fit"\
	' | gnuplot

C.svg: out.data Makefile
	echo '\
	set term svg font "Arial,20";\
	set out "$@";\
	set title "Rutherford and Soddy experiment";\
	set log y;\
	set xlabel "Time in Days";\
	set ylabel "Per-cent Activity";\
	plot "$<" with errorbars title "experimental data"\
	,"$<" index 1 with lines title "best fit"\
	,"$<" index 2 with lines title "c_0+dc_0"\
	,"$<" index 3 with lines title "c_0-dc_0"\
	,"$<" index 4 with lines title "c_1+dc_1"\
	,"$<" index 5 with lines title "c_1-dc_1"\
	' | gnuplot

out.data B.txt :main.exe
	mono $< 1> out.data 2>B.txt

main.exe: main.cs lsfit.cs matlib.dll
	mcs $(filter-out %.dll,$^) -reference:$(lastword $^)

SRC := \
$(HOME)/public_html/prog/matlib/matrix/vector.cs\
$(HOME)/public_html/prog/matlib/matrix/matrix.cs\
$(HOME)/public_html/prog/solutions/problems/2-linear-equations/gramschmidt.cs\
$(HOME)/public_html/prog/solutions/problems/2-linear-equations/backsubst.cs\
$(HOME)/public_html/prog/solutions/problems/2-linear-equations/solve.cs\
$(HOME)/public_html/prog/solutions/problems/2-linear-equations/inverse.cs\

matlib.dll: $(SRC)
	mcs $^ -target:library -out:$@

clean:
	rm -f *.dll *.exe A* B* C* log*

comma:=,
empty:=
space:=$(empty) $(empty)
clist = $(subst $(space),$(comma),$(1))
