tags:

views:

40

answers:

2

Hiya, I have written two different methods to numerically differentiate a function and I am looking for a way to compare them. I have installed GNUPlot and would like to make a file (e.g. approximations.dat) for it to plot. At the moment my programn prints a series of columns with x-coordinate, approximation 1, approximation 2 and actual value like this:

x-coord      approx 1      approx 2      actual  
x-coord      approx 1      approx 2      actual  
x-coord      approx 1      approx 2      actual  
x-coord      approx 1      approx 2      actual  
 ...            ...           ...          ...

Is there a way for me to make this into a file which can be input easily into GUPlot? Many thanks.

Jack

+1  A: 

This is already a format well suited for gnuplot. Look up help plot using from the gnuplot prompt.

In order to get this into a file, you can either pipe the standard output from your program (e.g. in Unix-like systems with yourprog > file.dat), or use the C function fprintf (with fopen and fclose).

Svante
In order to 'pipe' it in do i need to have my program returning a set of arrays or just having the columns printed out as is currently the case?
Jack Medley
@Jack Medley: Your "just printing out" is the same as "outputting on standard output stream". Pipes operate on streams, so "just printing out" is right.
Svante
Cool, ive starting implementing the fprintf approach but I'll have a crack at that after for good measure!
Jack Medley
I had a go at this 'piping' approach with this code: http://pastebin.com/pjrQLNpkthen in terminal used:gcc -lm mycode.c > test.datBut that printed a blank file. I think we may talking at crossed purposes :s
Jack Medley
@Jack Medley: Piping has nothing to do with the compilation. You can pipe any program output. Simply run your program with the pipe: `myprog > file.dat`.
Svante
+1  A: 

This tutorial should help you http://www.duke.edu/~hpgavin/gnuplot.html

Rahul
Yeah, i found this a while ago. My problem is mainly getting the data into the .dat file. I can do the rest. Cheers
Jack Medley