FMINUNC cannot continue help?

I am trying to learn how to use fminunc, but it gives the error "Failure in initial objective function evaluation. FMINUNC cannot continue."
Help please?
Note: Updated
for i = 1:modes
params.x0 = [y0 dy0];
params.xp = xspan;
fobj = @(beta)myobj(beta, params);
for j = 1:1000 % begin convergence loop for beta
beta = fminunc(fobj, beta0); % run optimization
end % end convergence loop
end
%%
function [err, T, Y] = myobj(beta)
x0 = params.x0;
xspan = params.xp;
[T,Y] = ode45('ffunc', xspan, x0);
err = abs(Y(end,2) + sqrt(K*L.^2 - beta)*Y(end,1)); % error
end

 採用された回答

Matt J
Matt J 2019 年 10 月 25 日
編集済み: Matt J 2019 年 10 月 25 日

0 投票

You forgot to pass your params,
fobj = @(beta)myobj(beta,params);
function [err, T, Y] = myobj(beta,params)
x0 = params.x0;
xspan = params.xp;
[T,Y] = ode('ffunc', xspan, x0);
err = abs(Y(end,2) + sqrt(K*L.^2 - beta)*Y(end,1)); % error
end

4 件のコメント

EB
EB 2019 年 10 月 25 日
Oh, how rookie of me.
However, I still get the same error when I try to use the fminunc function.
Matt J
Matt J 2019 年 10 月 25 日
Well, you should use
>>dbstop if caught error
to trap it.
EB
EB 2019 年 10 月 25 日
It just says fobj used twice, but that is correct because I need to state my fobj, then use it for the next part.
EB
EB 2019 年 10 月 25 日
Still the same error.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

製品

タグ

質問済み:

EB
2019 年 10 月 25 日

編集済み:

EB
2019 年 10 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by