Re: [GD-DEVEL] Re: plotting data c++

[email protected] (Patolfo)
Newsgroups php.gd.devel
Message-ID <[email protected]>
Using gnuplot is what i am doing right now, but if a share my program as 
it has to be, the the other person must have gnuplot, that's why i tried 
to port perl to c, and compile it, i do have many ways of plotting data, 
excel, matlab, maple, cosmos, gnuplot, origin, but it is necesary to 
have them installed on the other machines, besides, the program is 
interactive, so, every time you change the input variables, you have to 
replot, that means to have to use two program at a time, i want it to be 
just one :)

Yeah sound selfish, excuse me for trying to make a fanvy program by the way.

The code is below:

> #include <stdio.h>
> #include <stdlib.h>
> #include <math.h>
>
> /*    What are we doing here
> We are adding harmonics or terms: n in this case, of a sine curve,
> not a continuous sine curve but a sampled one, this sine curve is
> depicted by x and sin(x) where x can be seen as the abscissa
> while sin(x) the ordinate in a cartesian coordinated system,
> the resulting square wave is seen when plotting x vs y
> */
> int main()
> {
> FILE *destino = fopen( "destino.txt", "w" );
>
> int    n,h;
> float    x,pi=3.14159265358979,y=0;
>     printf("Number of terms: ");
>     scanf("%d", &n);       /* Read the number of terms -harmonics- for 
> the approximation */
>     /* Definition of the curve points, i.e., sampling points that 
> define the curve */
>     for(x = 0;x <= 2*pi;x+=pi/256)
>     {
>         y=0;
>         // Harmonic number, 1 is the fundamental, 2,4,6... the harmonics
>         for(h = 1;h <= n;h+=2)
>         {
>             // Summation of a sine curve harmonics, point by point
>             y+=sin(h*x)/h;
>         };
>         // Yields the points that define and square wave
>     printf("%-2.8g \n", y);
>     fprintf( destino, "%-2.8g %-2.8g \n", x,y);
>     }
>     fclose(destino);
>     return 0;
> }
It gives a file "destino.txt" with a variable number of data pairs 
dpening on the number of samples used, and it is always between 0 and 1.

This is the routine for the dtaa generation, for the gui i am working on 
it, just making fancy with menus and the like, the problem of the plot 
or graph it self is where i am stalled.

Thanks a bunch for your attention
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.