Given the data points (xi , yi), with
xi 0 1.2 2.3 3.5 4
yi 3.5 1.3 -0.7 0.5 2.7
find and plot (using MATLAB) the least-squares basis functions and the resulting least-squares fitting functions together with the given data points for the case of
a) a linear monomial basis p(x)= {1 x}T .
b) a quadratic monomial basis p(x)= {1 x x2}T .
c) a trigonometric basis p(x)= {1 cosx sinx}T
Moreover, determine the coefficients a by the Moore-Penrose pseudoinverse V+. Lastly, calculate the leasts-squares error measure E2(a) for each case, and give a brief statement.
MATLAB Code:
close all
clear
clc
x = [0 1.2 2.3 3.5 4]';
y = [3.5 1.3 -0.7 0.5 2.7]';
xx = min(x)-1:0.01:max(x)+1;
scatter(x,y), hold on
fprintf('Part
(a)\n---------------------------------------------------\n')
V = [ones(size(x)) x];
a = pinv(V)*y; % Pseudo-Inverse
fprintf('Model: y = %f + %f*x\n', a)
plot(xx, a(1) + a(2)*xx)
error = norm(y - (a(1) + a(2)*x));
fprintf('Error: %f\n', error)
fprintf('\nPart
(b)\n---------------------------------------------------\n')
V = [ones(size(x)) x x.^2];
a = pinv(V)*y;
fprintf('Model: y = %f + %f*x + %f*x^2\n', a)
plot(xx, a(1) + a(2)*xx + a(3)*xx.^2)
error = norm(y - (a(1) + a(2)*x + a(3)*x.^2));
fprintf('Error: %f\n', error)
fprintf('\nPart
(c)\n---------------------------------------------------\n')
V = [ones(size(x)) cos(x) sin(x)];
a = pinv(V)*y;
fprintf('Model: y = %f + %f*cos(x) + %f*sin(x)\n', a)
plot(xx, a(1) + a(2)*cos(xx) + a(3)*sin(xx))
error = norm(y - (a(1) + a(2)*cos(x) + a(3)*sin(x)));
fprintf('Error: %f\n', error)
fprintf('\nHence, the trigonometric basis fits the data better.\n')
xlabel('x'), ylabel('y')
legend('Data Points', 'Part (a)', 'Part (b)', 'Part (c)')
Output:
Part (a)
---------------------------------------------------
Model: y = 2.186531 + -0.330241*x
Error: 3.183762
Part (b)
---------------------------------------------------
Model: y = 3.777155 + -3.653015*x + 0.817536*x^2
Error: 1.109697
Part (c)
---------------------------------------------------
Model: y = 1.990093 + 1.803397*cos(x) + -1.820891*sin(x)
Error: 0.826195
Hence, the trigonometric basis fits the data better.
Plot:
Given the data points (xi , yi), with xi 0 1.2 2.3 3.5 4 yi 3.5 1.3 -0.7 0.5 2.7 find and plot (using MATLAB) the least-squares basis functions and the resulting least-squares fitting functions toget...
Consider the following table of data points: Using least squares fitting, find the polynomial Q(x) of degree 2 that fits the data points given in the table above. Approximate f(0.3) using Q(0.3). Use P(x) = Ax2+Bx +C to find 3 equations and then find A,B,C. f(x) i Xi 0 0.000 1.00000 1 0.125 0.98450 2 0.250 0.93941 0.375 0.86882 4 0.500 0.77880 5 0.625 0.67663 6 0.750 0.56978 0.875 0.46504 8 1.000 0.36788
Problem 2. Given the data points (xi. yi), with xi 2 02 4 yil 5 1 1.25 find the following interpolating polynomials, and use MATLAB to graph both the interpolating polynomials and the data points: a) The piecewise linear Lagrange interpolating polynomialx) b) The piecewise quadratic Lagrange interpolating polynomial q(x) c) Newton's divided difference interpolation pa(x) of degree s 4 Problem 2. Given the data points (xi. yi), with xi 2 02 4 yil 5 1 1.25 find the following...
Consider the following table of data points: Using least squares fitting, find the polynomial Q(x) of degree 2 that fits the data points given in the table above. Approximate f(0.3) using Q(0.3). f(x) i Xi 0 0.000 1.00000 1 0.125 0.98450 2 0.250 0.93941 0.375 0.86882 4 0.500 0.77880 5 0.625 0.67663 6 0.750 0.56978 0.875 0.46504 8 1.000 0.36788 f(x) i Xi 0 0.000 1.00000 1 0.125 0.98450 2 0.250 0.93941 0.375 0.86882 4 0.500 0.77880 5 0.625 0.67663...
3. (25 pts) Consider the data points: t y 0 1.20 1 1.16 2 2.34 3 6.08 ake a least squares fitting of these data using the model yü)- Be + Be-. Suppose we want to m (a) Explain how you would compute the parameters β | 1 . Namely, if β is the least squares solution of the system Χβ y, what are the matrix X and the right-hand side vector y? what quantity does such β minimize? (b)...