数値計算法レポート2-オイラー

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include "report2.h"
  5.  
  6. int main(){
  7. double x,y,vx,vy;
  8. int i;
  9. FILE *fpdata;
  10. if((fpdata=fopen("euler.dat","w")) == NULL){
  11. printf("error:cannot open file\n");
  12. exit(1);
  13. }
  14.  
  15. for(i=-10;i<=10;i++){
  16. x=min;
  17. y=i*20;
  18. vx=sqrt(Energy/mass)*c;
  19. vy=0;
  20. while(x<=max && y<=max && y>=min && x>=min){
  21. fprintf(fpdata,"%lf %lf ",x,y);
  22. x=x+vx*dt;
  23. y=y+vy*dt;
  24. vx=vx+Z*197/137/mass*x/(pow(x*x+y*y,1.5))*c*c*dt;
  25. vy=vy+Z*197/137/mass*y/(pow(x*x+y*y,1.5))*c*c*dt;
  26. }
  27. }
  28. fclose(fpdata);
  29. }
  30.  
最終更新:2011年06月29日 10:06