Variable X must be of size [12 4]. It is currently of size [12 5]. Check where the variable is assigned a value.
3 views (last 30 days)
Show older comments
m = 1:12; m = m';
Y = [2.8 3.5 4.7 6.3 6.6 7 6.4 5.8 5.3 4.2 3.4 2.6]';
% Part (a)
X = [ones(size(m)) m m.^2 m.^3 m.^4 ];
z = X'*Y;
S = X'*X;
U = chol(S);
w = U'\z;
disp('(a) Coefficients:')
c = U\w
plot(m,Y,'o'), hold on
q = min(m):0.1:max(m);
fit = c(1) + c(2)*q + c(3)*q.^2 + c(4)*q.^3 + c(5)*q.^4;
plot(q, fit), hold off
xlabel('m'), ylabel('Y')
legend('Data Points', 'Curve Fit')
title('Part (a)')
% Part (b)
c = X\Y
c = c([5:-1:1]);
figure, plot(m,Y,'o'), hold on
q = min(m):0.1:max(m);
fit = polyval(c, q);
plot(q, fit), hold off
xlabel('m'), ylabel('Y')
legend('Data Points', 'Curve Fit')
title('Part (b)')
0 Comments
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!