15. Exercise Set 6

Exercise 6.1: Quadratic Roots Function

Given: three real values, a, b, and c, and the formula for the roots of a quadratic equation
x1 = b + (b**2-4ac)**0.5/2a and
x2 = b - (b**2-4ac)**0.5/2a;
Compose: a function of a, b, and c that calculates and returns the roots or some flag values if the roots cannot be calculated.
Click here for a sample answer.

Exercise 6.2: Relaxation Function

Given: a two-dimensional array, A, of real values
Compose: a function of A that performs one relaxation step, returning the new array whose values at each position [i, j] are the average of the values from A of that position and that position's eight nearest neighbors, [i+/-1, j+/-1].
Click here for a sample answer.

Exercise 6.3: Polynomial Evaluation Program

Given: a two-dimensional array, C, of real valued polynomial coefficients, each row of which contains the coefficients of a single polynomial;
Given: for each row of C, the index of each coefficient's position is the exponent of x for that term;
Given: a one-dimensional array X of real valued polynomial unknowns, with each element corresponding to the unknown for the whole set of polynomials;
Compose: a function of C and X that evaluates each polynomial with each unknown, and returns the two-dimensional array containing in each row the value of each polynomial for one of the unknowns.
Click here for a sample answer.




Previous Section



Next Section



Table of Contents