Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. % TO MUSI BYC DOBRZE I CHUJ
  2.  
  3.  
  4. R1 = 100;
  5. R2 = 100;
  6. C1 = 100e-6;
  7. C2 = 220e-6
  8. L = 1e-3;
  9.  
  10. E = [R1*C1 0 L;0 R2*C2 L;C1 C2 0];
  11. A1 = [-1 0 0; 0 -1 0; 0 0 1];
  12. B1 = [1 0;0 1; 0 0];
  13. A=inv(E)*A1;
  14. B=inv(E)*B1;
  15.  
  16.  
  17. e1='5*sin(2*pi*50*t)'; %5 zamiast 10
  18. e2='20*sin(2*pi*50*t)';
  19.  
  20. x0=0;
  21. dt=1e-5;
  22. t=1e-1;
  23.  
  24. tic
  25. function sym_stanE2(A,B,fw1,fw2,dt,t,x0)
  26. maxit=t/dt;
  27.  
  28. x=x0;
  29.  
  30. [m,n]=size(A);
  31. I=eye(m,m);
  32.  
  33. f1=inline(fw1);
  34. f2=inline(fw2);
  35.  
  36. for i=1:maxit
  37. u1=feval(f1,i*dt);
  38. u2=feval(f2,i*dt);
  39. u=[u1;u2];
  40. x=(I+dt*A)*x+dt*B*u;
  41.  
  42. xw1(i) = x(1);
  43. xw2(i) = x(2);
  44. xw3(i) = x(3);
  45. tw(i) = i*dt;
  46. end;
  47.  
  48. figure;
  49. hold on;
  50. plot(tw, xw1, 'r')
  51. plot(tw, xw2, 'g')
  52. plot(tw, xw3, 'b')
  53. xlabel('t[s]')
  54. ylabel('U[V], I[A]')
  55. legend('U1', 'U2', 'I')
  56. hold off;
  57.  
  58. end;
  59. toc
  60.  
  61. tic
  62. function sym_stanE1(A,B,fw1,fw2,dt,t,x0)
  63. maxit=t/dt;
  64.  
  65. x=x0;
  66.  
  67. [m,n]=size(A);
  68. I=eye(m,m);
  69.  
  70. f1=inline(fw1);
  71. f2=inline(fw2);
  72.  
  73. for i=1:maxit
  74. u1=feval(f1,i*dt);
  75. u2=feval(f2,i*dt);
  76. u=[u1;u2];
  77. x=inv(I-dt*A)*(x+dt*B*u);
  78.  
  79. xw1(i) = x(1);
  80. xw2(i) = x(2);
  81. xw3(i) = x(3);
  82. tw(i) = i*dt;
  83. end;
  84.  
  85. figure;
  86. hold on;
  87. plot(tw, xw1, 'r')
  88. plot(tw, xw2, 'g')
  89. plot(tw, xw3, 'b')
  90. xlabel('t[s]')
  91. ylabel('U[V], I[A]')
  92. legend('U1', 'U2', 'I3')
  93. hold off;
  94.  
  95. end;
  96. toc
  97.  
  98. sym_stanE2(A,B,e1,e2,dt,t,x0)
  99.  
  100. sym_stanE1(A,B,e1,e2,dt,t,x0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement