solve multiple equation in one variable
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Davide Masiello
il 28 Ott 2022
Modificato: Davide Masiello
il 28 Ott 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]
s = solve(B)
Are you sure the system is correctly coded?
You might have missed to include p1 somewhere.
2 Commenti
Torsten
il 28 Ott 2022
Modificato: Torsten
il 28 Ott 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]
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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Assumptions in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!