solve multiple equation in one variable
조회 수: 8 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
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]
s = solve(B)
Are you sure the system is correctly coded?
You might have missed to include p1 somewhere.
댓글 수: 2
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]
s = solve([B(1),B(3),B(4),B(5)]); % e.g.
p2 = double(s.p2)
p3 = double(s.p3)
p4 = double(s.p4)
p5 = double(s.p5)
or use
[A,b] = equationsToMatrix(B);
sol = double(A)\double(b)
which solves the system of 5 equations in 4 unknowns in the least-squares sense.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Assumptions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!