Hi, I am trying to find use the fminbnd function to find the minimum and maximum values of a function.
I am getting these errors when I try and use the fminbnd function in my code:
Error using fcnchk (line 106): FUN must be a function, a valid character vector expression, or an inline function object
and
Error in fminbnd (line 194): funfcn = fcnchk(funfcn,length(varagin));
Here is my code
x=-10:.0001:10
f = (2+(x-1.45).^2)./(3+3.5.*(.8.*x.^2-.6.*x+2))
minusf=-1.*f
[xmin,y]=fminbnd(f,-10,10) *(THIS IS THE LINE THAT THE ERROR APPEARS AT)*
[xmax,y2]=fminbnd(minusf,-10,10)
fmin=f(xmin)
fmax=f(xmax)

댓글 수: 1

James Robinson
James Robinson 2017년 12월 5일
Any help will be greatly appreciated!! Thanks in advance!

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

 채택된 답변

Walter Roberson
Walter Roberson 2017년 12월 5일

0 개 추천

You have a discrete system. You can just search for its extremes directly.
x=-10:.0001:10
f = (2+(x-1.45).^2)./(3+3.5.*(.8.*x.^2-.6.*x+2))
[fmin, minidx] = min(f);
xmin = x(minidx);
[fmax, maxidx] = max(f);
xmax = x(maxidx);
If you want to use a continuous system then:
f = @(x) (2+(x-1.45).^2)./(3+3.5.*(.8.*x.^2-.6.*x+2));
[xmin, fmin] = fminbnd(f, [-10 10]);
[xmax, fmax] = fminbnd(@(x) -f(x), [10 10]);

댓글 수: 3

James Robinson
James Robinson 2017년 12월 5일
I am required to use fminbnd, and when I tried your second suggestion there, it didn't work. It popped up the error message:
Error using fminbnd (line 98) FMINBND requires three input arguments.
Thanks for your help
f = @(x) (2+(x-1.45).^2)./(3+3.5.*(.8.*x.^2-.6.*x+2));
[xmin, fmin] = fminbnd(f, -10, 10);
[xmax, fmax] = fminbnd(@(x) -f(x), -10, 10);
fmax = -fmax;
James Robinson
James Robinson 2017년 12월 6일
That works! Thanks so much!

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Communications Toolbox에 대해 자세히 알아보기

태그

질문:

2017년 12월 5일

댓글:

2017년 12월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by