run program

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2008
Posts: 1
Reputation: toboto is an unknown quantity at this point 
Solved Threads: 0
toboto toboto is offline Offline
Newbie Poster

run program

 
0
  #1
Jan 23rd, 2008
please somebody run this program
i have problem with #include <graphics.h>
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <graphics.h>
  4. #include <conio.h>
  5.  
  6. Void DrawFunction (int Npoint, double data[], double H) ;/* Display results */
  7.  
  8. Void MakePotential (int Npoint, double x0, double dx, double V0, double v[], double vd[]) ; /*potential*/
  9.  
  10. Void MakePacket (int Npoint, double x0, double dx, double k0, double *norm1, double yr[], double yi[]) ; /*make wavepacket*/
  11.  
  12. Void TimeIntegral (int Npoint, double dx2, double dt, double *norm2, double yr[], double yi[], double yd[], double v[], double a[], double b[]);
  13.  
  14. double a[4] = {0.0, 0.5, 0.5, 1.0};
  15. double b[4] = {1/6.0, 1/3.0, 1/3.0, 1/6.0};
  16. double yr[401],yi[401],yd[401],v[401],vd[401];
  17. double kr[401],ki[401],dyr[401],dyi[401],ykr[401],yki[401];
  18. void main(void)
  19. {
  20. int t, I, itest, Nmax;
  21. double V0, x0, x, dx, dx2, dt, k0, E, norm1, norm2;
  22. int graphriver = DETECT, graphmode;
  23.  
  24. initgraph( &graphriver, &graphmode , “ “);
  25. setviewport(200, 50, 600, 350, 1);
  26. rectangle(0,0,400,300);
  27. dx = 0.02;
  28. Nmax = 400;
  29. dx2 = dx*dx;
  30. dt = dx2/2.0;
  31. x0 = 0.0;
  32. V0 = 400.0;
  33.  
  34. MakePotential (Nmax, x0, dx, V0, v, vd);
  35. DrawFunction (Nmax, vd, 0);
  36. Gotoxy(1,1);
  37. printf(“Input wave number (k0<25) ! “);
  38. scanf(“%1f”, &k0); E=k0*ko;
  39. printf(“ Time Norm”);
  40. norm 1=0;
  41. MakePacket(Nmax, x0, dx, k0, &norm1, yr, yi);
  42. norm2=norm1;
  43. for( t=0; t<=600; t++)
  44. { gotoxy(1,3); printf(“%5d %8.41f”,t, norm2/norm1); printf(“%d \n”,t);
  45.  
  46. TimeIntegral (Nmax, dx2,dt, %norm2, yr,yi,yd,v,a,b);
  47.  
  48. itest=fmod(t,10);
  49. if (itest==0) { clearviewport();
  50. rectangle(0,0,400,300);
  51. setcolor(4); DrawFunction (Nmax,yr,E/V0);
  52. setcolor(1); DrawFunction (Nmax,yr,E/V0);
  53. setcolor(7); DrawFunction (Nmax,yr,E/V0);
  54. DrawFunction (Nmax,vd,0); }
  55. }
  56. printf(“ Calculation ends,if ready, please return key!”);
  57. getche();
  58. closegraph();
  59. } /* -- End of main function -- */
  60.  
  61. void DrawFunction(int Npoint,double data[], double H)
  62. { int n, iy +
  63. moveto(0,250-(data[0]+H)*100);
  64. for( n=0; n<=Npoint-1; n++)
  65. { iy=250-(data[n]+H*100; lineto(n, iy);
  66. }
  67. }
  68.  
  69. void MakePotential (int Npoint,double x0, double dx, double V0,double v[], double vd[])
  70. { int n;
  71. double x;
  72. x=x0 ;
  73. for ( n=0; n<=Npoint-1; n++ )
  74. { if (n<220) vd[n]=0 ;else if (n>230) vd[n]=0;
  75. else vd[n]=1.0;
  76. v[n]=V0*vd[n]; x+=dx; }
  77. }
  78.  
  79. void MakePacket (int Npoint,double x0, double dx, double k0, double *norm1, double yr[], double yi[])
  80. { int n;
  81. double x;
  82. x=x0 ;
  83. for ( n=0; n<=Npoint-1; n++ )
  84. { yr[n]= cos(k0*x}*exp(-(x-2.5)*(x-2.5)*3.0) ;
  85. yi[n]= sin(k0*x}*exp(-(x-2.5)*(x-2.5)*3.0) ;
  86. x+=dx;
  87. *norm1=norm1+yr[n]*yr[n]+yi[n]*yi[n]; }
  88. }
  89.  
  90. void TimeIntegralt (int Npoint,double dx2, double dt, double *norm2, double yr[], double yi[], double yd[], double v[],
  91. double a[], double b[])
  92. { int nx,ij ;
  93. for ( nx=0; nx<=Npoint; nx++ )
  94. { dyr[nx] = 0.0; dyi[nx] = 0.0 ;
  95. kr[nx] = 0.0; ki[nx] = 0.0; }
  96.  
  97. for ( ij=0 ;ij<=3 ;ij++) /* I loop */
  98. {
  99. for ( nx=0; nx<=Npoint; nx++ )
  100. { ykr[nx]= yr[nx] + a[ij]*kr[nx] ;
  101. yki[nx]= yi[nx] + a[ij]*ki[nx] ; }
  102.  
  103. for ( nx=1; nx<=Npoint-1; nx++ )
  104. { kr[nx]=-((yki[nx+1]-2.0*yki[nx]+yki[nx-1])/dx2-v[nx]*yki[nx])*dt;
  105. ki[nx]=-((ykr[nx+1]-2.0*ykr[nx]+ykr[nx-1])/dx2-v[nx]*yki[nx])*dt;
  106. }
  107.  
  108. for ( nx=0; nx<=Npoint; nx++ )
  109. { dyr[nx] = dyr[nx] + b[ij]*kr[nx] ;
  110. dyi[nx] = dyi[nx] + b[ij]*ki[nx] ; }
  111. } /* i-loop end */
  112.  
  113. *norm2=0.0;
  114. for ( nx=0; nx<=Npoint; nx++ )
  115. { yr[nx] = yr[nx] + dyr[nx];
  116. yi[nx] = yi[nx] + dyi[nx];
  117. yd[nx] = yr[nx]*yr[nx]+yi[nx]*yi[nx];
  118. *norm2=*norm2+yd[nx] ;
  119. }
  120. }
Last edited by Ancient Dragon; Jan 23rd, 2008 at 8:07 am. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,878
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 301
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Cenosillicaphobiac

Re: run program

 
0
  #2
Jan 23rd, 2008
i have problem with #include <graphics.h>
This code can only be compiled by the (ancient) Turbo C compiler, so if you try to compile it with something else this error will come up. I'm guessing you're using something newer?

Niek
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC