solve multiple equation in one variable

9 views (last 30 days)
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

Accepted Answer

Davide Masiello
Davide Masiello on 28 Oct 2022
Edited: Davide Masiello on 28 Oct 2022
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 Comments
Kalvin
Kalvin on 28 Oct 2022
Edited: Kalvin on 28 Oct 2022
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 on 28 Oct 2022
Edited: Torsten on 28 Oct 2022
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.

Sign in to comment.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!