Inputting polynomial as parameter
Afficher commentaires plus anciens
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 commentaire
KSSV
le 5 Sep 2017
Where is this function bisect2 ?
Réponses (1)
Steven Lord
le 5 Sep 2017
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))
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!