Solving linear system of equations

조회 수: 5 (최근 30일)
Rick
Rick 2015년 3월 5일
답변: John D'Errico 2015년 3월 5일
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;

채택된 답변

Torsten
Torsten 2015년 3월 5일
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.

추가 답변 (1개)

John D'Errico
John D'Errico 2015년 3월 5일
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.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by