Matrix calculus and solving system of equations

조회 수: 4 (최근 30일)
Viorel-Mihai Popescu
Viorel-Mihai Popescu 2024년 9월 3일
댓글: Viorel-Mihai Popescu 2024년 9월 3일
I have a Aleator.xlsx table from I imported the integer value in D => 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); and b1= D(1027,1).. b10= D(1017,1);
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;
And write the result in Vector Rez = [a11 a21 ... a101];
Please Help!

채택된 답변

Jaimin
Jaimin 2024년 9월 3일
From the description, I understand there is a file named 'Aleator.xlsx' that contains the necessary data. You want to use this data to solve a system of linear equations.
We can use the “readmatrix” function to load the data, and the "\" operator to solve the system of linear equations.
Here I have attached sample code for better understanding.
% Step 1: Load the Excel file
filePath = 'Aleator.xlsx'; % Replace with your actual file path
data = readmatrix(filePath);
% Step 2: Extract the integer values from column D
D = data(:, 4); % Assuming column D is the 4th column
% Step 3: Construct the difference matrix DM
DM = zeros(10, 10);
for i = 1:10
DM(i, :) = D(i) - D(i+1:i+10);
end
% Step 4: Extract b1 to b10
b = [D(1027); D(1026); D(1025); D(1024); D(1023); D(1022); D(1021); D(1020); D(1019); D(1018)];
% Step 5: Solve the system of equations
% DM' * a = b
a = DM' \ b; % Transpose DM to match the equation format
% Step 6: Write the result in Vector Rez
Rez = a;
% Display the result
disp('Vector Rez =');
disp(Rez);
For more information on the 'readmatrix' function, please refer to the MathWorks documentation.
readmatrix:
For more information on system of linear equation, please refer to the MathWorks documentation.
Systems of Linear Equations:
I hope this will be helpful.

추가 답변 (1개)

Dheeraj
Dheeraj 2024년 9월 3일
Hi Viorel-Mihai Popescu,
You can use "xlsread" function to read to the file and the data associated with it. you need to set up a system of linear equations based on the provided matrix equations and solve for the coefficients . Below is an example to do the same assuming you have "DM" matrix created using your logic.
Formulate the system of equations
% 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
a = DM \ b;
Thank You.
  댓글 수: 3
Torsten
Torsten 2024년 9월 3일
Insert the lines
size(DM)
size(b)
before using the command
a = DM \ b;
What does MATLAB print out for the two sizes ?
Viorel-Mihai Popescu
Viorel-Mihai Popescu 2024년 9월 3일
Now has no compile error but have some logical emprovement...

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by