ColorGrayscale Jeffrey Schiano 2014. All rights reserved. Rec 5. EE 350Continuous-Time Linear SystemsRecitation 51 Jeffrey Schiano 2014. All rights reserved. Rec 5. Recitation 5 Topics• Solved Problems (Exam I Review)– Solution of ODEs– Stability• MATLAB Program Flow Control • Relational Operators– Logical Operators– Conditional Statements – For Loop– While Loop2 Jeffrey Schiano 2014. All rights reserved. Rec 5. Problem 1• A LTI system with input f(t) and output y(t) has the ODE representation1. Determine the roots of the characteristic equation and sketch the roots in the λ–plane2. State if the system is unstable, marginally stable, or unstable3. Determine the zero-state unit-step response4. Determine the zero-state response for f(t) = cos(t) u(t)3()yy ft Jeffrey Schiano 2014. All rights reserved. Rec 5. Problem 1 Solution4 Jeffrey Schiano 2014. All rights reserved. Rec 5. Problem 1 Solution5 Jeffrey Schiano 2014. All rights reserved. Rec 5. Problem 1 Solution6 Jeffrey Schiano 2014. All rights reserved. Rec 5. Problem 1 Solution7 Jeffrey Schiano 2014. All rights reserved. Rec 5. Problem 1 Solution8 Jeffrey Schiano 2014. All rights reserved. Rec 5. Problem 2• A second-order LTI system has the following zero-state and zero-input responses for a given input f(t) and set of initial conditions• Determine1. The characteristic equation 2. The total response3. The natural response (homogeneous solution)4. The forced response (particular solution)5. The initial conditions9223() 2 0() 4 2 2 0ttzitt tzsyt e e tyt e e e t Jeffrey Schiano 2014. All rights reserved. Rec 5. Problem 2 Solution10 Jeffrey Schiano 2014. All rights reserved. Rec 5. Problem 2 Solution11 Jeffrey Schiano 2014. All rights reserved. Rec 5. Relational Operators• Compare variable values and produce a result that is true (1) or false (0)• Example• The syntax of a relational expression is12>> x = 10; y = 20; % assign values to two variables>> z = x < y; % compare x < y1zleft expression relational operator right express Jeffrey Schiano 2014. All rights reserved. Rec 5. List of Relational Operators13Relational Operator Description< Less than<= Less than or equal to> Greater than>= Greater than or equal to== Equal to~= Not equal to Jeffrey Schiano 2014. All rights reserved. Rec 5. Problem 3• Determine the results of the following expressions– verify using MATLAB14>> a = -1; b = 2; c = 3; d = 4; >> e = a^2 + b^2 >= c^2 + d^2e =f = (b > a) + 2*(c < d)f = >> x = [0, 2, 4, 6, 8]; y = [1, -1, 8, 2, 8];>>g = x > 3g =>> h = x >= yh = Jeffrey Schiano 2014. All rights reserved. Rec 5. Logical Operators• Logical operators work on logical variables and yield a logical value (0 or 1)• Use parentheses to control the order of evaluation• Logical operators work on with numbers– The number 0 is used as logical 0– A nonzero number is used as logical 115Logical Operator Description&AND|ORxor(a,b) Exclusive OR (XOR)~NOT Jeffrey Schiano 2014. All rights reserved. Rec 5. Short-Circuit Logical Operators• Evaluate the second operand only when the result is not fully determined by the first operand• Examples– If A = 0, then MATLAB will not evaluate B when determining A && B– If A = 1, then MATLAB will not evaluate B when determining A || B16Logical Operator Description&& Short-circuit Logical AND|| Short-circuit Logical OR Jeffrey Schiano 2014. All rights reserved. Rec 5. Problem 4• Determine the results of the following expressions– verify using MATLAB17>> a = 0; b = 1; c = pi; >> b & cans =a | bans = >> xor(b,c)ans =>>~cans = Jeffrey Schiano 2014. All rights reserved. Rec 5. The if-end Structure• Simplest if structure • If the expression is true the block of statements is executed, otherwise the block of statements is skipped and execution continues after the end statement18if expressionblock of statementsend Jeffrey Schiano 2014. All rights reserved. Rec 5. The if-else-end Structure• Provides a means for choosing among two blocks of statements to execute• If the expression is true, statements in block #1 execute• If the expression is false, statements in block #2 execute19if expressionblock #1 of statementselseblock #2 of statementsend Jeffrey Schiano 2014. All rights reserved. Rec 5. The if-elseif-else-end Structure• Most general if structure 20if expression 1block #1 of statementselseif expression 2block #2 of statementselseblock #N of statementsend Jeffrey Schiano 2014. All rights reserved. Rec 5. Problem 5• Determine x, verify using MATLAB2110;>> if (x < -2) || (x > 2), x = 2*sign(x); endxxx 4;>> if x > 0, x=sqrt(x);else^2;endxxxxx Jeffrey Schiano 2014. All rights reserved. Rec 5. For Loop• Repeats executing a block of statements a predetermined number of times• Syntax22for loop_index = first_index : index_increment : last_indexblock of statementsend Jeffrey Schiano 2014. All rights reserved. Rec 5. Problem 6• Consider the row vector x and column vector y• Use a For Loop to determine the product xy– Measure the execution time using the tic and tocfunctions – use MATLAB help to determine the syntax• Determine the product using a command line multiply– Measure the execution time• Which approach is faster?23x = ones(1,10000); y = ones(10000,1) Jeffrey Schiano 2014. All rights reserved. Rec 5. Problem 6 Solution24 Jeffrey Schiano 2014. All rights reserved. Rec 5. While Loop• Repeats executing a block of statements until an expression is no longer true• Syntax25while expression block of statementsend Jeffrey Schiano 2014. All rights reserved. Rec 5. Problem 7• Use a While Loop to display 20,21,.., 2N, where the integer N ≥ 0• Verify using MATLAB26 Jeffrey Schiano 2014. All rights reserved. Rec 5. EE 350Continuous-Time Linear SystemsRecitation 51 Jeffrey Schiano 2014. All rights reserved. Rec 5. Recitation 5 Topics• Solved
View Full Document