Variable X must be of size [12 4]. It is currently of size [12 5]. Check where the variable is assigned a value.

3 visualizzazioni (ultimi 30 giorni)
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)')

Risposte (1)

Arif Hoq
Arif Hoq il 11 Feb 2023
Modificato: Arif Hoq il 11 Feb 2023
check in line 4
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]';
X = [ones(size(m)), m,m.^2, m.^3, m.^4]
X = 12×5
1 1 1 1 1 1 2 4 8 16 1 3 9 27 81 1 4 16 64 256 1 5 25 125 625 1 6 36 216 1296 1 7 49 343 2401 1 8 64 512 4096 1 9 81 729 6561 1 10 100 1000 10000
X = [m,m.^2, m.^3, m.^4]
X = 12×4
1 1 1 1 2 4 8 16 3 9 27 81 4 16 64 256 5 25 125 625 6 36 216 1296 7 49 343 2401 8 64 512 4096 9 81 729 6561 10 100 1000 10000

Categorie

Scopri di più su Interpolation in Help Center e File Exchange

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by