equation and matrix calculus

5 Ansichten (letzte 30 Tage)
Viorel-Mihai Popescu
Viorel-Mihai Popescu am 9 Sep. 2024
Bearbeitet: Torsten am 9 Sep. 2024
I have a Aleat.xlsx table from I imported the integer value in D(15,6) => and construct a matrix in the first column we write the difference
DM(i,1) = D(i,1)-D(i+1,1); .... DM(i,10) = D(i,10)-D(i+1,10);
I have to calculus the coeficents a11, ...a10,1 from equations
b1 = DM(1,1)*a11+DM(1,2)*a21+DM(1,3)*a31+DM(1,4)*a41+DM(1,5)*a51+DM(1,6)*a61+DM(1,7)*a71+DM(1,8)*a81+DM(1,9)*a91+DM(1,10)*a101;
b10 = DM(10,1)*a11+DM(10,2)*a21+DM(10,3)*a31+DM(10,4)*a41+DM(10,5)*a51+DM(10,6)*a61+DM(10,7)*a71+DM(10,8)*a81+DM(10,9)*a91+DM(10,10)*a101;
the result in [a11 a21 ... a101];
We have to predict [a11 a21 ... a101] so b1 = D(1,1).. b10 = D(10,1); thus the line 11 of D(11,i) is equal with those calculus .
The program is of fixed lenght = 10 how can I modified the program thus D(n+5,6), b1...bn, a(11),.. a(n,1), in a loop for n integer >= 1000
so we shift the the calculus area from the first to n position until 2 to n+1 and the prediction of line n+2 and continue 5 steps with other coeficients . a(21),.. a(n+1,1) and find value a(n,n).
Practicly prom a set of n data to predict the n+1 value considering the order 1,2,3... differece multipplied with constant coefficient.
The program should be in some kind extensible with given n and to inspect the coeficient [a11 a21 ... an1]; to find the rule for an acurate prediction of the next value.
Please Help!
D = xlsread('Aleat.xlsx',1);
n = 10;
nCols = 10;
syms a11 a21 a31 a41 a51 a61 a71 a81 a91 a101;
M = zeros(n,n);
%filePath = 'Aleator.xlsx'
%data = readMatrixData(filePath);
%N = data(:,4);
M(1,1:n) = 0;
DM = zeros(10,10);
for i = 1:n
DM(i,1) = D(i,1)-D(i+1,1);
end;
for i = 1:(n-1)
DM(i,2) = DM(i,1)-DM(i+1,1);
end;
for i = 1:(n-2)
DM(i,3) = DM(i,2)-DM(i+1,2);
end;
for i = 1:(n-3)
DM(i,4) = DM(i,3)-DM(i+1,3);
end;
for i = 1:(n-4)
DM(i,5) = DM(i,4)-DM(i+1,4);
end;
for i = 1:(n-5)
DM(i,6) = DM(i,5)-DM(i+1,5);
end;
for i = 1:(n-6)
DM(i,7) = DM(i,6)-DM(i+1,6);
end;
for i = 1:(n-7)
DM(i,8) = DM(i,7)-DM(i+1,7);
end;
for i = 1:(n-8)
DM(i,9) = DM(i,8)-DM(i+1,8);
end;
for i = 1:(n-9)
DM(i,10) = DM(i,9)-DM(i+1,9);
end;
b1 = D(14,1);
b2 = D(13,1);
b3 = D(12,1);
b4 = D(11,1);
b5 = D(10,1);
b6 = D(9,1);
b7 = D(8,1);
b8 = D(7,1);
b9 = D(6,1);
b10 = D(5,1);
B1 = [b1 b2 b3 b4 b5 b6 b7 b8 b9 b10];
B2 = B1';
% We need to solve DM * a = b
% DM is (nRows - 1) x nCols matrix
% b is a column vector of size nCols
% Check if we have enough equations and variables
if size(DM, 1) < nCols
error('Insufficient number of equations.');
end
% Solve for coefficients a
% We are solving DM * a = b
% Using left division to find a
%size(DM)
%size(B1)
a = DM' \ B1';
b1 = DM(1,1)*a11+DM(1,2)*a21+DM(1,3)*a31+DM(1,4)*a41+DM(1,5)*a51+DM(1,6)*a61+DM(1,7)*a71+DM(1,8)*a81+DM(1,9)*a91+DM(1,10)*a101;
b2 = DM(2,1)*a11+DM(2,2)*a21+DM(2,3)*a31+DM(2,4)*a41+DM(2,5)*a51+DM(2,6)*a61+DM(2,7)*a71+DM(2,8)*a81+DM(2,9)*a91+DM(2,10)*a101;
b3 = DM(3,1)*a11+DM(3,2)*a21+DM(3,3)*a31+DM(3,4)*a41+DM(3,5)*a51+DM(3,6)*a61+DM(3,7)*a71+DM(3,8)*a81+DM(3,9)*a91+DM(3,10)*a101;
b4 = DM(4,1)*a11+DM(4,2)*a21+DM(4,3)*a31+DM(4,4)*a41+DM(4,5)*a51+DM(4,6)*a61+DM(4,7)*a71+DM(4,8)*a81+DM(4,9)*a91+DM(4,10)*a101;
b5 = DM(5,1)*a11+DM(5,2)*a21+DM(5,3)*a31+DM(5,4)*a41+DM(5,5)*a51+DM(5,6)*a61+DM(5,7)*a71+DM(5,8)*a81+DM(5,9)*a91+DM(5,10)*a101;
b6 = DM(6,1)*a11+DM(6,2)*a21+DM(6,3)*a31+DM(6,4)*a41+DM(6,5)*a51+DM(6,6)*a61+DM(6,7)*a71+DM(6,8)*a81+DM(6,9)*a91+DM(6,10)*a101;
b7 = DM(7,1)*a11+DM(7,2)*a21+DM(7,3)*a31+DM(7,4)*a41+DM(7,5)*a51+DM(7,6)*a61+DM(7,7)*a71+DM(7,8)*a81+DM(7,9)*a91+DM(7,10)*a101;
b8 = DM(8,1)*a11+DM(8,2)*a21+DM(8,3)*a31+DM(8,4)*a41+DM(8,5)*a51+DM(8,6)*a61+DM(8,7)*a71+DM(8,8)*a81+DM(8,9)*a91+DM(8,10)*a101;
b9 = DM(9,1)*a11+DM(9,2)*a21+DM(9,3)*a31+DM(9,4)*a41+DM(9,5)*a51+DM(9,6)*a61+DM(9,7)*a71+DM(9,8)*a81+DM(9,9)*a91+DM(9,10)*a101;
b10 = DM(10,1)*a11+DM(10,2)*a21+DM(10,3)*a31+DM(10,4)*a41+DM(10,5)*a51+DM(10,6)*a61+DM(10,7)*a71+DM(10,8)*a81+DM(10,9)*a91+DM(10,10)*a101;
%c1 = 20;%
%B1 = zeros(n,1);
%X = linsolve(DM, B1);

Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by