how to solve simultaneous equations?

조회 수: 181 (최근 30일)
bsd
bsd 2011년 9월 6일
댓글: Sam Chak 2024년 4월 30일
Dear sir/madam,
I need to solve two simultaneous linear equations. How could I do this in matlab? Looking forward to hearing from you soon.
Thanking you, BSD
  댓글 수: 1
MUYIDEEN MOMOH
MUYIDEEN MOMOH 2019년 3월 24일
Question
3x+2y=12
4x+6y=18
Matlab code
A=[3, 2 ; 4, 6];
B=[12; 18];
sol=linsolve(A,B)

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

채택된 답변

Paulo Silva
Paulo Silva 2011년 9월 6일
Equations:
1x + 2y = 0
2x + 2y = 0
MATLAB code:
A = [1 2;2 2]
B = [0;0]
X = A\B

추가 답변 (4개)

Ishika Shivahre
Ishika Shivahre 2021년 3월 10일
x1+x2=1
0.718+y2 = 1
x1*P"= 0.718*86.8
x2*P2" = y2* 86.8
  댓글 수: 1
Walter Roberson
Walter Roberson 2024년 4월 30일
syms x1 x2 y2 P_dprime P2_dprime
eqn1 = x1 + x2 == 1
eqn1 = 
eqn2 = 0.718 + y2 == 1
eqn2 = 
eqn3 = x1 * P_dprime == 0.718*86.8
eqn3 = 
eqn4 = x2 * P2_dprime == y2 * 86.8
eqn4 = 
sol = solve([eqn1, eqn2, eqn3, eqn4], [x1, x2, y2, P_dprime])
sol = struct with fields:
x1: (1250*P2_dprime - 30597)/(1250*P2_dprime) x2: 30597/(1250*P2_dprime) y2: 141/500 P_dprime: (77903*P2_dprime)/(1250*P2_dprime - 30597)
That is as far as you can get. You have 4 equations in 5 variables, so you cannot solve for all of them simultaneously.

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


Yaavendra Ramsaroop
Yaavendra Ramsaroop 2021년 5월 4일
A=[3, 2 ; 4, 6];
B=[12; 18];
sol=linsolve(A,B)

KELVIN
KELVIN 2023년 6월 5일
편집: KELVIN 2023년 6월 5일
Step 1: Express your equations into an Augmented Matrix where each equation represents a row of that matrix (excluding the answers/ the value beyond "=" sign.), assign the matrix to a variable. Let say A.
Step 2: Form a column matrix of the answers/ values beyond the "=" sign. Assign the column matrix to another variable B.
Step 3: Compute the solution by 'linsolve()' function OR sipmly A\B=inverse(A)*B
Solution=linsolve(A,B)

SHRDRACK
SHRDRACK 2024년 4월 30일
편집: Walter Roberson 2024년 4월 30일
A=[3, 2 ; 4, 6];
B=[12; 18];
sol=inv(A)*B
enter in comand window
  댓글 수: 2
Walter Roberson
Walter Roberson 2024년 4월 30일
It is not recommended that you use inv() for this purpose; it is less precise then some of the alternatives.
A=[3, 2 ; 4, 6];
B=[12; 18];
sol=A\B
sol = 2x1
3.6000 0.6000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Sam Chak
Sam Chak 2024년 4월 30일
Hi @SHRDRACK, In my Grade 10 Math class, my teacher taught me this method of solving a system of linear equations. It's natural to use the inv() command when searching online for how to compute the inverse of a square matrix. Interestingly, even the professor who taught my Numerical Methods course never showed me the trick of Left Matrix Division using "A\b" like @Walter Roberson did.
A = [3, 2; 4, 6];
b = [12; 18];
% step 1
detA = det(A)
detA = 10
% step 2
adjA = adjoint(A)
adjA = 2x2
6.0000 -2.0000 -4.0000 3.0000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
% step 3
invA = (1/detA)*adjA
invA = 2x2
0.6000 -0.2000 -0.4000 0.3000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
% step 4
x = invA*b
x = 2x1
3.6000 0.6000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

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

카테고리

Help CenterFile Exchange에서 Particle & Nuclear Physics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by