How to resolve this error?

2 views (last 30 days)
Austin Hogan
Austin Hogan on 7 Feb 2023
Commented: Les Beckham on 7 Feb 2023
function f = Deflection_Function(x) % NAME THE FUNCTION
Beam_Length = 700; %lENGTH OF BEAM IN CM
Youngs = 50000; %YOUNG'S MODULUS IN kN/cm^2
MoI = 30000; % AREA MOMENT OF INERTIA IN cm^4
Dist_Load = 50; % DISTRIBUTED LOAD IN kN/cm
f = Dist_Load/(120.*Youngs.*MoI.*Beam_Length).*(-x.^5 + 2.*Beam_Length...
.^2.*x.^3 - Beam_Length.^4.*x); % INPUT THE DEFLECTION
% EQUATION AND ACCOUNT FOR A TARGET VALUE OF DEFLECTION
end
function f = Deflection_Function_with_Target(x,~) % NAME THE FUNCTION
Beam_Length = 700; %lENGTH OF BEAM IN CM
Youngs = 50000; %YOUNG'S MODULUS IN kN/cm^2
MoI = 30000; % AREA MOMENT OF INERTIA IN cm^4
Dist_Load = 50; % DISTRIBUTED LOAD IN kN/cm
f = Dist_Load/(120.*Youngs.*MoI.*Beam_Length).*(-x.^5 + 2.*Beam_Length...
.^2.*x.^3 - Beam_Length.^4.*x); % INPUT THE DEFLECTION
% EQUATION AND ACCOUNT FOR A TARGET VALUE OF DEFLECTION
end
Error using fzero>localFirstFcnEval
FZERO cannot continue because user-supplied function_handle ==>
@(fzero_start)Defelection_Function_with_Target(fzero_start<target) failed with the error below.
Undefined function 'Defelection_Function_with_Target' for input arguments of type 'logical'.
Error in fzero (line 305)
fx = localFirstFcnEval(FunFcn,FunFcnIn,x,varargin{:});
Error in How_To_Code_Bisection_Method_020123 (line 84)
fzero_root = fzero(fzero_fun,fzero_start);
  2 Comments
Les Beckham
Les Beckham on 7 Feb 2023
Looks to me like Defelection_Function_with_Target is being called like this
@(fzero_start)Defelection_Function_with_Target(fzero_start<target)
and the "<" should be a comma ","

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 7 Feb 2023
@(fzero_start)Defelection_Function_with_Target(fzero_start<target)
You are asking fzero to invoke a function Defelection_Function_with_Target and pass in to the function the logical result of comparing the scalar fzero_start to target .
The first problem is that it does not work because you do not define
Defelection_Function_with_Target
^
and instead define
Deflection_Function_with_Target
but if you fix that typing mistake then function Deflection_Function_with_Target is going to receive scalar true or false as its only input, and would calculate
f = Dist_Load/(120.*Youngs.*MoI.*Beam_Length).*(-x.^5 + 2.*Beam_Length...
.^2.*x.^3 - Beam_Length.^4.*x)
based on x being either 0 (false) or 1 (true).
There are only two possible outcomes from that, so it is not possible to estimated a gradient from it, so fzero will not be able to find a zero unless it just happens to pass in a value that returns false on the logical test.

Tags

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!