fminbnd question, program doesn't work?

1 回表示 (過去 30 日間)
Joseph Percsy
Joseph Percsy 2013 年 4 月 5 日
This is what I have so far.
clear
x = -2:.01:4;
y = x.^2-2*x-4;
y=originlen(x);
plot(x,y)
pause % Press any key to continue
x1=input('Enter left hand endpoint of subinterval: ');
x2=input('Enter right hand endpoint of subinterval: ');
xmin = fminbnd('originlen',x1,x2)
ymin=originlen(xmin);
originlen is this
function d=originlen(x)
x=-2:0.01:4;
d=sqrt(x.^2+(x.^2-2*x-4).^2);
plot(x,d)
This is currently the error that I'm getting:
??? Operands to the and && operators must be convertible to logical scalar values.
Error in ==> fminbnd at 260 if ( (abs(p)<abs(0.5*q*r)) && (p>q*(a-xf)) && (p<q*(b-xf)) )
Error in ==> plotting at 12 xmin = fminbnd('originlen',x1,x2)
What I want the program to do is display the point on the parabola that is closest to the origin, (found by d(x)), and the minimum distance.

回答 (0 件)

カテゴリ

Help Center および File ExchangeModeling についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by