Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. %-------------------------------------
  2. %Homework 4
  3. %Greenwood Problem 4.2
  4. %Henry Lam
  5. %-------------------------------------
  6.  
  7. global A1 A2
  8. %Given value of circuit elements
  9. L=0.12; %Henry
  10. C=32e-6; %Farads
  11. R=92; %Ohm
  12.  
  13. t0=0; %define the initial time
  14. tf=15e-3; %define the final time
  15. nsteps=500; %number of steps from t0 to tf)
  16. hsteps=(tf-t0)/nsteps;
  17. tspan=t0:hsteps:tf;
  18.  
  19. A1=[0 -1/C;1/L 0]; %When only S1 is closed.
  20. A2=[-1/(R*C) -1/C;1/L 0]; %When S2 is closed while S1 is already closed.
  21.  
  22. disp('Eigenvalue of A1 are:')
  23. lambda1=eig(A1);
  24. disp('Eigenvalue of A2 are:')
  25. lambda2=eig(A2);
  26.  
  27. x0=[40e3 0.0]; % initial conditions
  28. [t,x]=ode23('hw4_gw42',tspan,x0);
  29.  
  30. subplot(2,1,1)
  31. plot(t,x(:,1),'Linewidth',1.5), grid on
  32. title('When S1 is closed, S2 is open');
  33. xlabel('time(sec)')
  34. ylabel('Vc(Volts)')
  35.  
  36. subplot(2,1,2)
  37. plot(t,x(:,2),'Linewidth',1.5), grid on
  38. title('When S1 and S2 are closed');
  39. xlabel('time(sec)')
  40. ylabel('iL(amps)')
  41. The switch S1 closed first then 5ms later switch S2 close
  42. function xdot=hw4_gw42(t,x)
  43. global A1 A2
  44. %state variables;
  45. %x(1)=Vc, x(2)=iL
  46. xdot=zeros(2,1);
  47. if(t<5e-3)
  48. xdot=A1*x; %state space equation when S1 is closed.
  49. else
  50. xdot=A2*x; %state space equation when S1 and S2 are closed.
  51. End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement