Matrix calculus and solving system of equations

4 次查看(过去 30 天)
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
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