CS 205 Intro. Compl. Programming
Vectorization of Code
April 1, 1998 and continuing April 13/15

A mathematical function that is used in signal processing is the sinc function, defined by

y(x) = sin(x)/x

This was introduced in our textbook on p. 80 [Sect. 3.6 User-Written Functions]
sinc_x.m

We can plot this function plot sin(x)/x.

I've written a MATLAB script relation_ex.m showing how you can work with this function over an interval that includes x=0.

I've placed this routine in the directory that your class accounts are set up to be able to read automatically, so you should be able to type, at the MATLAB prompt,

relation_ex

Which of these routines is most efficient?
How do you define efficient?
What are the costs of a program?

  1. Time to develop, debug and document a program (person time)
  2. Time to execute the code (computer time)
MATLAB has built in commands to give the programmer access to measuring the computer time. tic, toc

From a MATLAB window you can run the script

timesinc.m

and I'd like to discuss in lab the results from using the MATLAB script

timesinc.m

. I would like to ask the class to help me understand why the first time this example is run we obtain such different results from the second running of the same MATLAB code. I don't know the answer, so I hope someone has an idea.
I wanted to leave you with this starting point for a new topic on the vectorization properties that MATLAB provides which we will examine in detail after spring break.
Background of L'Hospital's rule:

Hopefully, you saw that there are problems for y(x) = sin(x)/x when x=0, but L'Hospital's rule (from calculus) tells us in this case that

		sin(0)   cos(0)
		------ = ------     
		  0        1
In case you don't remember from calculus, L'Hospital's rule says that for the quotient of two functions
	f(x)						f(0)
	----  for x=0 gives the "indetermindant"	---- = 0/0
	g(x)  		        			g(0)
in which case
	f(x)   f'(x)   cos(x)
	---- = ----- = ----- = cos(x)      at the point x=0
	g(x)   g'(x)     1
for f(x) = sin(x) and g(x) = x