% relation_ex.m % kris stewart, cs 205, spring '98 % examples using relational operators on vectors % clear close all clc %------------------------------------------------------------------- echo on x1 = -3:.1:3; % set up a range of values y1 = sin(x1)./x1; % given these values of x, compute sin(x)/x % What does l'Hospital's Rule say about % sin(x)/x as x -> 0? % % you probably got a message about divide by zero. % x2 = x1+(x1==0)*eps; % replace x with eps if it's component was zero y2 = sin(x2)./x2; % try to compute sin(x)/x % % no divide by zero message this time, right? % % to validate this, let's plot the function sin(x)/x and see what it's % graph reveals about its behavior near x=0 figure x = linspace(-3,3,50); y = sin(x)./x; plot(x,y), grid, title('Looks nicely behaved to me'),... xlabel('x'),ylabel('sin(x)/x')