I am trying to solve a system of equations for each of the 500 elements in the "mass" vector and return vectors for all the solutions. I wrote a for loop to calculate and save the solutions for all the mass values but the script is taking way too long to run.
Is there a quicker/more efficient way to go about this?
rho = 1000;D = 8e-3;h = 28e-3;mass = (1e-3):(1e-3):(500e-3);g = 9.81;volFlow = zeros(500,0);massFlow = zeros(500,0);V1 = zeros(500,0);V2 = zeros(500,0);for i = 1:500% Equations
syms w1 w2 mdot Q eqn1 = (1/2)*rho*w1^2 == (1/2)*rho*w2^2+rho*g*h; eqn2 = mass(i)*g == w2*mdot; eqn3 = Q == (pi/4)*D^2*w2; eqn4 = mdot == rho*Q;% Solve system of equations
sol = solve([eqn1,eqn2,eqn3,eqn4], [w1,w2,mdot,Q]); Q = double(sol.Q); w1 = double(sol.w1); w2 = double(sol.w2); mdot = double(sol.mdot);% Solver returns positive and negative value for each, only need positive
Q = max(Q); w1 = max(w1); w2 = max(w2); mdot = max(mdot);% Add solver solution to vectors
volFlow(i) = Q; massFlow(i) = mdot; V1(i) = w1; V2(i) = w2;end
Best Answer