Inputting polynomial as parameter
이전 댓글 표시
Hi, newbie to MATLAB here, I currently get "Error using error Function is not defined for 'struct' inputs." I am wondering how to input a polynomial function into bisect2 (and fcnchk) properly. Appreciate any help!
function [x, out] = bisect2(FunFcnIn, Intv, params)
TOL = params.tol;
NO = params.MaxIt;
[FunFcn,msg] = fcnchk(FunFcnIn,0);
if ~isempty(msg)
error('InvalidFUN',msg);
end
...
댓글 수: 1
KSSV
2017년 9월 5일
Where is this function bisect2 ?
답변 (1개)
Steven Lord
2017년 9월 5일
The second output of fcnchk is a struct array. The error function can accept a struct array like that second output of fcnchk OR it can accept an error message string. Don't combine the two, it won't work.
function [x, out] = bisect2(FunFcnIn, Intv, params)
TOL = params.tol;
NO = params.MaxIt;
[FunFcn,msg] = fcnchk(FunFcnIn,0);
if ~isempty(msg)
error(msg);
end
To confirm that this works, run this code. You will receive an error.
bisect2(1:10, 1, struct('tol', 1, 'MaxIt', 2))
Alternately, just let fcnchk throw the error itself.
function [x, out] = bisect2(FunFcnIn, Intv, params)
TOL = params.tol;
NO = params.MaxIt;
FunFcn = fcnchk(FunFcnIn,0);
And again, check:
bisect2(1:10, 1, struct('tol', 1, 'MaxIt', 2))
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!