How can I fix this error and what does mean by should return 1 or two arguments help pls
Ältere Kommentare anzeigen
% Check userfun
userFG = checkFun(userfun,'SNOPT','userfun');
gotDeriv = 0;
try
[F,G] = userFG(x);
gotDeriv = 1;
catch
try
F = userFG(x);
gotDeriv = 0;
catch
error('SNOPT:InputArgs','userfun should return 1 or 2 arguments');
end
end
Error
Error using snopt (line 318)
userfun should return 1 or 2 arguments
Error in Untitled2 (line 173)
[x, f, inform, xmul, fmul] = snopt(xg, xlwr, xupr, xmul, xstate, ...
Akzeptierte Antwort
Weitere Antworten (1)
Yongjian Feng
am 6 Sep. 2021
0 Stimmen
userFG shall return one or two arguments. You can see that the code tries to call userFG and retrieves two returns. If this call throws an exception, then it tries to call userFG and retrieve one retuen. If this also throws exception, then it errors out. So it expects one or two returns.
4 Kommentare
Mudrik Ahmed
am 6 Sep. 2021
Yongjian Feng
am 7 Sep. 2021
Bearbeitet: Yongjian Feng
am 7 Sep. 2021
So you have validation code and a userFG in discrepancy here basically.
Your validation code shown above requires that a userFG shall return one or two returns. But your userFG returned from the first line does not.
You need to fix this discrepancy.
- If a userFG indeed needs to return one or two returns, then check your userFG. It shall be something like
function ret1 = your_user_function(x)
% this function returns only one return
end
or
function [ret1, ret2] = your_user_function(x)
% this function returns two returns
end
Use the debugger to step into the first line `userFG = checkFun(userfun,'SNOPT','userfun');` to figure out what userFG is.
2. If a userFG is allowed to return something other than one or two returns then fix your validation code.
Mudrik Ahmed
am 7 Sep. 2021
Yongjian Feng
am 7 Sep. 2021
Great.
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!