

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Note: In case there are some typos found, or I expand on some of the problem (very likely), download the file again over the weekend. Please send questions about any aspect of this, or if you want a more concrete description of what you want to do. Right now it is somewhat loose, and I urge people to think a little creatively and explore things. The coding effort in C++ should be minimal. I should be able to answer any matlab or DataTank questions you have, and you shouldn’t hesitate to ask.
DTDoubleArray PolynomialInterpolation(const DTDoubleArray &x, const DTDoubleArray &y) { int N = x.m()-1; DTMutableDoubleArray returnArray(2,N+1); // returnArray(0,i) = x(i) // returnArray(1,i) = corresponding Newton divided difference.
return returnArray; }
Then another function that takes in the polynomial from the function above and a list of x values where it should evaluate and returns the y values.
DTDoubleArray yValues(const DTDoubleArray polynomial,const DTDoubleArray &x) { int m = x.m(); DTMutableDoubleArray returnArray(m); // returnArray(i) = polynomial evaluated at x(i) return returnArray; }
Now drive it from matlab or DataTank, and draw the result. You should test the following cases
as a function of x). Draw the error in [1, 2] as well as outside it, i.e. [0, 3].
Integrate(a,b,eps) c = (a+b)/2; Total = Single(a,b); Left = Single(a,c); Right = Single(b,c); error = (Left+Right-Total)/(2^(k-1)-1); if (abs(error)<eps) return Left+Right; else return Integrate(a,c,eps/2) + Integrate(c,b,eps/2);
You need to keep track of all of the a,b,c’s that you compute and draw those as lines on top of the plot of the function that you hand in. It is perfectly reasonable to hard code your function in C++, but if you driving things from DataTank you can pass in the function as an argument. Run the following analysis on this:
(a) Run this for a smooth function like exp(x) (b) Try a function some not so smooth like sin(b ∗ x ∗ (1 − x)) (c) What happens if you do a non-smooth function like step func- tions, or the absolute value function.