$ ls -l $ ls -l -a $ ls -la $ ls -F $ ls <dirname> <dirname> $ cd <dirname> <dirname> $ cd $ pwd $ cat <filename> <filename> $ less <filename> <filena

Similar documents
j x j j j + 1 l j l j = x j+1 x j, n x n x 1 = n 1 l j j=1 H j j + 1 l j l j E

$ pwd /home1/t0/t0903 / / /home1/t0/t0903 / / /home1/t0/t0903 / /... ~ $ ls $ ls -a

#include <stdio.h> 2 #include <stdlib.h> 3 #include <GL/glut.h> 4 Program 1 (OpenGL GameSample001) 5 // 6 static bool KeyUpON = false; // 7 sta

第3章 OpenGL の基礎

演算増幅器

1 1. Program 1 OpenCV (OpenCV Sample001) 1 /* 2 - > - > - >VC++ 3 ( ) 4 C:\opencv\build\include 5 ( ) 6 C:\opencv\build\x86\vc10\lib 7 - > - > - > - >

3D グラフィックス処理の一般過程 1. 3D グラフィックス処理の一般過程

/*p7-1-1*/

( ) 1 1: 1 #include <s t d i o. h> 2 #include <GL/ g l u t. h> 3 #include <math. h> 4 #include <s t d l i b. h> 5 #include <time. h>

第3章 OpenGL の基礎

謗域・ュ逕ィppt

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裵²ó ¨¡ À©¸æ¹½Â¤¡§¾ò·ïʬ´ô ¨¡

libaux.dvi

超初心者用

2 : 2008/12/ /01/ G :

2 2 GLUI 2 GLUI 2.1 GLUI GLUI OpenGL OpenGL glut OpenGL glut C++ Linux, Windows (Visual C++, gcc), Macintosh glut glut GUI glut GUI CG glmultmatrix()

演算増幅器

‚æ4›ñ

2 3 OpenGL 2 OpenGL OpenGL(Open Graphics Library) Silicon Graphics (SGI) 3D OpenGL SGI HP, SUN, IBM UNIX Linux, FreeBSD PC UNIX Windows, Mac OS API PD

XMPによる並列化実装2

1) OOP 2) ( ) 3.2) printf Number3-2.cpp #include <stdio.h> class Number Number(); // ~Number(); // void setnumber(float n); float getnumber();

C B

