error in fminbnd and in my live function

1 次查看(过去 30 天)
i have to find the minimum Radius and Area using two equations:
V = 1/3 * pi*r^2*h and A = pi*r*sqrt(r^2 + h^2)
first i had to find area without using h, so i solved V for h, then substituted
A = pi*r*sqrt(r^2 + V/((1/3)*pi*r^2))
I then had to make a live function detailing this, using V as a global V
function A = area
global V = 10 % constant volume in in^3
r = radius; % changing radius in inches
A = pi*r*sqrt(r^2 + V/((1/3)*pi*r^2));
end
my next step was to find the minimum r and area
[rmin,Amin] = fminbnd(@area, 0.5, 5)
this got me two error messages
  1. Incorrect use of '=' in the live function
  2. error in fminbnd : x= xf; fx = funfcn(x, varargin{:})
How do i fix these errors?

回答(1 个)

Torsten
Torsten 2022-10-18
编辑:Torsten 2022-10-19
Don't you have to include the circular area G = pi*r^2 at the bottom ?
Then add pi*r^2 to A as indicated below.
V = 10; % constant volume in in^3
[rmin,Amin] = fminbnd(@(r)area(r,V),0,50)
rmin = 1.8901
Amin = 19.4393
hmin = V/(1/3*pi*rmin^2)
hmin = 2.6730
function A = area(r,V)
A = pi*r*sqrt(r^2 + (V/(1/3*pi*r^2))^2); %+ pi*r^2;
end

类别

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

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by