Why do I get repeated values for a variable when its parameters change with every iteration?
Show older comments
I have a code, and I was figuring out the equations to plug into my for loops, testing as I went. The initial run throughs were fine, yielding results that weren't quite correct, but were expected. Now, while I think I have my final equations, the variable that I would like to see is getting repeating values, and I do not know why.
In my code V3 should equal A2 times V2 times 1.1, all divided by A3. A3 is constant, but A2 and V2 change with every loop iteration. However V3 is getting repeating resutls.
Code Below
Thank You
clc;
clear all;
close all;
%Define variables
d1 = .05; %m
A1 = (pi/4)*d1^2;%m^2
d3 = .01; %m
A3 = (pi/4)*d3^2;%m^2
d2 = (0.1:.1:0.5).*d1;%m
A2 = (pi/4)*d2.^2;%m^2
L = 0.5; %m
h = 3; %m
rho = 1000; %kg/m^3
Pt = [500 750 1000].*1000; %Pa gauge
g = 9.81; %m/s^2
%Preallocation Matrices
Vave = zeros();%m/s
Ptube = zeros();%Pa
V3 = zeros();%m/s
V1 = zeros();%m/s
V2 = zeros();%m/s
%Loop to iterativly calculate Vave, Ptube, V2, and V3
for j = 1: length(Pt)
for k = 1:length(d2)
Vave(j,k) = sqrt((Pt(j)*A1 +rho*g*h*A1)/((((rho*A1)/2)+...
((0.002*rho)/2)*(2*pi*(d1/2)*L)+2*pi*(d1/2)^2)));
Ptube(j,k) = Pt(j) + rho*g*h-(rho*0.002*Vave(j,k).^2)/2;
V2(j,k) = (A1*Vave(j,k))./(A2(k)*(.1+1));
V3(j,k) = (A2(k).*V2(j,k)*(1.1))/A3;
end
end
plot(V3, d2);
xlabel('Nozzle Velocity (m/s)');
ylabel('Pump Jet Nozzle diameter (m)');
legend('Pt = 500kPa', 'Pt = 750kPa', 'Pt = 1000kPa', 'location', 'southeast');
Accepted Answer
More Answers (0)
Categories
Find more on Timing and presenting 2D and 3D stimuli 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!