Search code examples
matlabnumeric

matlab system of equations with one unchanging solution ('q')


I am trying to solve a model of 4 equations, where everything is real. It is essentially a pipe branch problem with "1" being upstream of the pump (with some head on it), and "2" and "3" are downstream w/o head. The units are English.

Anyway, I'm just solving the system of 4 equations and 4 unknowns and looking at a plot of head (ha) vs. total flow rate (Q1). Across this space though I only am collecting points in a vertical line, i.e. the head changes but the flowrate doesn't.

I was thinking the problem may be some variables are being held onto, but I treat "ha" the same as "Q1" so that doesn't seem likely... Realistically, this is matching a system curve to a pump curve, and of course that point moves when the system changes (both flowrate and head), so it seems I am doing something wrong....

Here is the script:

clear sol1 sol2 sol3 sol4 S q h
clc; clearvars; close all;

syms Q1 Q2 Q3 ha

D1 = 1.25/12;      Z1 = 0;   P1 = 62.4*10;   A1 = pi*(1/4)*D1*D1;     f1 = 0.011; L1 = 50;
D2 = 0.5/12;       Z2 = 25;  P2 = 0;         A2 = pi*(1/4)*D2*D2;     f2 = 0.011; L2 = 100; %V2 = Q2 / A2;
D3 = 0.5/12;       Z3 = 10;  P3 = 0;         A3 = pi*(1/4)*D3*D3;     f3 = 0.011; L3 = 100; %V3 = Q3 / A3;

gamma = 62.468;

origPumpData = [0 150; 0.4 148; 0.8 145; 1.2 143; 1.6 141; 2 139; 2.4 138; 2.8 136; 3.2 134; 3.6 132; 4 130; 4.4 128; 4.8 127; 5.2 125; 5.6 124; 6 121; 6.4 118; 6.8 117; 7.2 115; 7.6 113; 8 111; 8.4 110; 8.8 108; 9.2 106; 9.6 104; 10 102; 10.4 100; 10.8 98; 11.2 97; 
11.6 94; 12.0 93; 12.4 91; 12.8 89; 13.2 87; 13.6 86; 14 84; 14.4 82; 14.8 80; 15.2 78; 15.6 76; 16 74; 16.4 72; 16.6 70];
pumpData(:,1) = origPumpData(:,1)/448.8312;
pumpData(:,2) = origPumpData(:,2);
polyFit = fit(pumpData(:,1),pumpData(:,2),'poly2');

assume(in(Q1,'real') & Q1 > 0.0001 & Q1 < 1 );
assume(in(Q2,'real') & Q2 > 0.0001 & Q2 < 1 );
assume(in(Q3,'real') & Q3 > 0.0001 & Q3 < 1 ) ;
assume(in(ha,'real') & ha > 0.0001 & ha < 1000.0);

eq1 = @(Q1) polyFit.p1*Q1*Q1 + polyFit.p2*Q1 + polyFit.p3;

eq2 = @(P1,Z1,F1,Q1,A1,L1,D1,P2,Z2,F2,Q2,A2,L2,D2) P1/gamma + ((Q1/A1)^2)/64.4 + Z1 - hf(F1,L1,D1,Q1,A1) - hf(F2,L2,D2,Q2,A2) + ha == P2/gamma + ((Q2/A2)^2)/64.4 + Z2;

eq3 = @(P1,Z1,F1,Q1,A1,L1,D1,P3,Z3,F3,Q3,A3,L3,D3) P1/gamma + ((Q1/A1)^2)/64.4 + Z1 - hf(F1,L1,D1,Q1,A1) - hf(F3,L3,D3,Q3,A3) + ha == P3/gamma + ((Q3/A3)^2)/64.4 + Z3;

eq4 = Q1 == Q2 + Q3;

guesses = [0.07116936917086152675558661517184;
0.035125850031368916048762418970837;
0.036043519139492610706824196201003;
303.02361035523126099594683749354];

for i = 1:1:2
    disp(i)
    disp(Z1)

    Z1 = Z1-5
    f1 = f1+0.01
    f3 = f3 + 0.01
    S(i) = vpasolve([eq1(Q1) eq2(P1,Z1,f1,Q1,A1,L1,D1,P2,Z2,f2,Q2,A2,L2,D2) eq3(P1,Z1,f1,Q1,A1,L1,D1,P3,Z3,f3,Q3,A3,L3,D3) eq4], [Q1 Q2 Q3 ha], guesses )
    S(i).Q1
    S(i).Q2
    S(i).Q3
    S(i).ha
    q(i) = S(i).Q1
    h(i) = S(i).ha
    guesses = [S(i).Q1 S(i).Q2 S(i).Q3 S(i).ha]'
    clear S 
end

plot( q, h, '*b');

function hf = hf(f,L,D,Q,A)
   hf = f*(L/D)*(1/64.4)*(Q/A)^2;
end

Solution

  • you're solving eq1 == 0(default) and computing Q1, independent of other equations and parameters. that's why you get constant Q1 in every iteration.