function Y = myFunc(P,P0)
N = 2;
Pa = 9;
k = floor((P0*N/Pa));
Y = F(P)+k*F(N*P0-P*k);
function Fp = F(P)
R = 3;
beta = 8;
Fp = 1 - exp(-((2^R-1)./P).^(beta/2));
%Step 2: Minimize it within the bounds:
P0 = 9;
[Pi, FVal] = fminbnd(@(x) myFunc(x,P0),0,7);
getting error: Error using myFunc (line 4)
Not enough input arguments.

 채택된 답변

Mischa Kim
Mischa Kim 2014년 1월 28일

0 개 추천

Hello Shobi, code looks fine. Make sure to save the two functions in one function file (called myFunc.m). Then execute the two final commands in the MATLAB command window:
P0 = 9;
[Pi, FVal] = fminbnd(@(x) myFunc(x,P0),0,7);

댓글 수: 10

shobi swaminathan
shobi swaminathan 2014년 1월 28일
which two functions.....
Youssef  Khmou
Youssef Khmou 2014년 1월 28일
편집: Youssef Khmou 2014년 1월 28일
hi, means the function called F is a subfunction of the main myFunc.
I mean, put
function Y = myFunc(P,P0)
N = 2;
Pa = 9;
k = floor((P0*N/Pa));
Y = F(P)+k*F(N*P0-P*k);
function Fp = F(P)
R = 3;
beta = 8;
Fp = 1 - exp(-((2^R-1)./P).^(beta/2));
in one function called myFunc.m.
shobi swaminathan
shobi swaminathan 2014년 1월 28일
After saving the code as myFunc.m if we run then the following error is shown
Error using myFun (line 4) Not enough input arguments
shobi swaminathan
shobi swaminathan 2014년 1월 28일
편집: shobi swaminathan 2014년 1월 28일
Then if we type
P0 = 7;
[Pi, FVal] = fminbnd(@(x) myFunc(x,P0),0,7); in the command window following error is shown
Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N) to change the limit. Be aware that exceeding your available stack space can crash MATLAB and/or your computer. Error in myFunc>F
Mischa Kim
Mischa Kim 2014년 1월 28일
편집: Mischa Kim 2014년 1월 28일
So it looks like it works (it works just fine on my machine). What MATLAB release are you working with?
What happens if you execute
[Pi, FVal] = fminbnd(@(x) myFunc(x,P0),0,1.1)
instead?
shobi swaminathan
shobi swaminathan 2014년 1월 28일
I am using matlab version 2013
Again error
Undefined function 'bs' for input arguments of type 'double'. Error in @(x)bs(x,P0)
Error in fminbnd (line 216) x= xf; fx = funfcn(x,varargin{:});
Mischa Kim
Mischa Kim 2014년 1월 28일
Sorry that was a typo: bs is supposed to be myFunc. Fixed in the above comment.
shobi swaminathan
shobi swaminathan 2014년 1월 28일
Thanks...we are getting the output....
But this code was taken from this website....
We are getting two values Pi and Fval Which one should we take it as minimum...what does Fval means
Mischa Kim
Mischa Kim 2014년 1월 28일
Pi is the x-value you are searching for, FVal is the function value that is minimized at x = Pi.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

shobi swaminathan
shobi swaminathan 2014년 1월 28일

0 개 추천

Thanks alot.. in the above code the value of P and P0 are fixed.. but in our problem the value of P
and P0 should be as follows
P0 varies from 1 to 10 and
P belongs to P1 such that P1= [0, Pb]∪ ((N*P0)/(k+1)). how to modify the above code to satisfy
these conditions

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

태그

Community Treasure Hunt

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

Start Hunting!

Translated by