I am writing a code to solve 5 simultaneous equations with 5 unknowns. I am using the function vpasolve, however the code takes 50 minutes to run. Is there a quicker way of solving the equations?

1 回表示 (過去 30 日間)
syms Qa_1 Q1_1 Q2_1 Q3_1 Q4_1;
eqn1 = (Qa_1 == Q1_1 + Q2_1 + Q3_1 + Q4_1);
eqn2 = (Qa_1^2/60.51 + Q1_1^2/0.8616 == 1.035/Q1_1 + 24.3/Qa_1);
eqn3 = (Qa_1^2/60.51 + Q2_1^2/1.346 == 1.321/Q2_1 + 16.57/Qa_1);
eqn4 = (Qa_1^2/60.51 + Q3_1^2/1.346 == 1.236/Q3_1 + 8.873/Qa_1);
eqn5 = (Qa_1^2/60.51 + Q4_1^2/1.346 == 1.044/Q4_1 + 1.619/Qa_1);
assume (Qa_1, 'real');
assume (Q1_1, 'real');
assume (Q2_1, 'real');
assume (Q3_1, 'real');
assume (Q4_1, 'real');
[sol_Qa_1, sol_Q1_1, sol_Q2_1, sol_Q3_1, sol_Q4_1] = vpasolve([eqn1, eqn2, eqn3, eqn4, eqn5], [Qa_1, Q1_1, Q2_1, Q3_1, Q4_1], [0 Inf; 0 Inf; 0 Inf; 0 Inf; 0 Inf])

採用された回答

Star Strider
Star Strider 2018 年 11 月 11 日
編集済み: Star Strider 2018 年 11 月 11 日
I would do this numerically, using fsolve. It requires a slight re-write of your equations to make them all implicit.
Example
syms Qa_1 Q1_1 Q2_1 Q3_1 Q4_1 real
eqn1 = (Qa_1 - (Q1_1 + Q2_1 + Q3_1 + Q4_1));
eqn2 = (Qa_1^2/60.51 + Q1_1^2/0.8616 - (1.035/Q1_1 + 24.3/Qa_1));
eqn3 = (Qa_1^2/60.51 + Q2_1^2/1.346 - (1.321/Q2_1 + 16.57/Qa_1));
eqn4 = (Qa_1^2/60.51 + Q3_1^2/1.346 - (1.236/Q3_1 + 8.873/Qa_1));
eqn5 = (Qa_1^2/60.51 + Q4_1^2/1.346 - (1.044/Q4_1 + 1.619/Qa_1));
Eqnsfcn = matlabFunction([eqn1, eqn2, eqn3, eqn4, eqn5], 'Vars',{[Qa_1, Q1_1, Q2_1, Q3_1, Q4_1]});
B0 = rand(1,5)*100;
[B,fval] = fsolve(Eqnsfcn, B0)
This was almost instantaneous. There are likely multiple roots, so experiment with different initial parameter estimates (here ‘B0’).
EDIT This version makes it easier to track the individual variable names:
Eqnsfcn = matlabFunction([eqn1, eqn2, eqn3, eqn4, eqn5], 'Vars',{Qa_1, Q1_1, Q2_1, Q3_1, Q4_1});
B0 = rand(1,5)*100;
[B,fval] = fsolve(@(b)Eqnsfcn(b(1),b(2),b(3),b(4),b(5)), B0)
  4 件のコメント
JS
JS 2018 年 11 月 12 日
Thank you, that's very helpful

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEquation Solving についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by