Why won't the arrays I make work in the functions I created where I need to find pressure?
10 次查看(过去 30 天)
显示 更早的评论
I need to find pressure but the arrays won't plug into my functions as I keep getting D = 0. Is there any ways to fix this? Thanks!
%% Calculating Pressure
% Gives 201 values
for x = 0:30000:6000000
% calculates the dome height at every x value
D = calc_dome_height(x);
% for every x value get all the verticle locationso
for z = 0 : 50 : 10000
% calculates the reference temperature
ref_T = calc_ref_temp(z,D);
% calculates the reference pressure
ref_P = calc_ref_pressure(z,D);
% calculates the pressure
p = calc_pressure(ref_P,ref_T,z,D);
end
end
function [D] = calc_dome_height(x)
if x < 1000000
D = 0;
elseif (1000000 <= x) && (x <= 5000000)
D = 5000 .* sin((pi/4000000).*(x - 1000000));
elseif x >= 5000000
D = 0;
end
end
function [temp_c] = calc_cold_temp(z, D)
temp_c = 300 - (0.004 - -0.007) .* D - -0.007* z;
end
function [ref_T] = calc_ref_temp(z, D)
if z <= D
ref_T = 300;
elseif z > D
ref_T = 300 - (0.004 .* D);
end
end
function [ref_P] = calc_ref_pressure(z,D)
if z <= D
ref_P = 1000;
elseif z > D
temp_c = calc_cold_temp(D,D);
ref_P = 1000* ((temp_c/300)^(9.81/(287*-0.007)));
end
end
function [pressure] = calc_pressure(ref_P, ref_T, z, D)
if z <= D
temp_c = calc_cold_temp(z,D);
pressure = ref_P * ((temp_c / ref_T)^(9.81/(287 * -0.007)));
elseif z > D
temp_w = calc_warm_temp(z);
pressure = ref_P * ((temp_w / ref_T)^(9.81/(287* 0.004)));
end
end
2 个评论
Torsten
2023-10-19
What exactly do you mean ? As you can see, D is not always equal to 0.
iter = 0;
for x = 0:30000:6000000
% calculates the dome height at every x value
iter = iter + 1;
D(iter) = calc_dome_height(x);
end
plot(1:iter,D)
function [D] = calc_dome_height(x)
if x < 1000000
D = 0;
elseif (1000000 <= x) && (x <= 5000000)
D = 5000 .* sin((pi/4000000).*(x - 1000000));
elseif x >= 5000000
D = 0;
end
end
回答(2 个)
Walter Roberson
2023-10-19
D = calc_dome_height(x);
That overwrites all of D for every iteration of the for loop, so at the end of the for loop, D is going to be whatever it was calculated to be for the last iteration. Which is going to e 0 because of the
elseif x >= 5000000
D = 0;
You are not recording each D as it is produced.
2 个评论
Walter Roberson
2023-10-19
I suggest you read https://www.mathworks.com/matlabcentral/answers/2032249-to-plot-1d-temperature-distribution-plot-versus-lenght-of-the-channel-of-the-fin#comment_2926184 with example code in the same thread.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!