Advertisement
Guest User

TP 7 MN - Team Muslim

a guest
Mar 20th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.24 KB | None | 0 0
  1. /********************************************
  2. *********************************************
  3. *********************************************/
  4. /**********desintegration.c******************/
  5. /********************************************
  6. *********************************************
  7. *********************************************/
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <math.h>
  11.  
  12. float f(float N)
  13. {
  14.     float lamda = 8.02;
  15.     return -lamda*N;
  16. }
  17.  
  18. void euler()
  19. {
  20.     float t,N,h;
  21.     t=0.;
  22.     N=10000000000;
  23.     h=0.01;
  24.     FILE *fichier;
  25.     fichier=fopen("desintegration.txt","w+");
  26.     while(t<80)
  27.     {
  28.     t+=h;
  29.     N=N+h*f(N);
  30.     fprintf(fichier,"%f\t%f\n", t,N);
  31.     //printf("%f\t%f\n", t,N);
  32.     }
  33.     fclose(fichier);
  34. }
  35.  
  36. int main()
  37. {
  38.     euler();
  39.     return 0;
  40. }
  41. /********************************************
  42. *********************************************
  43. *********************************************/
  44. /**********pendule.c******************/
  45. /********************************************
  46. *********************************************
  47. *********************************************/
  48. #include <stdio.h>
  49. #include <stdlib.h>
  50. #include <math.h>
  51.  
  52. float f(float N)
  53. {
  54.     float lamda = 8.02;
  55.     return -lamda*N;
  56. }
  57.  
  58. void euler()
  59. {
  60.     float o,w,t,h;
  61.     t=0.;
  62.     o=1.;
  63.     w=0.5;
  64.     h=0.01;
  65.     FILE *fichier;
  66.     fichier=fopen("pendule.txt","w+");
  67.     while(t<50)
  68.     {
  69.     t+=h;
  70.     o+=h*w;
  71.     w+=-h*(9.8/0.2)*o;
  72.     fprintf(fichier,"%f\t%f\t%f\n", t,o,w);
  73.     printf("%f\t%f\t%f\n", t,o,w);
  74.     }
  75.     fclose(fichier);
  76. }
  77.  
  78. int main()
  79. {
  80.     euler();
  81.     return 0;
  82. }
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89. /*autre*/
  90. #include <stdio.h>
  91. #include <stdlib.h>
  92. #include <math.h>
  93.  
  94. float f(float N)
  95. {
  96.     float lamda = 8.02;
  97.     return -lamda*N;
  98. }
  99.  
  100. void rungekutta()
  101. {
  102.     float x0,y0,m1,m2,m3,m4,m,y,x,h,xn;
  103.     x=0.5;
  104.     y=0.5;
  105.     t=0.;
  106.     h=0.01;
  107.     FILE *fichier;
  108.     fichier=fopen("pendule.txt","w+");
  109.     while(t<50)
  110.     {
  111.     m1=f(x0,y0);
  112.     m2=f((x0+h/2.0),(y0+m1*h/2.0));
  113.     m3=f((x0+h/2.0),(y0+m2*h/2.0));
  114.     m4=f((x0+h),(y0+m3*h));
  115.     m=((m1+2*m2+2*m3+m4)/6);
  116.     y=y+m*h;
  117.     x=x+h;
  118.     t+=h;
  119.     fprintf(fichier,"%f\t%f\t%f\n", t,x,y);
  120.     printf("%f\t%f\t%f\n", t,x,y);
  121.     }
  122.     fclose(fichier);
  123. }
  124.  
  125. int main()
  126. {
  127.     rungekutta();
  128.     return 0;
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement