From: W. Trevor King Date: Wed, 13 Feb 2013 01:13:15 +0000 (-0500) Subject: error.gp: Add gnuplot script and rules to build an error-scaling plot X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d9db6719865039f3a28b1582f9eec741f8f1a301;p=assignment-template.git error.gp: Add gnuplot script and rules to build an error-scaling plot As requested in the homework. I didn't bother writing a stand-alone script for building the data files, although you could split my error-%.data rule out into its own script if you wish. --- diff --git a/.gitignore b/.gitignore index 830e366..816ccac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ one_gaussian_bump error_analysis *.o +*.data +*.png diff --git a/Makefile b/Makefile index d66f5f8..44e3fe2 100644 --- a/Makefile +++ b/Makefile @@ -75,7 +75,7 @@ help: # target: clean - remove automatically generated files clean: - $(RM) -rf $(PROGRAMS) *.o $(RELEASE)* + $(RM) -rf $(PROGRAMS) *.o *.data *.png $(RELEASE)* # target: dist - generate a tarball packaging the source # Here, we move the source into a temporary release directory, tar the @@ -138,8 +138,19 @@ $(CXX_PROGRAMS): % : $$($$(*)_OBJECTS) # gnuplot plot.gp # where plot.gp was a gnuplot script for plotting data generated by # RUN_PROGRAM. -run: $(PROGRAMS) - ./$(RUN_PROGRAM) +run: error.png + +.SECONDEXPANSION: +error-%.data: $(PROGRAMS) + echo -e "# dt\terror" > "$@" + for dt in 0.00004 0.0002 0.001 0.005 0.025; do \ + echo -en "$$dt\t" >> "$@"; \ + ./one_gaussian_bump --time-step "$$dt" --$(@:error-%.data=%) | \ + ./error_analysis >> "$@"; \ + done + +error.png: error.gp error-euler.data error-midpoint.data error-rk4.data + gnuplot "$<" > "$@" # Pattern rule for compiling object files from C++ source # There is an implicit rule for this in GNU make diff --git a/error.gp b/error.gp new file mode 100644 index 0000000..7975aee --- /dev/null +++ b/error.gp @@ -0,0 +1,11 @@ +set term png +set title 'Error scaling' +set xlabel 'dt' +set ylabel 'relative error' +set key left top +set logscale x +set logscale y +set style data linespoints +plot 'error-euler.data' title 'Euler', \ + 'error-midpoint.data' title 'Midpoint', \ + 'error-rk4.data' title '4th order Runge-Kutta'