lab1 - Lab 1 for ECES 302 Piecewise-Linear Functions I...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Page 1 Lab 1 for ECES 302 Piecewise-Linear Functions I Background: Many of the practical signals and input functions studied in our course are piecewise-defined functions. Proficiency working with such functions in Matlab and Maple is critical if students are to have a rewarding learning experience in the computer lab. The unit step function u ( t ) and the ramp function r ( t ) are the basic building blocks needed to construct all piecewise-linear functions. Exercise 1. Building Blocks for Piecewise Functions in Maple. Here is how to define, evaluate and plot the units step function and ramp function in Maple. > alias(u=Heaviside): r := t -> t*u(t): > u(-2); u(0); u(2); which returns: 0, undefined, 1 > r(-2); r(0); r(2); which returns: 0, undefined, 2 > plot( u(t), t = -2 . . 2); > plot( r(t), t = -2 . . 2); You can create a simultaneous plot of both using square bracket notation. > plot( [u(t),r(t)], t = -2 . . 2, color = [blue, red] ); The alias command is used so that students can enter the unit step function as u(t) agreeing with the notation in their book and lectures, instead of having to type out Maple’s Heaviside command each time. The ramp function is defined as r(t) using arrow notation. Unit step function u(t). Ramp function r(t).
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Page 2 function y = u(x) y = ones( size(x) )/2; set1 = find(x>0); y(set1) = ones(size(set1)); set2 = find( x<0 ); y(set2) =zeros(size(set2))/2; Below is an alternative version for u(x) which would even work for matrices. function y = r(x) z = zeros( size(x) ); set1 = find( x>0 ); z(set1) = ones( size(set1) ); y=z.*x; Below is an alternative version for r(x) which would even work for matrices. Exercise 2. Building Blocks for Piecewise Functions in Matlab. W first need to create the unit step function and ramp function for use in Matlab. We will do this using m-files. In Matlab, each function must be defined in a plain text file called an M-file. Open Matlab.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

lab1 - Lab 1 for ECES 302 Piecewise-Linear Functions I...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online