Advertisement
szymcio93

townini 11.11.11.11

Jan 6th, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. 11111111111111
  2.  
  3. function [ xprim ] = rlc( t,x )
  4.  
  5. w=1;
  6. R1=0.02;
  7. R2=0.5;
  8. C=0.01;
  9. L1=1;
  10. L2=1.5;
  11. M=1;
  12.  
  13. D=M/(L1*L2-M^2);
  14.  
  15. A = [-R1*L2*D/M R2*L2*D/L2 -L2*D/M
  16. R1*D -R2*L1*D/M D
  17. 1/C 0 0];
  18.  
  19. B = [L2*D/M
  20. -D
  21. 0];
  22.  
  23. % e = sin(w*t);
  24. % if t<0
  25. % e=0;
  26. % else
  27. % e=1;
  28. % end
  29. if t==10
  30. e=1/100;
  31. else
  32. e=0;
  33. end
  34. % if t==0 || t==1 || t==2 || t==3 || t==4 || t==5 || t==6 || t==7 || t==8 || t==9 || t==10 || t==11 || t==12
  35. % e=1;
  36. % else
  37. % e=0;
  38. % end
  39. % e=sin(t)+sin(2*t)+sin(5*t);
  40. xprim = A*x + B.*e;
  41. end
  42.  
  43. //////for i=1:3
  44. for k=4:length(e)-4;
  45. xprim(i,k-3)=(1/25)*(48*xprim(i,k))-36*xprim(i,k-1)+16*xprim(i,k-2)-3*xprim(i,k-3)+12*dt*f(i,k+1);
  46. end
  47. end
  48.  
  49. --------------------------------------------------------
  50. 2222222222222
  51.  
  52. clear all;
  53. close all;
  54. dt=0.001;
  55. xx(:,1)=[0 ; 0 ; 0];
  56. % for i=1:24000
  57. % xx(:,i+1)=xx(:,i)+dt*rlc(0.001*i,xx(:,i));
  58. % end
  59. % plot(xx(1,:))
  60.  
  61. dt=0.001;
  62. % xx=zeros(3,1);
  63. [tt,tty]=ode45(@rlc,[0:0.001:24],xx(:,1));
  64. figure, plot(tt,tty(:,1));
  65. figure, plot(tt,tty(:,2));
  66. figure, plot(tt,tty(:,3));
  67. % %
  68. % tty=tty';
  69. xx(:,2)=tty(2,:);
  70. xx(:,3)=tty(3,:);
  71. xx(:,4)=tty(4,:);
  72. for k=4:(24/dt)
  73. xx(:,k+1) = 1/25 * (48*xx(:,k) -36*xx(:,k-1) + 16*xx(:,k-2) - 3*xx(:,k-3) + 12*dt*rlc((k+1)*dt, xx(:,k)));
  74. xx(:,k+1) = 1/25 * (48*xx(:,k) -36*xx(:,k-1) + 16*xx(:,k-2) - 3*xx(:,k-3) + 12*dt*rlc((k+1)*dt, xx(:,k+1)));
  75. end
  76. % hold on;
  77. % t=linspace(0,24,24/dt);
  78. % % % tty=tty';
  79. figure
  80. hold on
  81. plot(tt, xx(1,:), 'r');
  82. plot(tt, tty(:,1), 'g');
  83. figure, plot(tt, tty(:,1)-xx(1,:)');
  84. hold off;
  85. figure
  86. hold on
  87. plot(tt, xx(2,:), 'r');
  88. plot(tt, tty(:,2), 'g');
  89. figure, plot(tt, tty(:,2)-xx(2,:)');
  90. hold off;
  91. figure
  92. hold on
  93. plot(tt, xx(3,:), 'r');
  94. plot(tt, tty(:,3), 'g');
  95. figure, plot(tt, tty(:,3)-xx(3,:)');
  96. hold off;
  97.  
  98. [max(abs(tty(:,1)-xx(1,:)')) max(abs(tty(:,1)-xx(1,:)'))/max(abs(tty(:,1)))]
  99. [max(abs(tty(:,2)-xx(2,:)')) max(abs(tty(:,2)-xx(2,:)'))/max(abs(tty(:,2)))]
  100. [max(abs(tty(:,3)-xx(3,:)')) max(abs(tty(:,3)-xx(3,:)'))/max(abs(tty(:,3)))]
  101. % % % plot(t,tty(1,:), '.-r');
  102. % % % plot(t,tty(2,:), '.-g');
  103. % % % figure, plot(t,xx(3,:))
  104. % % % figure, ode45('rlc', 24, [0, 0, 0]');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement