I am given set of 50 data points with values {a^(i),b^(i)} for i=1,...,50 stored in the arrays a and b. I know that the Vandermonde matrix A has size m x n, where n = 2 ... 11 and m is the size of the array a.
I want to to fit the data with a polynomial of degree (n − 1), for n = 2,...,11. To do that for each n I have to set up the Vandermonde matrix A of size m × n.
The Vandermonde matrix A solves the following equation:
A^T*A*x = A^T*b
Where the A^T is the transpose matrix and I have b already given.
Also we know that Aij = (a^(i))^(j−1) for j = 1,...,n,
What confuses me is how to set the matrix for n = 2,..,11.
What my line of thought is:
I have m = length(a); this will set up m = 50;
n = 11;
Then A=ones(m,n); This creates a matrix A filled with ones that has the correct size.
However I am not sure how to populate the matrix. I wrote the following for loop which I thought will populate the matrix:
for n = 2:11
j=n;
for i = 1:50
A(i,n) = (a^(i))^(j-1);
end
end
Could you help me please with setting up the matrix?
Try to avoid for-loops if you can in matlab. A hint is you can use
for example
returns $$rows = \left[\begin{array}{ccc}1&2&3\\1&2&3\\1&2&3\\1&2&3\end{array}\right], cols= \left[\begin{array}{ccc}1&1&1\\2&2&2\\3&3&3\\4&4&4\end{array}\right]$$
Then you can use point operators on matrices.
calculates elementwise multiplication
calculates elementwise power