clear %3015
clc
% Constants
R = 10; % in
L = 24; % in
W = 42.27; % lb
rho = 0.101; % lb/in^3
% Volume equation
syms t
V = (L * pi * R^2) + ((4/3) * pi * R^3) - (pi * (R - t)^2 * L) - ((4/3) * pi * (R - 1.5*t)^3);
eqn = V == W/rho;
% Solve for t
t_vals = roots(double(fliplr(coeffs(eqn))));
t_val = t_vals(t_vals > 0); % pick positive root
% Print wall thickness
fprintf("Cylindrical section wall thickness: %.4f in\\n", t_val);
fprintf("Hemispherical heads wall thickness: %.4f in\\n", 1.5 * t_val);
% Constants
R = 10; % in
S = 20000; % psi
E = 1; % joint/weld efficiency
t_cyl = t_val; % from Part A
t_sph = 1.5 * t_val; % from Part A
% Pressure range
P_range = linspace(100, 400, 100);
% Minimum required thickness
t_req_cyl = R * (exp(P_range * R / (S * E - P_range)) - 1);
t_req_sph = 0.5 * R * (exp(P_range * R / (2 * S * E - P_range)) - 1);
% Check if vessel can operate in pressure range
if all(t_req_cyl <= t_cyl) && all(t_req_sph <= t_sph)
fprintf("The pressure vessel can be operated in the range of 100 to 400 psi.\\n");
allowable_range = "100 to 400 psi";
else
fprintf("The pressure vessel cannot be operated in the range of 100 to 400 psi.\\n");
allowable_range = "N/A";
end
% Plot minimum required thickness vs pressure
figure;
hold on;
plot(P_range, t_req_cyl, 'b-', 'LineWidth', 2);
plot(P_range, t_req_sph, 'r-', 'LineWidth', 2);
plot([100, 400], [t_cyl, t_cyl], 'b--');
plot([100, 400], [t_sph, t_sph], 'r--');
ylim([0, max([t_req_cyl, t_req_sph, t_cyl, t_sph])]);
xlabel('Internal Pressure (psi)');
ylabel('Minimum Required Thickness (in)');
title('Minimum Required Thickness vs Internal Pressure');
legend('Cylindrical Section', 'Hemispherical Heads', 'Actual Cylindrical Thickness', 'Actual Head Thickness', 'Location', 'northwest');
....
我试图绘制壁厚与内部压力的关系图,但收到以下输出和错误:圆柱段壁厚:in\n半球形封头壁厚:in\n压力容器可以在100到400 psi的范围内操作。\n错误使用绘图矢量必须具有相同的长度。
P2(第52行)图中的错误([100,400],[t_cyl,t_cyl],'B--');
1条答案
按热度按时间6bc51xsx1#
1.-错误来自空的
t_val
t_val
为空,因为您调用fsolve
的方式不返回任何根。因此
t_val
为空,因为t_vals
也为空。修改的问题行:
对于这个特定的函数**,将有效根约束在范围**
[0 R]
内,则只有正(或空)根。2.-下面是您的其余代码:
3.-现在,您可以从这里开始添加所需的任何其他图形。