I have set of data point (x_i,y_i) from a text file. How can I write a C-program that reads those data, send the data to Sage, computes the Pearson correlation and send the result back to C. I have no idea how can I use C to give input to some Linux-program and read its output to a variable.
Share
OK, let me get it straight: you are working on a C program, and within that program you need to calculate Pearson’s correlation coefficient. You’d like to pass these calculations to Sage rather than code them yourself.
Now, I don’t know Sage, but I guess it is possible to run it from command line. Assuming that you can prepare an input file or files for Sage, and run the calculations in Sage producing an output, I would then use the
systemfrom stdlib.h (man 3 system) to call the command line. Here is the outline of the steps in your C program:That said, I would not do it using Sage. Pearson correlation coefficient is easy enough to implement in C, and if you do it, your program will not depend on the whole Sage installation.