Error in function handle using fminsearch

7 ビュー (過去 30 日間)
Elianther
Elianther 2020 年 10 月 7 日
コメント済み: madhan ravi 2020 年 10 月 7 日
I'm trying to solve the following maximization problem:
The proposed code is the following:
clear;clc
st = [1.312,1.314,1.479,1.552,1.700,1.803,1.861,1.865,1.944,1.958,1.966, 1.997,...
2.006,2.027,2.055,2.063,2.098,2.14, 2.179,2.224,2.240,2.253, 2.270,2.272,...
2.274,2.301,2.301,2.359,2.382,2.382,2.426,2.434,2.435, 2.478,2.490,2.511,...
2.514,2.535,2.554,2.566,2.57, 2.586,2.629,2.633, 2.642,2.648,2.684,2.697,...
2.726,2.770,2.773,2.800,2.809,2.818,2.821, 2.848,2.88, 2.954,3.012,3.067,...
3.084,3.090,3.096,3.128,3.233,3.433, 3.585,3.585]; % Data
x0 = [1,1]; % Initial search
f = @(x)dPL(x, st); % Passing arguments
min = fminsearch(@f, x0); % Find minima
Where the function dPL is given by
function loglik = dPL(x, data)
mu = x(1); sigma = x(2);
loglik = length(data)*(log(mu) + 2*log(sigma) - log(sigma+1)) + sum(log(1 + data.^mu)) + (mu - 1)*sum(log(data)) - sigma*sum(data.^mu);
loglik = -loglik;
end
Nevertheless, I get the following error when executed:
Unrecognized function or variable 'f'.
Error in fminsearch (line 200)
fv(:,1) = funfcn(x,varargin{:});
Error in min_test (line 31)
min3 = fminsearch(@f, x0);
The dPL function works correctly:
>> dPL([3.86, 0.045], st)
ans =
49.0302
Any ideas? Thanks.
  2 件のコメント
Star Strider
Star Strider 2020 年 10 月 7 日
I gave you the same Answer in: Error in fminsearch (line 200)
madhan ravi
madhan ravi 2020 年 10 月 7 日
Elianther why did you ask the SAME question TWICE?? DON’T waste others time by asking the same question multiple TIMES.

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

採用された回答

madhan ravi
madhan ravi 2020 年 10 月 7 日
min3 = fminsearch(f, x0);
  2 件のコメント
Elianther
Elianther 2020 年 10 月 7 日
Thanks. It was a very silly mistake. Anyway, could you elaborate on why is not neccesary tu put the "@" symbol?
madhan ravi
madhan ravi 2020 年 10 月 7 日
編集済み: madhan ravi 2020 年 10 月 7 日
It was already put in f = @ why would you put it again? In that case y could use @(x) f(x).

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by