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?

조회 수: 3 (최근 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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Equation Solving에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by