x h = (b a)/n [x i, x i+1 ] = [a+i h, a+ (i + 1) h] A(x i ) A(x i ) = h 2 {f(x i) + f(x i+1 ) = h {f(a + i h) + f(a + (i + 1) h), (2) 2 a b n A(x i )

Microsoft Word - C.....u.K...doc

2 2 2 OpenGL (R,G,B,A) 2.1 OpenGL (x y) width height pixels void glreadpixels(glint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum t

2 T ax 2 + 2bxy + cy 2 + dx + ey + f = 0 a + b + c > 0 a, b, c A xy ( ) ( ) ( ) ( ) u = u 0 + a cos θ, v = v 0 + b sin θ 0 θ 2π u = u 0 ± a

I. Backus-Naur BNF : N N 0 N N N N N N 0, 1 BNF N N 0 11 (parse tree) 11 (1) (2) (3) (4) II. 0(0 101)* (

I. Backus-Naur BNF S + S S * S S x S +, *, x BNF S (parse tree) : * x + x x S * S x + S S S x x (1) * x x * x (2) * + x x x (3) + x * x + x x (4) * *

準備 計算結果を可視化するために OpenGL を 利用する. 2

C

2 2 OpenGL ( ) OpenGL ( ) glclearcolor(glclampf red, GLclampf green, GLclampf

A/B (2018/10/19) Ver kurino/2018/soft/soft.html A/B

:30 12:00 I. I VI II. III. IV. a d V. VI

新・明解C言語 ポインタ完全攻略

comment.dvi

新版明解C言語 実践編

:30 12:00 I. I VI II. III. IV. a d V. VI

II ( ) prog8-1.c s1542h017%./prog8-1 1 => 35 Hiroshi 2 => 23 Koji 3 => 67 Satoshi 4 => 87 Junko 5 => 64 Ichiro 6 => 89 Mari 7 => 73 D

/* drawing function */ function_graph();// drawing graph glflush(); int main(int argc, char **argv ) glutinit( &argc, argv ); glutinitdisplaymode( GLU

/* do-while */ #include <stdio.h> #include <math.h> int main(void) double val1, val2, arith_mean, geo_mean; printf( \n ); do printf( ); scanf( %lf, &v

double float

18 C ( ) hello world.c 1 #include <stdio.h> 2 3 main() 4 { 5 printf("hello World\n"); 6 } [ ] [ ] #include <stdio.h> % cc hello_world.c %./a.o

Microsoft Word - Cプログラミング演習(12)

programmingII2019-v01

[1] #include<stdio.h> main() { printf("hello, world."); return 0; } (G1) int long int float ± ±

2 2 OpenGL OpenGL OpenGL(Open Graphics Library) Silicon Graphics (SGI) 3D OpenGL SGI HP, SUN,

ex01.dvi

Microsoft PowerPoint - program.ppt [互換モード]

‚æ2›ñ C„¾„ê‡Ìš|

1 OpenGL OpenGL OpenGL OpenGL

C による数値計算法入門 ( 第 2 版 ) 新装版 サンプルページ この本の定価 判型などは, 以下の URL からご覧いただけます. このサンプルページの内容は, 新装版 1 刷発行時のものです.

1.ppt

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裶²ó ¨¡ À©¸æ¹½Â¤¡§·«¤êÊÖ¤· ¨¡

Informatics 2010.key

Informatics 2014

C 2 / 21 1 y = x 1.1 lagrange.c 1 / Laglange / 2 #include <stdio.h> 3 #include <math.h> 4 int main() 5 { 6 float x[10], y[10]; 7 float xx, pn, p; 8 in

II 3 yacc (2) 2005 : Yacc 0 ~nakai/ipp2 1 C main main 1 NULL NULL for 2 (a) Yacc 2 (b) 2 3 y

slide5.pptx

273? C

kiso2-09.key

: CR (0x0d) LF (0x0a) line separator CR Mac LF UNIX CR+LF MS-DOS WINDOWS Japan Advanced Institute of Science and Technology

tuat1.dvi

PC Windows 95, Windows 98, Windows NT, Windows 2000, MS-DOS, UNIX CPU

PowerPoint プレゼンテーション

第5回お試しアカウント付き並列プログラミング講習会

新・明解C言語 実践編

untitled

1 4 2 EP) (EP) (EP)

C¥×¥í¥°¥é¥ß¥ó¥° ÆþÌç

卒 業 研 究 報 告.PDF

I ASCII ( ) NUL 16 DLE SP P p 1 SOH 17 DC1! 1 A Q a q STX 2 18 DC2 " 2 B R b

untitled

P05.ppt

ex01.dvi

実際の株価データを用いたオプション料の計算

PowerPoint Presentation

44 6 MPI 4 : #LIB=-lmpich -lm 5 : LIB=-lmpi -lm 7 : mpi1: mpi1.c 8 : $(CC) -o mpi1 mpi1.c $(LIB) 9 : 10 : clean: 11 : -$(DEL) mpi1 make mpi1 1 % mpiru


pptx

#define N1 N+1 double x[n1] =.5, 1., 2.; double hokan[n1] = 1.65, 2.72, 7.39 ; double xx[]=.2,.4,.6,.8,1.2,1.4,1.6,1.8; double lagrng(double xx); main

(search: ) [1] ( ) 2 (linear search) (sequential search) 1

Original : Hello World! (0x0xbfab85e0) Copy : Hello World! (0x0x804a050) fgets mstrcpy malloc mstrcpy (main ) mstrcpy malloc free fgets stream 1 ( \n

£Ã¥×¥í¥°¥é¥ß¥ó¥°(2018) - Âè11²ó – ½ÉÂꣲ¤Î²òÀ⡤±é½¬£² –

2 P.S.P.T. P.S.P.T. wiki 26

5. p.1/37

Krylov (b) x k+1 := x k + α k p k (c) r k+1 := r k α k Ap k ( := b Ax k+1 ) (d) β k := r k r k 2 2 (e) : r k 2 / r 0 2 < ε R (f) p k+1 :=

9 8 7 (x-1.0)*(x-1.0) *(x-1.0) (a) f(a) (b) f(a) Figure 1: f(a) a =1.0 (1) a 1.0 f(1.0)

導入基礎演習.ppt


r07.dvi

ohp07.dvi

21 B92 B92 Quantum cryptography simulator

BW BW

lexex.dvi

K227 Java 2

Informatics 2015

I J

1 return main() { main main C 1 戻り値の型 関数名 引数 関数ブロックをあらわす中括弧 main() 関数の定義 int main(void){ printf("hello World!!\n"); return 0; 戻り値 1: main() 2.2 C main

AutoTuned-RB

untitled

Transcription:

$ pwd /home1/t0/t0903 / / /home1/t0/t0903 / / /home1/t0/t0903 / /... ~ $ ls $ ls -a

$ ls -l $ ls -l -a $ ls -la $ ls -F $ ls <dirname> <dirname> $ cd <dirname> <dirname> $ cd $ pwd $ cat <filename> <filename> $ less <filename> <filename> less $ man <cmdname> <cmdname> $ mkdir <dirname> <dirname>

nrps ~ nrps ~/nrps $ cd ~/nrps nrps hello.c.c ~/nrps hello.c /* This is my first C program. */ #include<stdio.h> #define MYNAME "abcdefg" int main() { printf("hello World!!\n"); printf("my name is %s.\n",myname); return(0); }

hello.c hello.c ~/nrps $ cd ~/nrps nrps $ ls-a $ gcc hello.c -o hello.out -lm hello.c hello.out hello.out aaa.out aaa.out $ ls hello.out $./hello.out hello.c gcc... c ~/nrps

$ cd ~/nrps $ chmod +x c $ cd ~/nrps $./c hello hello.c hello.out ~/nrps ~/nrps $ cd~/nrps cd $ ls -a $ rm -r <file name> $ ls -a

main2d.c ~/nrps main2d.c $ cd ~/nrps $./c main2d $./main2d.out 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <GL/glut.h> 4 5 #define WIDTH 300 6 #define HIGHT 300 7 8 void display(void); 9 void reshape(int w, int h); 10 void keyboard(unsigned char key, int x, int y); 11 void ginit(int* pargc, char** argv); 12 13 void display(void) 14 { 15 int i, j; 16 17 glclear(gl_color_buffer_bit); 18 glpointsize(1);

19 glbegin(gl_points); 20 glcolor3f(1.0,0.0,0.0); /* red */ 21 glvertex2f(1,1); 22 glcolor3f(0.0,1.0,0.0); /* green */ 23 glvertex2f(2,2); 24 glcolor3f(0.0,0.0,1.0); /* blue */ 25 glvertex2f(3,3); 26 27 glend(); 28 glutswapbuffers(); 29 } 30 31 void reshape(int w, int h) 32 { 33 glviewport(0, 0, (GLsizei)w, (GLsizei)h ); 34 glmatrixmode(gl_projection); 35 glloadidentity(); 36 gluortho2d(0.0, (GLdouble)w, 0.0, (GLdouble) h); 37 } 38 39 void keyboard(unsigned char key, int x, int y) 40 { 41 switch(key) { 42 case 'q': 43 case 'Q': 44 exit(0); 45 break; 46 case ' ': 47 glutidlefunc(0); 48 break; 49 default: 50 break; 51 } 52 }

53 54 void ginit(int* pargc, char** argv) 55 { 56 glutinit(pargc,argv); 57 glutinitdisplaymode(glut_double GLUT_RGB); 58 glutinitwindowsize(width,hight); 59 glutinitwindowposition(100,50); 60 glutcreatewindow("numerical Recipes for Polymer Science"); 61 glclearcolor(0.0,0.0,0.0,0.0); /* background color */ 62 glshademodel(gl_flat); 63 glutdisplayfunc(display); 64 glutreshapefunc(reshape); 65 glutkeyboardfunc(keyboard); 66 } 67 68 int main(int argc, char* argv[]) 69 { 70 ginit(&argc,argv); 71 glutmainloop(); 72 return 0; 73 } WIDTH HIGHT WIDTH 300 reshape void int

display glutdisplayfunc(display) display i j display() 1 glbegin() glend() glbegin(gl_points) glbegin(gl_lines) glbegin(gl_line_strip) glbegin(gl_line_loop) glbegin(gl_triangles / GL_QUADS) glbegin(gl_trianble_strip / GL_QUAD_STRIPE) glbegin(gl_triangle_fan) glbegin(gl_polygon) glcolor3f() glvertex2f(float x, float y) (x, y) glutswapbuffers() reshape(int w, int h) glutreshapefunc() glutkeyboardfunc()

ginit(int* pargc, char** argv) main() main() { } #include.c ;

#include <stdio.h> int main() { printf("hello World!\n"); return(0); } #include <stdio.h> int main(){printf("hello World!\n");return(0);} main() #include <stdio.h> int mai n(){printf("hello World!\n");return(0);} ; : {} () [] <> #include '' "" / % { } _ _

+ a = b+c; b c a - a = b-c; b c a * a = b*c; b c a / a = b/c; b c a % a = b%c; b c a ++ a++; ++a; a = a + 1; -- a--; --a; a = a - 1; - b = -a;

= a = b += a += b; a = a + b; -= a -= b; a = a - b; *= a *= b; a = a*b; /= a /= b; a = a/b; %= a %= b; a = a%b; > < >= <= ==!= a = (b > c); c b a a a = ( b!= c); b c a a a = (b > c) && (c < d); b>c c<d a a = (b > c) (c < d); b>c c<d a &&!

a =!(b > c); b>c a if for while 1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int main() 5 { 6 int num,i; 7 8 for(i=0;i<4;i++){ 9 num = rand()%2000; 10 11 if(num < 100){ 12 printf("%d < 100\n", num); 13 }else if(num > 1000){ 14 printf("%d > 1000\n", num); 15 }else{ 16 printf("100 <= %d <= 1000\n",num); 17 } 18 19 if(num < 100)printf("The num is smaller than 100\n"); 20 21 } 22 23 i=0;

24 while(i < 5){ 25 num = rand()%2000; 26 printf("num = %d\n",num); 27 i++; 28 } 29 30 do{ 31 num = rand()%2000; 32 printf("in do_while, num = %d\n",num); 33 i--; 34 }while(i>0); 35 36 return(0); 37 } 38.c 1 #include <stdio.h>

2 #include <stdlib.h> 3 4 double f2bai(double x); 5 double tasu(double x, double y); 6 7 double f2bai(double x) 8 { 9 printf("f2bai works.\n"); 10 11 return(2.0*x); 12 } 13 14 double tasu(double x, double y) 15 { 16 return(x+y); 17 } 18 19 int main() 20 { 21 double a,b; 22 23 a = (rand()%1000)/1000.0; 24 b = (rand()%1000)/1000.0; 25 26 printf("2*%lf = %lf\n", a, f2bai(a)); 27 printf("%lf + %lf = %lf\n", a, b, tasu(a,b)); 28 29 return(0); 30 } ~/nrps

$ pwd main2d.c hexagon.c $ cp main2d.c hexagon.c 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <GL/glut.h> * 4 #include <math.h> 5 6 #define WIDTH 300 7 #define HIGHT 300 * 8 #define RADIUS 100 * 9 #define X0 150 *10 #define Y0 150 11 17 void display(void) 18 { *19 int x, y, deg; 20 21 glclear(gl_color_buffer_bit); 22 glpointsize(1); *23 glbegin(gl_line_loop); *24 glcolor3f(1.0, 1.0, 0.0); /* yellow */ *25 for(deg = 0; deg < 360; deg = deg+60){ *26 x = RADIUS*cos(deg*M_PI/180); *27 y = RADIUS*sin(deg*M_PI/180); *28 glvertex2f(x0+x,y0+y); *29 }

30 glend(); 31 glutswapbuffers(); 32 } hexagon.c math.h RADIUS X0 Y0 display() hexagon.c hexagon.c 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <GL/glut.h> 4 #include <math.h> * 5 #include <time.h> 6 7 #define WIDTH 300 8 #define HIGHT 300 9 #define RADIUS 100 10 #define X0 150 11 #define Y0 150 *12 #define DEGSTEP 10 13 14 void display(void); 15 void reshape(int w, int h); 16 void keyboard(unsigned char key, int x, int y); 17 void ginit(int* pargc, char** argv);

*18 void idle(void); 19 *20 int Degshift=0; 21 *22 void idle(void) *23 { *24 static int first = 1; *25 static time_t past; *26 time_t now; *27 *28 if(first == 1){ *29 time(&past); *30 first = 0; *31 return; *32 } *33 *34 time(&now); *35 *36 if(difftime(now,past) > 1.0){ *37 Degshift += DEGSTEP; *38 past = now; *39 } *40 *41 glutpostredisplay(); *42 } 43 44 void display(void) 45 { 46 int x, y, deg; 47 48 glclear(gl_color_buffer_bit); 49 glpointsize(1); 50 glbegin(gl_polygon); 51 glcolor3f(1.0, 1.0, 0.0); /* yellow */

52 for(deg = 0; deg < 360; deg = deg+60){ *53 x = RADIUS*cos((deg+Degshift)*M_PI/180); *54 y = RADIUS*sin((deg+Degshift)*M_PI/180); 55 glvertex2f(x0+x,y0+y); 56 } 57 glend(); 58 glutswapbuffers(); 59 } 60 61 void reshape(int w, int h) 62 { 63 glviewport(0, 0, (GLsizei)w, (GLsizei)h ); 64 glmatrixmode(gl_projection); 65 glloadidentity(); 66 gluortho2d(0.0, (GLdouble)w, 0.0, (GLdouble) h); 67 } 68 69 void keyboard(unsigned char key, int x, int y) 70 { 71 switch(key) { 72 case 'q': 73 case 'Q': 74 exit(0); 75 default: 76 break; 77 } 78 } 79 80 void ginit(int* pargc, char** argv) 81 { 82 glutinit(pargc,argv); 83 glutinitdisplaymode(glut_double GLUT_RGB); 84 glutinitwindowsize(width,hight); 85 glutinitwindowposition(100,50);

86 glutcreatewindow("numerical Recipes for Polymer Science"); 87 glclearcolor(0.0,0.0,0.0,0.0); /* background color */ 88 glshademodel(gl_flat); 89 glutdisplayfunc(display); 90 glutreshapefunc(reshape); 91 glutkeyboardfunc(keyboard); *92 glutidlefunc(idle); 93 } 94 95 int main(int argc, char* argv[]) 96 { 97 ginit(&argc,argv); 98 glutmainloop(); 99 return 0; 100 } 101 rothex.c time() time.h.h DEGSTEP idle(void) Degshift

glutidlefunc() 1 0 first static static time.h time_t now past now past time(&past) first return if time(&now) now difftime(now,past) now past Degshift DEGDTEP now past idle(void)

8 9 7 6 4 2 3 5 1 j x j j j + 1 l j l j = x j+1 x j, n x n x 1 = n 1 l j j=1 H j j + 1 l j l j E a n 1 H = ae l j, j=1

l j = x j+1 x j, x n x 1 = n 1 j=1 l j, l j = ±l (l > 0) n 1 H = ϵ l j, j=1 ϵ e x x = 0 e x = j=0 x j j! = 1 + x + 1 2 x2 + 1 6 x3 + + 1 j! xj +, 0! = 1 x = 1 e = 1 + 1 + 1 2 + 1 6 + + 1 j! + = j=0 1 j!, e = n j=0 1 j!. n 1 15 n

T j H j j Ψ j k Ψ j = 1 ( Z H ) j, k T Z = j ( H ) j, k T j T a b P a b ( H ) ( a P ab = H ) b P ba, k T k T

N N H 3N r N = (r 1, r 2, r N ) 3N p N = (p 1, p 2, p N ) H = N j=1 p 2 j 2m + U(r 1, r 2,, r N ), U r j = (x j, y j, z j ) p j = (p xj, p yj, p zj ) x j y j z j j x y z p xj p yj p zj p N r N r N = (r 1, r 2,, r N ) p N = (p 1, p 2,, p N ) r + r N = (r 1 + r 1, r 2 + r 2,, r N + r N ) p + p N = (p 1 + p 1, p 2 + p 2,, p N + p N ) ( H ) r N p N k T ( H ) k T Q r N Q < Q > ( Q ( Q H ) r N p N k < Q >= T ( H ) = r N p N k T U ) r N k T ), r N ( U k T N r N k t k t t m N 1 a x a y b z b

x a x a + δ x (1 2ξ 1 ), y a y a + δ y (1 2ξ 2 ), z a z a + δ z (1 2ξ 3 ). δ x, δ y, δ z x y z ξ j [0, 1] 8δ x δ y δ z t m t m t U t m U m U t U m k + 1 m U t < U m m [0, 1] η ( η < U ) m U t k T m k + 1 ( η > U ) m U t k T t k + 1 N l j = ±1 0

t m N l j 1 k t t m 1 n 1 a l a +1 1 l a +1 1 1 +1 l a 1 t m m t H t m H m H t H m k + 1 m H t < H m [0, 1] η m k + 1 ( η < H ) m H t k T ( η > H ) m H t k T t k + 1

1 #include <stdio.h> 2 #include <stdlib.h> 3 4 #define N (20) 5 6 double uran(){ 7 return((double)rand()/rand_max); 8 } 9 10 int main() 11 { 12 float rn[n]; 13 int l[n]; 14 int j; 15 16 for(j=0;j<n;j++){ 17 rn[j] = uran(); 18 if(rn[j] < 0.5){ 19 l[j] = -1; 20 }else{ 21 l[j] = 1; 22 } 23 24 printf("%f,%2d\n",rn[j],l[j]); 25 } 26 return(0); 27 } 28

H ϵ = 6.0 10 22 k = 1.380662 23 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <math.h> 4 5 #define N (100) 6 #define EP (6.0e-22) /* [J] */ 7 #define KB (1.380662e-23) /* The Botzmann's constant [J/K] */ 8 #define MCTIME (1000) 9 10 double uran(){ 11 return((double)rand()/rand_max); 12 } 13 14 int main() 15 { 16 int l[n],p[n+1]; 17 int k,j,mct,lbefore,end; 18 float dene,t; 19 FILE *fp; 20 21 printf("temperature ="); 22 scanf("%f",&t); 23 printf("\n"); 24 25 for(j=0;j<n;j++){ 26 l[j] = 1; 27 } 28 29 for(j=0;j<n+1; j++){ 30 p[j] = 0;

31 } 32 33 for(mct=0;mct<mctime;mct++){ 34 for(k=0;k<n;k++){ 35 j = (N+1)*uran(); 36 lbefore = l[j]; 37 l[j] *= (-1); 38 dene = - EP*l[j] - (-EP*lbefore); 39 if(dene > 0){ 40 if(exp(-dene/(kb*t)) < uran()){ 41 l[j] = lbefore; 42 } 43 } 44 } 45 46 for(j=0,end=0;j<n;j++){ 47 end += l[j]; 48 } 49 p[(end+n)/2]++; 50 51 printf("%d\n",mct); 52 } 53 54 fp = fopen("result.txt","w"); 55 56 for(j=0;j<(n+1);j++){ 57 fprintf(fp,"%d\t%e\n",2*j-n,((float)p[j])/mctime); 58 } 59 60 fclose(fp); 61 62 return(0); 63 } 64

65 result.txt $ mv result.txt 10.txt result.txt 10.txt 100.txt 1000.txt

[0, 1] uran() double j int l[n] [ ]... [ ] p[n+1] [ ]... [ ] lbefor end float dene t FILE fp t for for { }

j 0 l[j] = 1 j j + 1 j j < N l[j] j 0 N p[j] 0 p[j] mct { } mct 1 mct MCTIME N N 1 j 0 N l[j] l[j] 1 1 lbefore l[j] l[j] l[j] 1 1 1 +1 l[j] 1 l[j] l[j] *= (-1); l[j] = l[j]*(-1); l j l j l j H H H H = ϵ(l 0 + + l j + + l N 1 ) ( ϵ)(l 0 + + l j + + l N 1 ) = ϵl j ( ϵl j), dene

dene ( H ) H, k T H H [0, 1] l[j] x l j 1 x = N x = N 2 x 2 x = N, N + 2, N + 4,..., N 4, N 2, N j = (x+n)/2 x = N, N +2, N +4,..., N 4, N 2, N j = 0, 1, 2,..., N 2, N 1, N x = 2j N p[j] 1 p[j] x p[(x 1 x = 2j N result.txt 2j N p[j]/mctime n 1 H = ϵ l xj, j=1

l xj j x rothex.c 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <GL/glut.h> 4 #include <math.h> 5 #include <time.h> 6 7 #define WIDTH 600 8 #define HIGHT 600 9 #define RADIUS 100 10 #define LENGTH 3 11 #define X0 300 12 #define Y0 300 13 #define DEGSTEP 10 14 15 #define N (100) 16 #define EP (6.0e-22) /* [J] */ 17 #define KB (1.380662e-23) /* The Botzmann's constant [J/K] */ 18 #define MCTIME (1000) 19 #define DL (0.5) 20 21 void display(void); 22 void reshape(int w, int h); 23 void keyboard(unsigned char key, int x, int y); 24 void ginit(int* pargc, char** argv); 25 void idle(void); 26 27 int Degshift=0; 28 int Zoom=1,Stop=1; 29 float Ep,T, Lx[N], Ly[N]; 30 31

32 double uran(){ 33 return((double)rand()/rand_max); 34 } 35 36 37 int mcrun() 38 { 39 int j; 40 float dene; 41 float lxbefore, lybefore; 42 float dx, dy, r; 43 44 j = (N-1)*uran()+1; 45 lxbefore = Lx[j]; 46 lybefore = Ly[j]; 47 48 do{ 49 dx = 2.0*DL*(uran()-0.5); 50 dy = 2.0*DL*(uran()-0.5); 51 }while( dx*dx + dy*dy > DL*DL); 52 53 /* 54 Lx[j] = Lx[j] + dx; 55 Ly[j] = Ly[j] + dy; 56 */ 57 58 Lx[j] = dx; 59 Ly[j] = dy; 60 61 r = sqrt(lx[j]*lx[j] + Ly[j]*Ly[j]); 62 Lx[j] = Lx[j]/r; 63 Ly[j] = Ly[j]/r; 64 65 dene = - Ep*Lx[j] - (-Ep*lxbefore);

66 dene = dene*ep; 67 68 if(dene > 0){ 69 if(exp(-dene/(kb*t)) < uran()){ 70 Lx[j] = lxbefore; 71 Ly[j] = lybefore; 72 } 73 } 74 75 return(0); 76 } 77 78 void idle(void) 79 { 80 if(stop == 1)return; 81 mcrun(); 82 glutpostredisplay(); 83 } 84 85 void display(void) 86 { 87 int x, y, j; 88 89 glclear(gl_color_buffer_bit); 90 glpointsize(1); 91 glbegin(gl_line_strip); 92 glcolor3f(1.0, 1.0, 1.0); /* white */ 93 x = 0; 94 y = 0; 95 glvertex2f(x0+x, Y0+y); 96 for(j=1;j<n;j++){ 97 if(j%2 == 0){ 98 glcolor3f(1.0, 1.0, 1.0); 99 }else{

100 glcolor3f(1.0, 1.0, 0.0); 101 } 102 x = x+zoom*length*lx[j]; 103 y = y+zoom*length*ly[j]; 104 glvertex2f(x0+x, Y0+y); 105 } 106 107 glend(); 108 glutswapbuffers(); 109 } 110 111 void reshape(int w, int h) 112 { 113 glviewport(0, 0, (GLsizei)w, (GLsizei)h ); 114 glmatrixmode(gl_projection); 115 glloadidentity(); 116 gluortho2d(0.0, (GLdouble)w, 0.0, (GLdouble) h); 117 } 118 119 void keyboard(unsigned char key, int x, int y) 120 { 121 switch(key) { 122 case 's': 123 Stop *= -1; 124 break; 125 case 'i': 126 if(zoom == 0){ 127 Zoom=1; 128 }else{ 129 Zoom *= 2; 130 } 131 break; 132 case 'o': 133 Zoom /= 2;

134 break; 135 case 'e': 136 printf("\nelectric field ="); 137 scanf("%f",&ep); 138 Stop = 1; 139 break; 140 case 't': 141 printf("\ntemperature ="); 142 scanf("%f",&t); 143 Stop = 1; 144 break; 145 case 'q': 146 case 'Q': 147 exit(0); 148 default: 149 break; 150 } 151 } 152 153 void ginit(int* pargc, char** argv) 154 { 155 glutinit(pargc,argv); 156 glutinitdisplaymode(glut_double GLUT_RGB); 157 glutinitwindowsize(width,hight); 158 glutinitwindowposition(100,50); 159 glutcreatewindow("numerical Recipes for Polymer Science"); 160 glclearcolor(0.0,0.0,0.0,0.0); /* background color */ 161 glshademodel(gl_flat); 162 glutdisplayfunc(display); 163 glutreshapefunc(reshape); 164 glutkeyboardfunc(keyboard); 165 glutidlefunc(idle); 166 } 167

168 int main(int argc, char* argv[]) 169 { 170 int j; 171 ginit(&argc,argv); 172 173 printf("temperature ="); 174 scanf("%f",&t); 175 printf("\n"); 176 printf("electric field ="); 177 scanf("%f",&ep); 178 179 for(j=1;j<n;j++){ 180 Lx[j] = 0.0; 181 Ly[j] = 1.0; 182 } 183 184 glutmainloop(); 185 return 0; 186 } 187