Advertisement
Guest User

Lab1

a guest
Jan 16th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. %---------------------------------------
  2. % Fill in your group number.
  3. GroupNumber = 3;
  4. % Fill in your student Name and ID.
  5. Students(1).Name = 'Tyler Young';
  6. Students(1).ID = '260730324';
  7. Students(2).Name = 'Jamie McLeish';
  8. Students(2).ID = '260708573';
  9. %---------------------------------------
  10.  
  11. %-Documentation-
  12. help dirac
  13. doc abs
  14.  
  15. %-Arrays-
  16. dt = 0.01; % timestep of discrete signal in seconds
  17. T = 10; % Final value of the time signal in seconds
  18.  
  19. % This creates an array |t = [0, 0.01, 0.02, 0.03, ..., 9.98, 9.99, 10.0]|.
  20. t = 0:dt:T; % time signal
  21.  
  22. x1 = sin(2*pi*t);
  23.  
  24. x2 = zeros(size(t)); % create a zero signal with the same size as time
  25. x2(t < 5) = t(t < 5); % value is equale to time, but only when time < 5
  26. x2(t >= 5) = -t(t >= 5) + 10; % value is equale to -time+10, but only when time >= 5
  27.  
  28. %-Plotting Signals-
  29. figure;
  30. hold on;
  31. grid on;
  32. plot(t, x1);
  33. plot(t, x2);
  34. title(sprintf('Group %d - Example plot', GroupNumber));
  35. xlabel('Time (seconds)')
  36. ylabel('Signal')
  37. legend('x_1(t)', 'x_2(t)')
  38. hold off;
  39.  
  40. %-Matrices-
  41. A = [8, 1, 6; 3, 5, 7; 4, 9, 2]
  42. det(A)
  43. eig(A)
  44. inv(A)
  45.  
  46. %-Saving/Loading Data-
  47. example = sprintf('A variable generated by groupe <%d>', GroupNumber);
  48. save('Lab01.mat', 'example')
  49. clear example
  50. load('Lab01.mat', 'example')
  51. disp(example)
  52.  
  53. %---Question 1---
  54. t = 0:dt:T; % time signal
  55.  
  56. y1(t >= 0) = 1;
  57.  
  58. y2(t < 5) = 0;
  59. y2(t >= 5) = -1;
  60.  
  61. y3 = zeros(size(t));
  62. y3(t >=0) = 0.1*t(t >= 0);
  63.  
  64. y4 = exp(-t/10);
  65.  
  66. figure;
  67. hold on;
  68. % Fill in your plots command
  69. plot(t, y1);
  70. plot(t, y2);
  71. plot(t, y3);
  72. plot(t, y4);
  73. title(sprintf('Group %d - Question 1 - Signals', GroupNumber));
  74. xlabel('Time (seconds)')
  75. ylabel('Signals')
  76. grid on;
  77. legend('y_1(t)', 'y_2(t)', 'y_3(t)', 'y_4(t)', 'location', 'best')
  78.  
  79. %-Computing Laplace Transforms-
  80. syms t s
  81. f = exp(-t);
  82. F = laplace(f, t, s);
  83. help laplace
  84. simplify(2/(s + 1)-s/(s + 1)^2)
  85. help sym/simplify
  86.  
  87. %---Question 2---
  88. syms t s
  89. f1 = dirac(t)
  90. f2 = t^2 + 4*t + 1
  91. f3 = t*exp(-t) + 0.5*exp(-t) + exp(-3*t)
  92. f4 = sin(2*t) + cos(t).^2
  93. f5 = exp(-t)*sin(5*t + pi/3) + (t.^2)*exp(-2*t)
  94.  
  95. %---Question 3---
  96. F1 = simplify(laplace(f1, t, s))
  97. F2 = simplify(laplace(f2, t, s))
  98. F3 = simplify(laplace(f3, t, s))
  99. F4 = simplify(laplace(f4, t, s))
  100. F5 = simplify(laplace(f5, t, s))
  101.  
  102. %-Computing Inverse Laplace Transforms-
  103. ilaplace(F, s, t);
  104.  
  105. %---Question 4---
  106. syms s t
  107. G1 = 1/s
  108. G2 = 1/(s*(s+1))
  109. G3 = 5/(s^2 +25)
  110. G4 = (10*s + 1)/(s^2 +2*s +10)
  111. G5 = (2*(s+1)*(s.^2+4))/((s.^2+4*s+1)*(s.^2+9))
  112.  
  113. g1 = simplify(ilaplace(G1, s, t))
  114. g2 = simplify(ilaplace(G2, s, t))
  115. g3 = simplify(ilaplace(G3, s, t))
  116. g4 = simplify(ilaplace(G4, s, t))
  117. g5 = simplify(ilaplace(G5, s, t))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement