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!