Data Set 1
Copyright By PowCoder代写 加微信 powcoder
Data Set 2
What happen when you make the degree much bigger than 8, say 20 or 50?
For data set 2, we have 41 data points, meaning that we can set degree between 0~40. We can see that the polynomial line would fit more closely to the data points.
When we set deg = 20:
When we set deg = 40, the polynomial line come across all data points:
In data science, using high degree polynomial would cause problem of overfitting. Here, the polynomial model fits exactly against every given data points when degree is 40. When we try to predict with new data, the model would not be able to give an accurate prediction.
What happen if you use small degree, such as 5, but evaluate and plot the p vector on a grid tt of points that runs from substantially less than t(1) to substantially greater than t(m)? This is called extrapolation.
The graph shows the result with degree = 5 on grid between -10 and 10.
By doing this, one can predict the response to an input that lies outside of the range of the values of the predictor variable used to fit the model. This is called extrapolation.
What happen if the t points are not all distinct, for example, t=[1 1 2 3]?
If t contain duplicated entries, x, which is the coefficients of the interpolating polynomial, would not be calculated. As the result, p can’t be calculated and no polynomial model can be created.
This occur because when we set up Vandermonde Matrix, if t contain duplicated entries, duplicated row would occur in Vandermonde Matrix. And thus error would occur when we use backslash operator to solves Ax = b.
Set A randomly by A=randn(10) and call your function to compute L and U. Double check that they are indeed unit lower and upper triangular respectively and check how good they are by computing
A − LU using norm(A-L*U)
Check whether your computed solution x is close to the one you obtain from x=A\b, computing the norm of the difference.
Now set the 1,1 entry of your random matrix to a small value, say 1e-10. How big is the resulting A − LU and why ?
The resulting ||A-LU|| is significant larger than before. This is resulted because firstly, instability is introduced when we calculate first multiplier by dividing U(2, 1) by U(1, 1), which introducing stability as we are dividing by a small number
absolute error increase
test your program on a randomly generated tridiagonal matrx and compare the result with the one you get from x=A\b
Reason behind the calculation done for tridiagonal matrix
Credit: https://www.webpages.uidaho.edu/~barannyk/Teaching/LU_factorization_tridiagonal.pdf
Operation count
We sum up the numbers of multiplications to see the operation counts it takes to solve x for tridiagonal matrix, and see that there are only 3 roughly n times loops, one in each function(LU decomposition, forward and backward substitution). To sum up, around 3n operations is required for solving tridiagonal matrix, and this is way less work, compare to normal matrix, which requires around n^3 operations.
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com