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
- Incorrect use of '=' in the live function
- error in fminbnd : x= xf; fx = funfcn(x, varargin{:})
How do i fix these errors?
0 个评论
回答(1 个)
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)
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!