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.
%{ Author: Matthew B. Pare Course: EE 3303 - Linear System Analysis Assignment: Worksheet 3?, Due February 24, 2009 Copyright 2009 Matthew B. Pare This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program as the file LICENSE.txt; if not, please see http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. %} %---------------- House Keeping ----------------% syms a s t w x; % Setup display('%-------------- Problem 5 --------------%'); % Find the Laplace transform of each of the following functions: display('%------ Part b ------%'); display('% LaTeX Problem: f(t) = 3t^4e^{-2t}u(t)'); % Is the heaviside (step) function uncessary here? Is it implied? L5b = laplace(f5b); display(L5b); %LaTeX Solution: 72\, \left( s+2 \right) ^{-5} display(latex(L5b)); % KICK ASS!!! display('%------ Part c ------%'); display('% LaTex Problem: 2tu(t) - 4 ''\frac{d}{dt}\delta(t)'); L5c = laplace(f5c); display(L5c); %LaTeX Solution: display(latex(L5c)); % KICK ASS!!! display('%------ Part d ------%'); display('% LaTex Problem: 2e^{-(t-1)}u(t)'); L5d = laplace(f5d); display('LaTex Solution: '); %LaTeX Solution: display(latex(L5d)); % KICK ASS!!! display('%-------------- Problem 7 --------------%'); display('%------ Part a ------%'); f7a = (2*t+4); L7a = laplace(f7a); display('LaTex Solution: '), display(latex(L7a)); display('%------ Part b ------%'); display('LaTex Solution: '), display(latex(L7b)); display('%------ Part c ------%') display('LaTex Solution: '), display(latex(L7c)); display('%------ Part d ------%'); display('LaTeX Solution: '), display(latex(L7d)); display('%-------------- Problem 8 --------------%'); display('%------ Part a ------%'); L8a = laplace(2*t * heaviside(t-4)); display('LaTex Solution: '), display(latex(L8a)); display('%------ Part b ------%') display('LaTex Solution: '), display(latex(L8b)); display('%------ Part c ------%') display('LaTex Solution: '), display(latex(L8c)); display('%------ Part d ------%'); display('LaTex Solution: '), display(latex(L8d)); %-------------- Problem 9 --------------% display('%------ Part a ------%'); L9a = laplace((t-4)*heaviside(t-2)); display('LaTeX Problem: '), display(latex(L9a)), display('LaTex Solution: '), display(latex(L9a)); display('%------ Part b ------%'); display('LaTex Solution: '), display(latex(L9b)); display('%------ Part c ------%'); display('LaTex Solution: '), display(latex(L9c)); display('%------ Part d ------%'); L9d = laplace(6*(heaviside(t-2) - heaviside(t-4))); display('LaTeX Problem: '), display(latex(L9d)), display('LaTex Solution: '), display(latex(L9d)); display('%------------- Problem 18 -------------%') display('%------ Part a ------%'); L18a = laplace(heaviside(t) + heaviside(t-1) + heaviside(t-2) - 3*heaviside(t-3)); display('LaTex Solution: '), display(latex(L18a)); display('%------ Part b ------%'); L18b = laplace(2*t*(heaviside(t) - heaviside(t-1)) + heaviside(t-1) - 2*t*(heaviside(t-3) - heaviside(t-4))); display('LaTex Solution: '), display(latex(L18b)); %---------------- Notes ----------------% % Readabout matlabFunction(f), poly(A), poly2sym(C), setVar, simplify, % solve, subexpr, subs, svd, % 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!
%{ Author: Matthew B. Pare Course: EE 3303 - Linear System Analysis Assignment: EE 3303 MatLab Overview for Laplace Copyright 2009 Matthew B. Pare This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program as the file LICENSE.txt; if not, please see http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. %} %---------------- House Keeping ----------------% %clear, clc; % Clear Variables and Screen %---------------- Example ----------------% %clear, clc; % Decending order num1 = [1 1]; num2 = [1 3]; % Decending order for power of s!!! den1 = [1 0]; den2 = [1 2]; den3 = [1 8 25]; % Convolution only works for steps of 2 so extra step % Transform, this is not essential but you get a nice output... H = tf(num, den); display(H); % Numerator, Denominator % R will represent the zeros in the numerator % P will represent the poles in the denominator % K will represent the remainder (Numerator greater order than denominator) % The ouput will share indexes for each term, so you can reconstruct these % by matching the numerator and denominator for each term... display(r), display(p), display(k); % 2 * abs(k) * exp^(-a*t)*cos(w*t*o)); "Formula in the book" % K is the magnitude of the numerator, w is the mag of denom, a is % Go backwards display(num), display(den); % We can take advantage of this by ralt = r(1:2); % Alternate numerator palt = r(1:2); % Alternate denumenator, just first two terms % Output K % This outputs as H(s) = \frac{-0.49s + 1.45}{s^2 + 8s + 25} display(numalt), display(denalt); syms a s t w x; % Setup h = (5*s^2 + 20*s + 15)/(s^4 + 10*s^3 + 41*s^2+50*s); hoft = ilaplace(h); display(hoft); %---------- Num greater than denominator example ----------% %clear, clc; % Remove this stuff to see what we just did... % S^3 / (S+1)(s+2) syms s; num = [1 0 0 0]; den1 = [1 1]; den2 = [1 2]; display(tf(num, den)); % SO OUR OUTPUT IS H(s) = \frac{8}{s+2} - \frac{1}{s+1} + s - 3 % And now we can take the inverse transform, where % s is the first der of del, e^-t, e^(-2t) %[r, p, k] = residue(num, den); % If you want to take an actual transform you have to use the symbolic % toolbox. Symbolic tool box is matlabs very odd way of establishing a % variable... I defined these up at the top, maybe I should move them? H2 = s^3/(s^2 + 3*s + 2); display(ilaplace(H2)); display(latex(ilaplace(H2)));
Comments
Post new comment