Sum the solution of solve function
古いコメントを表示
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
採用された回答
その他の回答 (2 件)
Leonardo
2012 年 2 月 23 日
Bjorn Gustavsson
2012 年 2 月 23 日
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?
カテゴリ
ヘルプ センター および File Exchange で Common Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!