Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. -------------------- P
  2. k0 = 0.01;
  3. kmax = 2.6;
  4. iterations = 100;
  5. increase = (kmax - k0)/iterations;
  6. W = zeros(iterations, 2);
  7.  
  8. Kp = k0;
  9. for i = 1:iterations
  10. sim('BorLech3_P');
  11. values = simout.data;
  12. time = simout.time;
  13. deviation = mean(simout.data(end-8:end));
  14. error_term = time.*(values - deviation).^2;
  15. Error = trapz(time, error_term);
  16. W(i,1) = Kp;
  17. W(i,2) = Error;
  18. Kp = Kp + increase;
  19. end
  20. f1 = figure;
  21. plot(W(:,1),W(:,2));
  22. Qmin = min(W(:,2));
  23. index = find(W(:,2) == Qmin);
  24. k_opt = W(index, 1);
  25. disp(k_opt);
  26.  
  27. Kp = k_opt;
  28. sim('BorLech3_P');
  29. v = simout.data;
  30. t = simout.time;
  31. f2 = figure;
  32. plot(t, v);
  33.  
  34.  
  35.  
  36. --------------------- PI
  37.  
  38. Ti0 = 0.01;
  39. Timax = 2.6;
  40. iterations = 100;
  41. increase = (Timax - Ti0)/iterations;
  42. W = zeros(iterations, 2);
  43.  
  44. Kp = 2.2;
  45. Ti = Ti0;
  46. for i = 1:iterations
  47. sim('BorLech3_PI');
  48. values = simout.data;
  49. time = simout.time;
  50. deviation = mean(simout.data(end-8:end));
  51. error_term = time.*(values - deviation).^2;
  52. Error = trapz(time, error_term);
  53. W(i,1) = Ti;
  54. W(i,2) = Error;
  55. Ti = Ti + increase;
  56. end
  57. Qmin = min(W(:,2));
  58. index = find(W(:,2) == Qmin);
  59. Ti_opt = W(index, 1);
  60. disp(Ti_opt);
  61.  
  62. Ti = Ti_opt;
  63. sim('BorLech3_PI');
  64. v = simout.data;
  65. t = simout.time;
  66. f1 = figure;
  67. plot(t, v);
  68.  
  69.  
  70. --------------------- PID
  71.  
  72.  
  73. Td0 = 0.01;
  74. Tdmax = 2.6;
  75. iterations = 100;
  76. increase = (Tdmax - Td0)/iterations;
  77. W = zeros(iterations, 2);
  78.  
  79. Kp = 0.3;
  80. Ti = 0.6316;
  81.  
  82. Td = Td0;
  83. for i = 1:iterations
  84. sim('BorLech3_PID');
  85. values = simout.data;
  86. time = simout.time;
  87. deviation = mean(simout.data(end-8:end));
  88. error_term = time.*(values - deviation).^2;
  89. Error = trapz(time, error_term);
  90. W(i,1) = Td;
  91. W(i,2) = Error;
  92. Td = Td + increase;
  93. end
  94. Qmin = min(W(:,2));
  95. index = find(W(:,2) == Qmin);
  96. Td_opt = W(index, 1);
  97. disp(Td_opt);
  98.  
  99. Td = Td_opt;
  100. sim('BorLech3_PID');
  101. v = simout.data;
  102. t = simout.time;
  103. f1 = figure;
  104. plot(t, v);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement