error in fminbnd and in my live function
2 views (last 30 days)
Show older comments
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
- Incorrect use of '=' in the live function
- error in fminbnd : x= xf; fx = funfcn(x, varargin{:})
How do i fix these errors?
0 Comments
Answers (1)
Torsten
on 18 Oct 2022
Edited: Torsten
on 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)
hmin = V/(1/3*pi*rmin^2)
function A = area(r,V)
A = pi*r*sqrt(r^2 + (V/(1/3*pi*r^2))^2); %+ pi*r^2;
end
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!