Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <math.h>
  4.  
  5. #define DT 20
  6. #define T DT*1000
  7. #define del 0.2
  8. #define del2 0.2
  9. #define omega1 sqrt(1-del*del)
  10. #define omega2 sqrt(1-del2*del2)
  11. #define Th 2.5
  12. void main(void)
  13. {
  14. FILE *fp;
  15. int i;
  16. \define the initial conditions
  17. double x = 0.1, t = 0.0, h = 1.0 / DT, y = 0.0,x0,y0;
  18.  
  19. fp = fopen("Kai.csv", "w+");
  20. fprintf(fp, "tau, x, x'n");
  21.  
  22.  
  23. for (i = 0; i <= T; i++) {
  24. x0 = x; \ Save the new initial conditions for using when x' reach the boundary
  25. y0 = y;
  26. if (y > Th) {
  27. while (y > Th) {
  28. \Solution for x, x' with initial conditions x0, y0
  29. x = exp(-del*t)*((x0 - 1)*cos(omega1*t) + (1 / omega1)*(y0 + del*(x0 - 1))*sin(omega1*t)) + 1;
  30. y = exp(-del*t)*(y0*cos(omega1*t) - (1 / omega1)*(del*y0 + (x0 - 1))*sin(omega1*t));
  31. fprintf(fp, "%f, %f,%fn", t, x, y);
  32. t = t + h;
  33. }
  34. }
  35. else if (y < -Th) {
  36. while (y < -Th) {
  37. x = exp(-del*t)*((x0 + 1)*cos(omega1*t) + (1 / omega1)*(y0 + del*(x0 + 1))*sin(omega1*t)) - 1;
  38. y = exp(-del*t)*(y0*cos(omega1*t) - (1 / omega1)*(del*y0 + (x0 + 1))*sin(omega1*t));
  39. fprintf(fp, "%f, %f,%fn", t, x, y);
  40. t = t + h;
  41. }
  42. }
  43. else {
  44. while ((y>=-Th) && (y<=Th)) {
  45. x = exp(del2*t)*(x0*cos(omega2*t) + (1 / omega2)*(y0 - del2*x0)*sin(omega2*t));
  46. y = exp(del2*t)*(y0*cos(omega2*t) + (1 / omega2)*(del2*y0 - x0)*sin(omega2*t));
  47. fprintf(fp, "%f, %f,%fn", t, x, y);
  48. t = t + h;
  49. }
  50. }
  51. }
  52. fclose(fp);
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement