error in fminbnd and in my live function

2 vues (au cours des 30 derniers jours)
Kyle
Kyle le 18 Oct 2022
Modifié(e) : Torsten le 19 Oct 2022
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?

Réponses (1)

Torsten
Torsten le 18 Oct 2022
Modifié(e) : Torsten le 19 Oct 2022
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

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by