Filter löschen
Filter löschen

Code error trying to find the max h

1 Ansicht (letzte 30 Tage)
Briana Canet
Briana Canet am 20 Sep. 2023
Beantwortet: Walter Roberson am 20 Sep. 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 Kommentare
Matt J
Matt J am 20 Sep. 2023
Bearbeitet: Matt J am 20 Sep. 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 am 20 Sep. 2023
Here is the mathematical expressions!

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 20 Sep. 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

Community Treasure Hunt

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

Start Hunting!

Translated by