Contour plot/Code: Difference between revisions

From Citizendium
Jump to navigation Jump to search
imported>Chris Day
imported>Chris Day
(No difference)

Revision as of 23:59, 1 February 2009

This article is developing and not approved.
Main Article
Discussion
Related Articles  [?]
Bibliography  [?]
External Links  [?]
Citable Version  [?]
Code [?]
 
A collection of code samples relating to the topic of Contour plot.
// ContourPlotExample.jpg
// Example of the code that generates graphic above
//
// In order to complie this example, files 
//ContourPlot/code/ado.cin (function that makes header of the eps file) and
//ContourPlot/code/conto.cin (function which draws a level) should be loaded.

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define DB double
#define DO(x,y) for(x=0;x<y;x++)
#include "conto.cin"
main(){ int j,k,m,n; DB x,y, p,q, t; 
//printf("example for conto (copyleft 2008 by Dmitrii Kouznetsov), contour plot.  
//#define Y(k) (dy*(k-K/2))
//printf("y_0=%6.3f y_K=%6.3f ",Y(0), Y(K));
int M=100,M1=M+1; 
int N=100,N1=N+1;
DB X[M1],Y[N1], f[M1*N1],w[M1*N1]; // w is working array.
char v[M1*N1]; // v is working array
 printf("Output  ContourPlotExample.eps\n");
FILE *o;o=fopen("ContourPlotExample.eps","w");ado(o,0,0,224,224);
// specify the output file name above 
fprintf(o,"112 112 translate\n 10 10 scale\n");


for(m=-10;m<11;m++) {M(m,-10)L(m,10)}
for(n=-10;n<11;n++) {M(  -10,n)L(10,n)} fprintf(o,".006 W 0 0 0 RGB S\n");
DO(m,M1) X[m]=-10+.2*m;
DO(n,N1) Y[n]=-10+.2*n;

fprintf(o,"/adobe-Roman findfont 1 scalefont setfont\n");
for(m=-8;m<0;m+=2) {M(-11.2,m-.3) fprintf(o,"(%1d)s\n",m);}
for(m= 0;m<9;m+=2) {M(-10.7,m-.3) fprintf(o,"(%1d)s\n",m);}

for(m=-8;m<0;m+=4) {M(m-.6,-10.8) fprintf(o,"(%1d)s\n",m);}
for(m= 0;m<9;m+=4) {M(m-.3,-10.8) fprintf(o,"(%1d)s\n",m);}

fprintf(o,"/Times-Italic findfont 1 scalefont setfont\n"); 
M(-10.7,  9.5) fprintf(o,"(y)s\n");
M(  9.6,-10.8) fprintf(o,"(x)s\n");

M(-10,10.4)fprintf(o,"(use conto.cin; copyleft 2008 by Dmitrii Kouznetov)s\n");
//Replace the line above with the title of your graphic, or just
// "comment" that line.
M(-11,0)L(11,0)
M(0,-11)L(0,11) fprintf(o,".01 W 1 0 1 RGB S\n");

DO(m,M1){ x=X[m];
DO(n,N1){ y=Y[n];
	  f[m*N1+n]=sin(M_PI*x/4)*sin(M_PI*y/4);}}
//	specify  your function above

conto(o,f,w,v,X,Y,M,N,(-.1),-.5,.5); fprintf(o,".06 W 1 0 0 RGB S\n");
conto(o,f,w,v,X,Y,M,N,( .1),-.5,.5); fprintf(o,".06 W 0 0 1 RGB S\n");

//M(-10,0)L(-2,0)fprintf(o,".04 W 1 0 1 RGB S\n");
fprintf(o,"showpage\n\%\%\%Trailer"); fclose(o);
//system( "ggv sqrt2a.eps");
 //system("open ContourPlotExample.eps\n");
 //getchar(); system("killall Preview");
}