solve multiple equation in one variable

조회 수: 8 (최근 30일)
Kalvin
Kalvin 2022년 10월 28일
편집: Torsten 2022년 10월 28일
syms p1 p2 p3 p4 p5
B = [(75*p2)/2 - (153*p3)/4 + (199*p4)/6 + (31*p5)/12 - 2165/12 == -433/36, 58*p2 - (89*p3)/2 + (457*p4)/9 + (127*p5)/18 - 4763/18 == -433/36, 38*p2 - (59*p3)/2 + (344*p4)/9 + (161*p5)/18 - 3031/18 == -433/36, 70*p2 - 81*p3 + (625*p4)/9 + (125*p5)/9 - 3031/9 == -433/36, (89*p2)/2 - (225*p3)/4 + (841*p4)/18 - (11*p5)/36 - 9959/36 == -433/36]
solve(b)
solx = [ans.p2 ans.p3 ans.p4 ans.p5]
i got 5 equation in B variable but when im trying to solve it. it always show
p2 = [0x1 sym]
p3 = [0x1 sym]
p4 = [0x1 sym]
p5 = [0x1 sym]
empty sym; 0 - by-4
is there any solution to solve that equation?
thank you

채택된 답변

Davide Masiello
Davide Masiello 2022년 10월 28일
편집: Davide Masiello 2022년 10월 28일
I think the problem is that you have 5 equations and 4 variables, because p1 does not appear anywhere in the system.
Therefore the system is overdetermined.
If I try to solve canceling the last equation it works, see below
syms p1 p2 p3 p4 p5
B = [(75*p2)/2 - (153*p3)/4 + (199*p4)/6 + (31*p5)/12 - 2165/12 == -433/36; 58*p2 - (89*p3)/2 + (457*p4)/9 + (127*p5)/18 - 4763/18 == -433/36; 38*p2 - (59*p3)/2 + (344*p4)/9 + (161*p5)/18 - 3031/18 == -433/36; 70*p2 - 81*p3 + (625*p4)/9 + (125*p5)/9 - 3031/9 == -433/36] % (89*p2)/2 - (225*p3)/4 + (841*p4)/18 - (11*p5)/36 - 9959/36 == -433/36]
B = 
s = solve(B)
s = struct with fields:
p2: 122537701/16461144 p3: -1231019/783864 p4: -1665751/304836 p5: 7365763/1829016
Are you sure the system is correctly coded?
You might have missed to include p1 somewhere.
  댓글 수: 2
Kalvin
Kalvin 2022년 10월 28일
편집: Kalvin 2022년 10월 28일
I see. So is there any command that can erase 1 equation from that variable? The p1 is missing because i need to substitude the p1 with another equation. Thats why i need to erase one equation from that variable.
Torsten
Torsten 2022년 10월 28일
편집: Torsten 2022년 10월 28일
syms p1 p2 p3 p4 p5
B = [(75*p2)/2 - (153*p3)/4 + (199*p4)/6 + (31*p5)/12 - 2165/12 == -433/36, 58*p2 - (89*p3)/2 + (457*p4)/9 + (127*p5)/18 - 4763/18 == -433/36, 38*p2 - (59*p3)/2 + (344*p4)/9 + (161*p5)/18 - 3031/18 == -433/36, 70*p2 - 81*p3 + (625*p4)/9 + (125*p5)/9 - 3031/9 == -433/36, (89*p2)/2 - (225*p3)/4 + (841*p4)/18 - (11*p5)/36 - 9959/36 == -433/36]
B = 
s = solve([B(1),B(3),B(4),B(5)]); % e.g.
p2 = double(s.p2)
p2 = -0.9168
p3 = double(s.p3)
p3 = -1.1433
p4 = double(s.p4)
p4 = 5.1320
p5 = double(s.p5)
p5 = -4.3249
or use
[A,b] = equationsToMatrix(B);
sol = double(A)\double(b)
sol = 4×1
0.8276 -0.6442 4.0401 -4.8917
which solves the system of 5 equations in 4 unknowns in the least-squares sense.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by