Code error trying to find the max h

2 次查看(过去 30 天)
Code not running fully. Continuous errors in code. I am trying to find the maximum h given f1, the other equations and other variable limitations.
% Variables
h = 10:0.01:16;
r = 14:0.01:22.13;
I = (pi*(r*2).^4)/(64);
P = ((4/3)*pi*(r.^3-(r-0.0127).^3)*7800*9.8)+((4/3)*pi*((r-0.0127).^3)*1000*9.8);
Pcr = (((pi)^2)*206*10^9*I)./(4*h.^2);
z = P <= Pcr/2;
f1 = -1*(h+2*r);
figure;
plot(r, h, 'o-');
xlabel('Radius');
ylabel('Height');
title('Problem 4i');
grid on;
  2 个评论
Matt J
Matt J 2023-9-20
编辑:Matt J 2023-9-20
It would be clearer if the optimization problem was described using mathematical expressions rather than code. As posted above, we don't really know what you intend as an equation and what you intend as a code operation.
Briana Canet
Briana Canet 2023-9-20
Here is the mathematical expressions!

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2023-9-20
You have I divided by h where I is the size of r. But r and h are row vector of different lengths.
If each h has a corresponding r then make them the same length.
If r and h are varying independently and you want to find the best combination then make one a column vector instead of a row vector and switch to a 3d plot or contour plot instead of a line plot

类别

Help CenterFile Exchange 中查找有关 Direct Search 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by