Solving system of two (non)-linear eqautions multiple times using a for loop
5 views (last 30 days)
Show older comments
Harm Gilsing
on 9 Sep 2022
Commented: Star Strider
on 11 Sep 2022
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
0 Comments
Accepted Answer
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
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
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.
.
2 Comments
More Answers (1)
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)
A_volute = W./(i.^2*rho*Omega^3*D^3*1.2e-8)
%Test for solution
(W*rho*A_volute)./(m_dot.^2*Omega*D) - 1.2e-8
m_dot./(rho*Omega*A_volute*D) - i
See Also
Categories
Find more on Numbers and Precision in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!