I'm working out this problem with a friend of mine on a group project and we are both stuck
Our professor insists that we do all of our work in Maple. I like Maple, but it's not as great as Mathematica.
a) A stock on the Nasdaq stockmarket has the following 9 values at the end of 9 consecutive business days: {(1, $18.35), (2, $25.25), (3, $22.85), (4, $23.65), (5, $22.05), (6, $25.75), (7, $26.15), (8, $26.25), (9, $25.85)}. Use the pseudoinverse method to find the linear combination of the functions
{1, x-5, (x-5)^2, (x-5)^3, (x-5)^4, (x-5)^5, (x-5)^6}
which best fits this data.
I have used the pseudo inverse method and found the linear equation y = .695x + 20.5416666666667
But when plotted with the data, it does not fit the graph very well.
He hinted that we should solve for the letters a through g of this equation
1*a + b*(x-5) + c*(x-5)^2 + d*(x-5)^3 + e*(x-5)^4 + f*(x-5)^5 + g*(x-5)^6
But I am at a loss.
I suspect that the goal is something like the following,
And that candidate solution can be plotted, along with the original data points.
It might be made more explicit, by computing the pseudo-inverse of Matrix
Musing singular value decomposition. Are you supposed to know how to use the singular values and left & right singular vectors to generate a pseudo-inverse (or do a least squares fit)?[addendum, as per request for clarification]
Take the definitions for
randufrom above.Observe that
r . uproduces the polynomialpinx, with unknowns being the names inu. You are going to try and fit this polynomialpto theXandYdata.Let's just take a single numeric data pair,
X[1]andY[1]. Evaluateratx=X[1].The dot product of that with
uis the polynomialpevaluated atx=X[1], and we take that as equal toY[1].This can be done for all 9 data pairs taken from data Vectors
XandY.That would produce 9 evaluations of
p(at each of theX[i]fori=1..9. Each of those equals the correspondingY[i],i=1..9. So you have 9 equations, with the LHSs being in terms of the 7 unknowns (ie. entries ofu, or coefficients in unexpandedp).Those 9 equations can be written more compactly, in Matrix-Vector notation, as
M . u = Y. The ith row of MatrixMconsists of the components ofrevaluated asX[i].In other words, the 9 data pairs have produced 9 instances of y=p(x). These are 9 equations that are linear in the 7 unknowns. That is an overdetermined system for which you can attempt to compute a least squares solution.
By multiplying
Yby the pseudo-inverse of 9-by-7 MatrixMyou obtain a VectorCwhose 7 values are taken to be a least squares solution foru.The least squares solution values
Ccan be substituted in for the unknowns inp. Here are two ways to get that,You might now ask yourself why
x-5is used in the terms ofu, and why a 6th degree polynomial was chosen.