error in fminbnd and in my live function

1 回表示 (過去 30 日間)
Kyle
Kyle 2022 年 10 月 18 日
編集済み: Torsten 2022 年 10 月 19 日
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 Center および File ExchangeMATLAB についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by