% timesinc.m % Run the sinc_x(x) function on the interval [-3,3] x = -3:.1:3; tic y = sinc_x(x); t = toc plot(x,y), grid, ... title(['Using sincx.m (p. 80 find) function to compute sin(x)/x taking ' num2str(t) ' time']),... xlabel('x'), ylabel('sin(x)/x') figure % ---------------------------------------------- x1 = x+(x==0)*eps; % replace x with eps if it's component was zero tic y1 = sin(x1)./x1; % try to compute sin(x)/x t1 = toc plot(x1,y1), grid, ... title(['Using logical text (x==0) to avoid problem x=0 taking ' num2str(t1) ' time']),... xlabel('x'), ylabel('sin(x)/x') % echo on % it's also important to have reproducible results pause % hit return when you're ready to run this example a second time echo off figure % Run the sinc_x(x) function on the interval [-3,3] x = -3:.1:3; tic y = sinc_x(x); t = toc plot(x,y), grid, ... title(['Using sincx.m (p. 80 find) function to compute sin(x)/x taking ' num2str(t) ' time']),... xlabel('x'), ylabel('sin(x)/x') figure % ---------------------------------------------- x1 = x+(x==0)*eps; % replace x with eps if it's component was zero tic y1 = sin(x1)./x1; % try to compute sin(x)/x t1 = toc plot(x1,y1), grid, ... title(['Using logical text (x==0) to avoid problem x=0 taking ' num2str(t1) ' time']),... xlabel('x'), ylabel('sin(x)/x')