How to resolve this error?

4 ビュー (過去 30 日間)
Austin Hogan
Austin Hogan 2023 年 2 月 7 日
コメント済み: Les Beckham 2023 年 2 月 7 日
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 件のコメント
Fifteen12
Fifteen12 2023 年 2 月 7 日
It looks like you didn't include all your code--the problem likely stems from how you're calling the function Deflection_Function_with_Target, look inside your How_To_Code_Bisection_Method_020123 function. If you need help with this (it looks like a class project), post that code and walk us through the problem you're seeing and what you've tried so far. We'd love to help!
Les Beckham
Les Beckham 2023 年 2 月 7 日
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 ","

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2023 年 2 月 7 日
@(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.

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by