Based on the function of sin(x), write a function for cos(x). Will you get strange results similar to that of sin(x).
it is always possible to rearrange the terms to a new form:
What is the advantages of the second form over the first one? Please count the number of multiplications. Which form would propagate errors faster? Write a function that takes a degree n polynomial (coefficients in an array) and an x, and evaluates the polynomial at x using the second form.
The above shows a pentagon ABCDE. If we draw the five diagonals of this pentagon, we have a smaller pentagon lying in pentagon ABCDE. This smaller pentagon has its vertices in white color. Let us call the original pentagon P and the smaller pentagon in(P), because it is the result of "going" inside of pentagon P.
If we extend the sides of the given pentagon, they will intersect in five points, which define a new pentagon lying outside of pentagon P. We call this new "outside" pentagon out(P), because it lies outside of pentagon P.
From this construction, we know that going out from in(P) should be P. Similarly, going in from out(P) should also be P. More precisely, we have P = out(in(P)) and P = in(out(P)). Let ink(P) denote executing the "going in" operation k times, and outk(P) denote executing the "going out" operation k times. Then, the following should hold
This means that going in k times followed by going out k times should yield pentagon P. Similarly, going out k times followed by going in k times should also yield pentagon P.
Now consider the following strange pentagon:
The vertices are as follows, where p can be 0.1, 0.01, 0.001, 0.0001, 0.00001 and 0.000001.
|D||1 + p||1|
|E||1||1 + p|
For a given P, compute out2(in2(P)), out3(in3(P)), in2(out2(P)) and in3(out3(P)). Then, theoretically all four pentagons should be identical to pentagon P. Unfortunately, due to finite precision arithmetic, this is not the case. As a result, we should measure the error generated from the in() and out() operations. For each vertex of the pentagon P, say A = (x, y), and its corresponding result after taking the in() and out() operations, say A' = (x', y'), we compute the maximum error as follows:
The maximum error of P is the maximum over all five vertices. Then, you can compile a table as follows:
|0.1||fill maximum error in each entry|
Write a program that uses both float and double to perform the calculation and generate the above max. error table. Name your program pentagon.c. You will need (1) constructing a line from two points, and (2) computing the intersection point of two lines. Please consult your calculus and analytic geometry book. Then, use your program to do the following: (1) filling the required max. error table, (2) generating the vertices of the resulting pentagons, and (3) producing an analysis for the following questions: (a) why could the error be very large? (b) will you be able to pinpoint the potential problem(s)? (c) which vertex (or vertices) causes the largest error?, and (d) any findings that are worth mentioning.