Solving linear system of equations

1 vue (au cours des 30 derniers jours)
Rick
Rick le 5 Mar 2015
Hello,
I want to solve a system of linear equations, but there is a slight twist in the equation (i.e. not every one is written Ax = B). How can I use matlab to solve this? I want to know xH. I suppose I will use linsolve command, but I don't know what exact manipulation will need to be made. Thanks
% Vapor Pressure of n-Hexane (kPa)
PH = zeros(5,1);
PH(1) = 101.3;
PH(2) = 136.7;
PH(3) = 197.3;
PH(4) = 284.0;
PH(5) = 456.0;
% Vapor Pressure of n-Octane (kPa)
PO = zeros(5,1);
PO(1) = 16.1;
PO(2) = 23.1;
PO(3) = 37.1;
PO(4) = 57.9;
PO(5) = 101.3;
% Liquid Mole fraction of n-Hexane in n-Hexane/n-Octane mixture
xH = zeros(5,1);
xH(1)*PH(1) + (1-xH(1))*PO(1) - 101.32 = 0;
xH(2)*PH(2) + (1-xH(2))*PO(2) - 101.32 = 0;
xH(3)*PH(3) + (1-xH(3))*PO(3) - 101.32 = 0;
xH(4)*PH(4) + (1-xH(4))*PO(4) - 101.32 = 0;
xH(5)*PH(5) + (1-xH(5))*PO(5) - 101.32 = 0;

Réponse acceptée

Torsten
Torsten le 5 Mar 2015
xH(1)=(101.32-PO(1))/(PH(1)-PO(1))
xH(2)=(101.32-PO(2))/(PH(2)-PO(2))
xH(3)=(101.32-PO(3))/(PH(3)-PO(3))
xH(4)=(101.32-PO(4))/(PH(4)-PO(4))
xH(5)=(101.32-PO(5))/(PH(5)-PO(5))
Best wishes
Torsten.

Plus de réponses (1)

John D'Errico
John D'Errico le 5 Mar 2015
Or, even simpler in one line for the solve, and one line each to define each of PO and PH...
PH = [101.3; 136.7; 197.3; 284.0; 456.0];
PO = [16.1; 23.1; 37.1; 57.9; 101.3];
xH = (101.32 - PO)./(PH - PO);
Learn to use vectors and arrays in MATLAB. Until then, you will find yourself writing far less efficient code, and spending far more time just writing the code.

Catégories

En savoir plus sur Chemistry dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by