Advertisement
ayurchyk1998

Untitled

Feb 3rd, 2021
2,095
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 1.89 KB | None | 0 0
  1. clc;
  2. clear;
  3. xdel(winsid());
  4.  
  5. // Initializing variables
  6. h = 0.03;
  7. x = 0.05;
  8. y = 1;
  9. z = 0.01;
  10. xt = 0.1;
  11. yt = 0.2;
  12. zt = 0.3;
  13.  
  14. // Start values equals zero
  15. for a = 1:2000
  16.  x_st = 0;
  17.  y_st = 0;
  18.  z_st = 0;
  19.  xt_st = 0;
  20.  yt_st = 0;
  21.  zt_st = 0;
  22. end
  23.  
  24. // myval equals zero in all dimensions
  25. for i = 1:2000
  26.  for j = 1:3
  27.     myvalue = 0;
  28.  end;
  29. end
  30.  
  31. // Using RK4 method to solve equations for 2000 points
  32. for i = 1:2000
  33.  myvalue(i,1) = y * z;
  34.  myvalue(i,2) = x - y;
  35.  myvalue(i,3) = 1 - x^2;
  36.  
  37.  kx1 = h*(y * z);
  38.  ky1 = h*(x - y);
  39.  kz1 = h*(1 - x^2);
  40.  
  41.  kx2 = h*((y+ky1)/2 * (z+kz1)/2);
  42.  ky2 = h*((x+kx1)/2 - ((y+ky1)/2));
  43.  kz2 = h*(1 - ((x+kx1)^2)/2);
  44.  
  45.  kx3 = h*((y+ky2)/2 * (z+kz2)/2);
  46.  ky3 = h*((x+kx2)/2 - ((y+ky2)/2));
  47.  kz3 = h*(1 - ((x+kx2)^2)/2);
  48.  
  49.  kx4 = h*((y+ky3) * (z+kz3));
  50.  ky4 = h*((x+kx3) - (y+ky3));
  51.  kz4 = h*(1 - ((z+kz3)^2));
  52.  
  53.  xt = (kx1+2*kx2+2*kx3+kx4)/6 + xt;
  54.  yt = (ky1+2*ky2+2*ky3+ky4)/6 + yt;
  55.  zt = (kz1+2*kz2+2*kz3+kz4)/6 + zt;
  56.  
  57.  xt_st(i) = xt;
  58.  yt_st(i) = yt;
  59.  zt_st(i) = zt;
  60.  
  61.  x_st(i) = x;
  62.  y_st(i) = y;
  63.  z_st(i) = z;
  64.  
  65.  x = x + h;
  66.  y = y + h;
  67.  z = z + h;
  68. end;
  69.  
  70. plot(x_st, xt_st, 'g*-');
  71. plot(y_st, yt_st, 'b*-');
  72. plot(z_st, zt_st, 'r*-');
  73. h1 = legend(['X(t)'; 'Y(t)'; 'Z(t)']);
  74. ylabel("t");
  75.  
  76. figure();
  77. param3d(xt_st, yt_st, zt_st);
  78. h1=legend(['X(t) = f(Y(t), Z(t))']);
  79.  
  80. //graphs after compression
  81. minValue = min(xt_st);
  82. maxValue = max(yt_st);
  83. for i = 1:2000
  84.  xt_st(i) = ((xt_st(i)-minValue) * 2)/(maxValue-minValue) - 1;
  85.  yt_st(i) = ((yt_st(i)-minValue) * 2)/(maxValue-minValue) - 1;
  86.  zt_st(i) = ((zt_st(i)-minValue) * 2)/(maxValue-minValue) - 1;
  87.  
  88.  if i < 51
  89.      mprintf("x(t) = %f, y(t) = %f, z(t) = %f\n", xt_st(i), yt_st(i), zt_st(i));
  90.  end;
  91. end
  92. figure();
  93.  
  94. plot(x_st, xt_st,'g*-');
  95. plot(y_st, yt_st,'b*-');
  96. plot(z_st, zt_st,'r*-');
  97. h1=legend(['X(t)'; 'Y(t)'; 'Z(t)']);
  98. ylabel("t");
  99.  
  100. figure();
  101. param3d(xt_st, yt_st, zt_st);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement