Hello,
I want to compute the max of a function on an interval [a,b].
For that I am using the function fminbnd as follows:
syms x;
f=sqrt(3-2sqrt(x)); a=0; b=1;
dfdx2=-abs(diff(f,2));
dfdx4=-abs(diff(f,4));
M2=-fminbnd(dfdx2,a,b);
M4=-fminbnd(dfdx4,a,b);
The derivatives are calculated just fine but for M2, I get the following error message:
??? Error using ==> fcnchk at 103
If FUN is a MATLAB object, it must have an feval method.
Error in ==> fminbnd at 183
funfcn = fcnchk(funfcn,length(varargin));
Error in ==> programme_test at 5
M2=-fminbnd(dfdx2,a,b);
What am I doing wrong ?

 採用された回答

Shashank Prasanna
Shashank Prasanna 2013 年 1 月 18 日
編集済み: Shashank Prasanna 2013 年 1 月 18 日

0 投票

Since you have created your objective function using symbolic variables, you need to convert them to function handles before you can use them to call FMINBND,
Try the following:
syms x;
f=sqrt(3-2*sqrt(x)); a=0; b=1;
dfdx2=-abs(diff(f,2));
dfdx4=-abs(diff(f,4));
F2 = matlabFunction(dfdx2)
F4 = matlabFunction(dfdx4)
M2=-fminbnd(F2,a,b);
M4=-fminbnd(F4,a,b);

2 件のコメント

James
James 2013 年 1 月 18 日
Thank you Benji :)
DR RAJVEER SINGH
DR RAJVEER SINGH 2021 年 11 月 30 日
function f = Pnl(r, a_0)
e = 1.6E-19 ; % Electron charge in Coulomb
m_e = 9.1E-31;% mass of electron in Kg
h = 6.626E-34;
hbar = h/(2*pi); % in eV.s
epsilon_0 = 8.854E-12; % in F/m
a_0 = (4*pi*epsilon_0*hbar^2)/(m_e*e^2); % Bohr radius
r_min = 0;
r_max = 100*a_0;
r_range = r_max-r_min;
r = linspace(r_min,r_max, 100);
x = r/a_0;
N = 1/(209952*sqrt(105*a_0.^3));
R = N*(x.^2).*(9072-1512*x+72*x.^2-x.^3).*exp(-x./6);
f = (4*pi*r.^2).*R.^2;
F = matlabFunction(Pnl);
end
Error :

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangePhysics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by