ECE-1011 (SPRING 2003)

QUIZ #6 PREP SHEET

 

NOTE: Some of these questions/statements require you to think beyond the strict information given in the text.

4.4 Numerical technique: Roots of Polynomials

 

(na) A polynomial is a function with a single variable (to powers) with coefficients. The degree (order) of the polynomial is equivalent to the largest non-zero exponent.

Example: f(x) = x^3 – 2x^2 + 0.1x – 4; this is a third degree polynomial.

 

(p 190) The roots of a polynomial may be real or complex (if poly is real, then complex roots will be in pairs). The number of roots is equal to the degree of the poly.  Solving for the roots of a degree two poly is relatively easy, using the quadratic formula. However, roots of higher order poly’s are difficult by hand. The polynomial will equal exactly zero, when a root is substituted into the variable.

 

(p 191 section 4.5) Incremental search of roots. (note: it will only solve for real roots, to solve for complex roots requires the derivative of the function)

Limitations of incremental root technique:

  1. May not detect a root of increment too large, example if two roots lie within interval the multiplication will be the same sign.
  2. May not detect if three roots are on an interval and the sign is opposite. It will detect one root but not two others!

 

(p 193 section 4.6) Problem Solving: System Stability

 

Without going into the details, a system (continuous or discrete) is stable when the roots of the denominator of the Laplace or Z transform, respectively, of that system has all its roots in the left-half of the S-plane or inside the unit circle of the Z-plane.

 

Assuming we are trying to find the real roots (only, with this technique) of this denominator.

 

Review pseudocode and functions for this section.

 

Knowing that there needs to be as many roots as the degree of the poly, ensure your answer reflects this fact.

 

(p 199) Newton-Raphson Method of root finding:

 

An important result of this method is that it takes fewer iterations to compute the root of a poly.

 

Review technique of this method on page 201 code. This method only solves for real roots. Note the function as well as its derivative needs to be hard-coded. Limit as to the number of iterations to find root is also included, why?

 

Limitations of this method:

If initial guess is too far off, it may not find the root or find another root, thus missing one of the roots.

Derivatives may be hard to obtain.

Poly with its derivative is zero or close to zero at peaks, or inflections can cause this method to fail near the origin.

 

(p 203) Integration of a function can be viewed as the summation of the area under the curve; that is, the area between the line of the curve and the abscissa, the area above the axis is positive the area below is negative, thus the summation could be zero. An example of this would be the integration of the function f(x) = sin(x), from 0 to 2pi.

 

(p 204) Integration using the trapezoidal method, of a function, implies we are trying to “approximate” the area between the function’s slope and the abscissa. To find the approximate area between to values of f(x1) and f(x2).

 

Area = 0.5*base*height

Where; Base =  x2 – x1; height = (f(x1) + f(x2));

Thus the integration between two points on the abscissa (a and b) would be:

 

  =

 

(p 205) If integration of points of data is required, the abscissa (horizontal coordinate) points are given along with the corresponding ordinate (vertical coordinate), to accomplish this a looping structure would need to be used, especially if the abscissa data was not equally distributed.

 

Example of function to perform this (assume data is retrieved from a file):

 

double int_data(void)

{

            FILE *data;

            double area = 0.0,x_new,x_old,y_new,y_old;

            data = fopen(“data_file”,r);

            if(data == NULL)

            {

                        printf(“Data file did not open\n”);

                        return(-1);

            {

            else

            {

                        /* get first data points */

                        fscanf(data,”%f%f”,&x_old,&y_old;

while (fscanf(data,”%f%f”,&x_new,&y_new) == 2)

                        {

                                    area += 0.5*(x_new-x_old)*(y_old+y_new);

                                    x_old = x_new;

                                    y_old = y_new;

                        }

            }

            fclose(data);

            return(area);

}

                                   

5.1 One-dimensional arrays

 

Why use arrays? When working with data that is associated and do not want a separte variable name for all the data. Example two arrays one with time value associated with each subscript and the other with distance associated with the time (at the same subscript value).

 

Distinction between elements in an array is done with a subscript along with the name of the array.

 

A one-dimensional array are defined by the format:

 

type array_name[size(optional)] = {optional element values if initializing};

 

An array that is defined and initialized, will take on the values initialized to. If the array is defined larger than the number of initialized values, the rest of the elements are initialized to zero.

 

An array subscript ALWAYS start at zero.

 

The definition requires the size or initialize the elements within braces.

 

All array elements are of the same type.

 

Arrays are defined as type, just as variables, functions, etc.

 

An array that is defined but not initialized, will have unknown values in the array elements.

 

Access of an array element is through the subscript value, example:

 

Signal[3], will access the 4th element of the array signal (remember, starts at zero);

Or Signal[var], where var is of type int (must be) and has an assigned value within the array size of signal.

 

Square brackets [] take highest precedence, along with ();

 

Very important not to access elements outside of the defined array, as it may cause segmentation fault or a buss error. This is especially true if you try to write to a value outside the array, this may write garbage data into executable code, stack area, etc. this is very bad!

 

(p 228) Typically data read from a file is put into an array. Be sure you know how to do this. A looping structure is usually used.

 

(p 229-230) Know how to scanf, fscanf, printf and fprintf, to and from and array.

 

(p 232) Arrays must be specified for a maximum number of elements, and when using the array not to exceed the number defined.

When passing an array to a function, pass the array name and number of array elements (good practice). The definition of the function needs to have an array defined.

Example:

 

double max(double y[], int npts)

{

            compute maximum value of the array y;

}

 

(p234) Array elements can, just like variables, be passed as a call-by-value (where the data in the array can not be changed) or as a call-by-address (where the data can be changed by the function, if required). Example of call-by-addrress &signal[0], this passes the (starting) address of the array signal. More about this later.

 

5.2 Statistics

 

Mean (average) of data is defined mathematically as:

 

Sum of all elements divided by the number of elements.

 

Median, is the middle value, it may or may not be a member of the data. If the number of elements is odd, it is the middle element’s value. If the number of elements is even then the value is the sum of the two middle values divided by two (mean of the two middle numbers).

 

Standard deviation is the square root of the variance and the variance is defined mathematically as:

Review all statistical functions in book, pages 235-8.

 

(p 239) Understand what a programmer-written header file is, how to create and how to include it in a program.

 

(p 240) Average power: power is the absolute value of a signal, where absolute is for a real number is just the fabs, but for complex it is the square-root of the square. To find average power mathematically it is written as: