Solving system of two (non)-linear eqautions multiple times using a for loop

5 views (last 30 days)
I want to solve a system of two equations and two unknows (m and A). However. the right side of the second equation is a integer, which I would like to change with every iteration in the for loop. Doing so with every iteration two equations appear and two new unknowns to solve.
The vectors m_dot and A_volute have the solutions, however when I fill in the solutions in the second equation it is not right.
Does anyone know what I am doing wrong?
%% constants
rho = 1.3;
D = 0.126;
%% choose
W = 2600
RPM = 6000
Omega = RPM*((2*pi)/60);
%% solve
m_dot = [];
A_volute = [];
for i = 1500:1000:4500
syms m A
E = [(W*rho*A)/(m^2*Omega*D) == 1.2e-8 , m /(rho*Omega*A*D) == i];
S = solve(E,m,A);
m_dot = [m_dot, S.m];
A_volute = [A_volute, S.A];
end

Accepted Answer

Star Strider
Star Strider on 9 Sep 2022
I am not certain what the problem is, however putting square brackets [] around the variables you want to solve for may do what you want —
%% constants
rho = 1.3;
D = 0.126;
%% choose
W = 2600
W = 2600
RPM = 6000
RPM = 6000
Omega = RPM*((2*pi)/60);
%% solve
m_dot = [];
A_volute = [];
for i = 1500:1000:4500
syms m A
E = [(W*rho*A)/(m^2*Omega*D) == 1.2e-8 , m /(rho*Omega*A*D) == i];
S = solve(E,[m,A])
m_dot = [m_dot, S.m]
A_volute = [A_volute, S.A]
end
S = struct with fields:
m: 3929008913747544817795072/(17273615680981667385*pi^2) A: 75557863725914323419136/(16323566818527675678825*pi^3)
m_dot = 
A_volute = 
S = struct with fields:
m: 3929008913747544817795072/(28789359468302778975*pi^2) A: 75557863725914323419136/(45343241162576876885625*pi^3)
m_dot = 
A_volute = 
S = struct with fields:
m: 3929008913747544817795072/(40305103255623890565*pi^2) A: 75557863725914323419136/(88872752678650678695825*pi^3)
m_dot = 
A_volute = 
S = struct with fields:
m: 3929008913747544817795072/(51820847042945002155*pi^2) A: 75557863725914323419136/(146912101366749081109425*pi^3)
m_dot = 
A_volute = 
Consider using either vpa (results are numerical however remain symbolic) or double (results can be used in code outside the Symbolic Math Toolbox) or both as necessary to rerurn the desired result.
.

More Answers (1)

Torsten
Torsten on 9 Sep 2022
%% constants
rho = 1.3;
D = 0.126;
%% choose
W = 2600;
RPM = 6000;
Omega = RPM*((2*pi)/60);
i = 1500:1000:4500;
%Solutions
m_dot = W./(i*Omega^2*D^2*1.2e-8)
m_dot = 1×4
1.0e+04 * 2.3046 1.3828 0.9877 0.7682
A_volute = W./(i.^2*rho*Omega^3*D^3*1.2e-8)
A_volute = 1×4
0.1493 0.0537 0.0274 0.0166
%Test for solution
(W*rho*A_volute)./(m_dot.^2*Omega*D) - 1.2e-8
ans = 1×4
1.0e-23 * 0 0.1654 0 -0.1654
m_dot./(rho*Omega*A_volute*D) - i
ans = 1×4
1.0e-12 * -0.2274 0 -0.4547 0.9095

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!