#include #include #include #ifndef PI #define PI 3.14159265358979323846 #endif #define NMAX 100 void tp_conv( double x, double y, double *tpx, double *tpy ); void tp_pa( double x, double y ); void tp_line( double x1, double y1, double x2, double y2, char *fmt ); void tp_func( double *x, double *y, int imin, int imax, char *fmt ); void tp_func_color( double *x, double *y, int imin, int imax, char *fmt, double r, double g, double b ); void tp_func_ncolor( double *x, double *y, int imin, int imax, char *fmt, char *color ); FILE *fp_tpic; double xd[NMAX+1], yd1[NMAX+1], yd2[NMAX+1]; double cx, cy, xmin, ymin, ysize; int main() { double h, x, y, xmax, ymax, xsize, tpx, tpy; int k; char *filename, string[128]; xmin = 0; xmax = PI; ymin = -1; ymax = 1; h = ( xmax - xmin )/NMAX; for(k=0; k<=NMAX; k++){ xd[k] = xmin + h*k; yd1[k] = sin(xd[k])*sin(9*xd[k]); yd2[k] = exp( -xd[k] )*sin(9*xd[k]); } /********* TeXo—Ν **********/ xsize = 5000; ysize = 2000; cx = xsize/( xmax - xmin ); cy = ysize/( ymax - ymin ); filename="sin.tex"; fp_tpic=fopen(filename,"w"); fprintf(fp_tpic,"\\documentclass{jarticle}\n"); // fprintf(fp_tpic,"\\usepackage[dvips]{color}\n"); // fprintf(fp_tpic,"\\ExecuteOptions{usenames}\n"); fprintf(fp_tpic,"\\begin{document}\n"); fprintf(fp_tpic,"\\pagestyle{empty}\n"); fprintf(fp_tpic,"\\unitlength 0.001in\n"); fprintf(fp_tpic,"\\begin{picture}(5000,2000)(0,-2000)\n"); /******* ŠΦ”•`‰ζ ******/ fprintf(fp_tpic,"\\special{pn 16}%%\n"); tp_func( xd, yd1, 0, NMAX, "fp" ); tp_func( xd, yd2, 0, NMAX, "da 0.05 0.05" ); // tp_func_color( xd, yd1, 0, NMAX, "fp", 1, 0, 0 ); // tp_func_color( xd, yd2, 0, NMAX, "fp", 0, 1, 0 ); // tp_func_ncolor( xd, yd1, 0, NMAX, "fp", "Cyan" ); // tp_func_ncolor( xd, yd2, 0, NMAX, "fp", "VioletRed" ); /******** ΐ•W޲ *******/ fprintf(fp_tpic,"\\special{pn 8}%%\n"); tp_line( xmin, 0., xmax, 0., "fp" ); /*** x-޲ ***/ tp_line( 0., ymin, 0., ymax, "fp" ); /*** y-޲ ***/ for(k=1; k<=6; k++ ){ /*** x-޲–ڐ·‚θ ***/ x=0.5*k; y=0; tp_line( x, -0.05, x, 0.05, "fp" ); tp_conv( x, y, &tpx, &tpy ); fprintf(fp_tpic,"\\put(%.0f,%.0f){\\large$%.1f$}%%\n", tpx-100, -tpy-200, x ); } fprintf(fp_tpic,"\\end{picture}\n"); fprintf(fp_tpic,"\\end{document}\n"); fclose(fp_tpic); /********* pLaTeX Žΐs ********/ sprintf(string,"platex %s", filename ); system(string); return 0; } void tp_conv( double x, double y, double *tpx, double *tpy ) { *tpx = cx*( x - xmin ); *tpy = ysize - cy*( y - ymin ); } void tp_pa( double x, double y ) { double tpx, tpy; tp_conv( x, y, &tpx, &tpy ); fprintf(fp_tpic,"\\special{pa %.0f %.0f}%%\n",tpx, tpy); } void tp_line( double x1, double y1, double x2, double y2, char *fmt ) { tp_pa( x1, y1 ); tp_pa( x2, y2 ); fprintf(fp_tpic,"\\special{%s}%%\n", fmt ); } void tp_func( double *x, double *y, int imin, int imax, char *fmt ) { int i; for( i=imin; i<=imax; i++ ) tp_pa( x[i], y[i] ); fprintf(fp_tpic,"\\special{%s}%%\n", fmt ); } void tp_func_color( double *x, double *y, int imin, int imax, char *fmt, double r, double g, double b ) { int i; for( i=imin; i<=imax; i++ ) tp_pa( x[i], y[i] ); fprintf(fp_tpic,"\\textcolor[rgb]{%f,%f,%f}{%%\n", r, g, b ); fprintf(fp_tpic,"\\special{%s}%%\n", fmt ); fprintf(fp_tpic,"}%%\n" ); } void tp_func_ncolor( double *x, double *y, int imin, int imax, char *fmt, char *color ) { int i; for( i=imin; i<=imax; i++ ) tp_pa( x[i], y[i] ); fprintf(fp_tpic,"\\textcolor[named]{%s}{%%\n", color ); fprintf(fp_tpic,"\\special{%s}%%\n", fmt ); fprintf(fp_tpic,"}%%\n" ); }