Borrar filtros
Borrar filtros

Code error trying to find the max h

1 visualización (últimos 30 días)
Briana Canet
Briana Canet el 20 de Sept. de 2023
Respondida: Walter Roberson el 20 de Sept. de 2023
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 comentarios
Matt J
Matt J el 20 de Sept. de 2023
Editada: Matt J el 20 de Sept. de 2023
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 el 20 de Sept. de 2023
Here is the mathematical expressions!

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 20 de Sept. de 2023
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

Categorías

Más información sobre Direct Search en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by