Sum the solution of solve function
Mostra commenti meno recenti
Dear friends,
When solving a system of equations by using S=solve()
I got this kind of result
S =
z11: [1x1 sym]
z12: [1x1 sym]
z13: [1x1 sym]
z21: [1x1 sym]
z22: [1x1 sym]
z23: [1x1 sym]
z31: [1x1 sym]
z32: [1x1 sym]
z33: [1x1 sym]
I would like to find the sum of S.
However it cant be done with sum(S) because: Undefined function or method 'sum' for input arguments of type 'struct'
I can do that manually by first, displaying the solutions, S=[S.z11 S.z12 S.z13 S.z21 S.z22 S.z23 S.z31 S.z32 S.z33] after that, I can finally use sum(S) to get the sum of S.
However, I found this is not practical when I have a huge number of solutions in S.
Is there any other way to get the sum of S? Any help will be greatly appreciated.
Thank you very much.
Sincerely,
Leonardo
Risposta accettata
Più risposte (2)
Leonardo
il 23 Feb 2012
Bjorn Gustavsson
il 23 Feb 2012
I can't get Walter's solution to work in my version of matlab (7.8.0.347 (R2009a)). There S is a sym object, and then this works:
S = solve('(x-x1)*(x-x2)*(x-x3)=0');
sum(S)
ans =
x1 + x2 + x3
What versions are you using?
1 Commento
Leonardo
il 23 Feb 2012
Categorie
Scopri di più su Common Operations in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!