Simple Laplace Transforms in MatLab

  • user warning: Can't open file: 'cache.MYI' (errno: 145) query: SELECT data, created, headers, expire, serialized FROM cache WHERE cid = 'schema' in /var/www/vhosts/mattalltech.com/httpdocs/includes/cache.inc on line 26.
  • user warning: Can't open file: 'cache.MYI' (errno: 145) query: UPDATE cache SET data = 'a:50:{s:6:\"blocks\";a:7:{s:11:\"description\";s:62:\"Stores block settings, such as region and visibility settings.\";s:6:\"fields\";a:13:{s:3:\"bid\";a:3:{s:4:\"type\";s:6:\"serial\";s:8:\"not null\";b:1;s:11:\"description\";s:29:\"Primary Key: Unique block ID.\";}s:6:\"module\";a:5:{s:4:\"type\";s:7:\"varchar\";s:6:\"length\";i:64;s:8:\"not null\";b:1;s:7:\"default\";s:0:\"\";s:11:\"description\";s:126:\"The module from which the block originates; for example, \'user\' for the Who\'s Online block, and \'block\' for any custom blocks.\";}s:5:\"delta\";a:5:{s:4:\"type\";s:7:\"varchar\";s:6:\"length\";i:32;s:8:\"not null\";b:1;s:7:\"default\";s:1 in /var/www/vhosts/mattalltech.com/httpdocs/includes/cache.inc on line 109.
  • user warning: Can't open file: 'cache.MYI' (errno: 145) query: SELECT data, created, headers, expire, serialized FROM cache WHERE cid = 'theme_registry:mattalltech' in /var/www/vhosts/mattalltech.com/httpdocs/includes/cache.inc on line 26.
  • user warning: Can't open file: 'cache.MYI' (errno: 145) query: UPDATE cache SET data = 'a:127:{s:24:\"block_admin_display_form\";a:7:{s:8:\"template\";s:38:\"modules/block/block-admin-display-form\";s:4:\"file\";s:29:\"modules/block/block.admin.inc\";s:9:\"arguments\";a:1:{s:4:\"form\";N;}s:4:\"type\";s:6:\"module\";s:10:\"theme path\";s:13:\"modules/block\";s:11:\"theme paths\";a:1:{i:0;s:13:\"modules/block\";}s:20:\"preprocess functions\";a:2:{i:0;s:19:\"template_preprocess\";i:1;s:44:\"template_preprocess_block_admin_display_form\";}}s:17:\"color_scheme_form\";a:6:{s:9:\"arguments\";a:1:{s:4:\"form\";N;}s:4:\"type\";s:6:\"module\";s:10:\"theme path\";s:13:\"modules/color\";s:8:\"function\";s:23:\"theme_color_scheme_form\";s:11:\"theme paths\";a in /var/www/vhosts/mattalltech.com/httpdocs/includes/cache.inc on line 109.

I've been trying to utilize some of my tools in my daily studies just to help me keep familiarity with them as I tend to forget things that I don't use on a daily basis. Here is a simple, though incomplete example of approaching my most recent linear systems homework with the assistance of Matlab.

This program is being updated as I complete the assignment.

  1. %{
  2. Author: Matthew B. Pare
  3. Date: February 21, 2009
  4. Course: EE 3303 - Linear System Analysis
  5. Assignment: Worksheet 3?, Due February 24, 2009
  6.  
  7. Copyright 2009 Matthew B. Pare
  8.  
  9. This program is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation.
  12.  
  13. This program is distributed in the hope that it will be useful, but
  14. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  15. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  16. for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program as the file LICENSE.txt; if not, please see
  20. http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
  21. %}
  22.  
  23. %---------------- House Keeping ----------------%
  24. clear, clc; % Clear Variables and Screen
  25. syms a s t w x; % Setup
  26.  
  27. display('%-------------- Problem 5 --------------%');
  28. % Find the Laplace transform of each of the following functions:
  29. display('%------ Part b ------%');
  30. display('% LaTeX Problem: f(t) = 3t^4e^{-2t}u(t)');
  31.  
  32. % Is the heaviside (step) function uncessary here? Is it implied?
  33. f5b = 3*t^4 * exp(-2*t) * heaviside(t);
  34.  
  35. L5b = laplace(f5b);
  36.  
  37. display(L5b);
  38.  
  39. %LaTeX Solution: 72\, \left( s+2 \right) ^{-5}
  40. display(latex(L5b)); % KICK ASS!!!
  41.  
  42. display('%------ Part c ------%');
  43. display('% LaTex Problem: 2tu(t) - 4 ''\frac{d}{dt}\delta(t)');
  44. f5c = 2*t-4*diff(dirac(t));
  45.  
  46. L5c = laplace(f5c);
  47.  
  48. display(L5c);
  49.  
  50. %LaTeX Solution:
  51. display(latex(L5c)); % KICK ASS!!!
  52.  
  53. display('%------ Part d ------%');
  54. display('% LaTex Problem: 2e^{-(t-1)}u(t)');
  55. f5d = 2*exp(-(t-1));
  56.  
  57. L5d = laplace(f5d);
  58.  
  59. display('LaTex Solution: ');
  60.  
  61. %LaTeX Solution:
  62. display(latex(L5d)); % KICK ASS!!!
  63.  
  64. display('%-------------- Problem 7 --------------%');
  65. display('%------ Part a ------%');
  66. f7a = (2*t+4);
  67.  
  68. L7a = laplace(f7a);
  69.  
  70. display('LaTex Solution: '), display(latex(L7a));
  71.  
  72.  
  73. display('%------ Part b ------%');
  74. L7b = laplace(4+3*exp(-2*t));
  75.  
  76. display('LaTex Solution: '), display(latex(L7b));
  77.  
  78. display('%------ Part c ------%')
  79. L7c = laplace(6*sin(3*t) + 8 * cos(3*t));
  80. display('LaTex Solution: '), display(latex(L7c));
  81.  
  82. display('%------ Part d ------%');
  83. L7d = laplace(exp(-2*t)*cosh(4*t));
  84. display('LaTeX Solution: '), display(latex(L7d));
  85.  
  86.  
  87. display('%-------------- Problem 8 --------------%');
  88. display('%------ Part a ------%');
  89. L8a = laplace(2*t * heaviside(t-4));
  90.  
  91. display('LaTex Solution: '), display(latex(L8a));
  92.  
  93. display('%------ Part b ------%')
  94. L8b = laplace(5*cos(t)*dirac(t-2));
  95.  
  96. display('LaTex Solution: '), display(latex(L8b));
  97.  
  98. display('%------ Part c ------%')
  99. L8c = laplace(exp(-t)*heaviside(t-a));
  100.  
  101. display('LaTex Solution: '), display(latex(L8c));
  102.  
  103. display('%------ Part d ------%');
  104. L8d = laplace(sin(2*t)*heaviside(t-a));
  105.  
  106. display('LaTex Solution: '), display(latex(L8d));
  107.  
  108. %-------------- Problem 9 --------------%
  109. display('%------ Part a ------%');
  110. L9a = laplace((t-4)*heaviside(t-2));
  111. display('LaTeX Problem: '), display(latex(L9a)), display('LaTex Solution: '), display(latex(L9a));
  112. display('%------ Part b ------%');
  113. L9b = laplace(2*exp(-4*t)*heaviside(t-1));
  114. display('LaTex Solution: '), display(latex(L9b));
  115.  
  116. display('%------ Part c ------%');
  117. L9c = laplace(5*cos(2*t-1));
  118. display('LaTex Solution: '), display(latex(L9c));
  119.  
  120.  
  121.  
  122. display('%------ Part d ------%');
  123. L9d = laplace(6*(heaviside(t-2) - heaviside(t-4)));
  124. display('LaTeX Problem: '), display(latex(L9d)), display('LaTex Solution: '), display(latex(L9d));
  125.  
  126.  
  127. display('%------------- Problem 18 -------------%')
  128. display('%------ Part a ------%');
  129. L18a = laplace(heaviside(t) + heaviside(t-1) + heaviside(t-2) - 3*heaviside(t-3));
  130. display('LaTex Solution: '), display(latex(L18a));
  131.  
  132. display('%------ Part b ------%');
  133. L18b = laplace(2*t*(heaviside(t) - heaviside(t-1)) + heaviside(t-1) - 2*t*(heaviside(t-3) - heaviside(t-4)));
  134.  
  135. display('LaTex Solution: '), display(latex(L18b));
  136.  
  137. %---------------- Notes ----------------%
  138. % Readabout matlabFunction(f), poly(A), poly2sym(C), setVar, simplify,
  139. % solve, subexpr, subs, svd,
  140. % http://www.mathworks.com/access/helpdesk/help/toolbox/control/getstart/f1-1016555.html

Here is a sample program that we went over in class. Dr. Mary Baker was presenting and I followed her example. She performed these examples just at the terminal but I thought creating a script file would be of greater use later on. Enjoy!

  1. %{
  2. Author: Matthew B. Pare
  3. Date: February 26, 2009
  4. Course: EE 3303 - Linear System Analysis
  5. Assignment: EE 3303 MatLab Overview for Laplace
  6.  
  7. Copyright 2009 Matthew B. Pare
  8.  
  9. This program is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation.
  12.  
  13. This program is distributed in the hope that it will be useful, but
  14. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  15. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  16. for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program as the file LICENSE.txt; if not, please see
  20. http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
  21. %}
  22.  
  23. %---------------- House Keeping ----------------%
  24. %clear, clc; % Clear Variables and Screen
  25.  
  26. %---------------- Example ----------------%
  27. %clear, clc;
  28.  
  29.  
  30. % Decending order
  31. num1 = [1 1];
  32. num2 = [1 3];
  33.  
  34. num = 5 * conv(num1, num2);
  35.  
  36. % Decending order for power of s!!!
  37. den1 = [1 0];
  38. den2 = [1 2];
  39. den3 = [1 8 25];
  40.  
  41. % Convolution only works for steps of 2 so extra step
  42. den12 = conv(den1, den2);
  43.  
  44. den = conv(den12, den3);
  45.  
  46. % Transform, this is not essential but you get a nice output...
  47. H = tf(num, den);
  48.  
  49. display(H);
  50.  
  51. % Numerator, Denominator
  52. % R will represent the zeros in the numerator
  53. % P will represent the poles in the denominator
  54. % K will represent the remainder (Numerator greater order than denominator)
  55. [r, p, k] = residue(num, den);
  56.  
  57. % The ouput will share indexes for each term, so you can reconstruct these
  58. % by matching the numerator and denominator for each term...
  59. display(r), display(p), display(k);
  60.  
  61.  
  62. % 2 * abs(k) * exp^(-a*t)*cos(w*t*o)); "Formula in the book"
  63. % K is the magnitude of the numerator, w is the mag of denom, a is
  64.  
  65. % Go backwards
  66. [num, den] = residue(r,p,k);
  67.  
  68. display(num), display(den);
  69.  
  70. % We can take advantage of this by
  71. ralt = r(1:2); % Alternate numerator
  72. palt = r(1:2); % Alternate denumenator, just first two terms
  73.  
  74.  
  75. % Output K
  76. [numalt, denalt] = residue(ralt, palt, k);
  77.  
  78. % This outputs as H(s) = \frac{-0.49s + 1.45}{s^2 + 8s + 25}
  79. display(numalt), display(denalt);
  80.  
  81. syms a s t w x; % Setup
  82.  
  83. h = (5*s^2 + 20*s + 15)/(s^4 + 10*s^3 + 41*s^2+50*s);
  84.  
  85. hoft = ilaplace(h);
  86.  
  87. display(hoft);
  88.  
  89.  
  90. %---------- Num greater than denominator example ----------%
  91. %clear, clc; % Remove this stuff to see what we just did...
  92.  
  93. % S^3 / (S+1)(s+2)
  94. syms s;
  95.  
  96. num = [1 0 0 0];
  97. den1 = [1 1];
  98. den2 = [1 2];
  99.  
  100. den = conv(den1, den2);
  101.  
  102. display(tf(num, den));
  103.  
  104. % SO OUR OUTPUT IS H(s) = \frac{8}{s+2} - \frac{1}{s+1} + s - 3
  105. % And now we can take the inverse transform, where
  106. % s is the first der of del, e^-t, e^(-2t)
  107. %[r, p, k] = residue(num, den);
  108.  
  109. % If you want to take an actual transform you have to use the symbolic
  110. % toolbox. Symbolic tool box is matlabs very odd way of establishing a
  111. % variable... I defined these up at the top, maybe I should move them?
  112. H2 = s^3/(s^2 + 3*s + 2);
  113.  
  114. display(ilaplace(H2));
  115. display(latex(ilaplace(H2)));

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
Either you're a spam bot or your not, now prove it!
Image CAPTCHA
Enter the characters shown in the image without spaces.