Local Minimum in MATLAB? -
i'm trying find exact minimum of simple function in matlab. i've been experimenting use of built-in functions such "fminbnd" , inline function definition, don't think quite know i'm doing.
my code below. want find x , y of error's minimum.
clear = 5; tau = linspace(1,4,500); %array of many tau values between 1 , 4 e1 = qfunc(((-tau) + 5) /(sqrt(2.5))); e0 = qfunc((tau)/(sqrt(2.5))); error = 0.5*e0 + 0.5*e1; figure subplot (311), plot(tau, e0); xlabel('threshold (tau)'), ylabel('e0') title('error vs. threshold (e0, 1 <= t <= 4)') subplot (312), plot(tau, e1); xlabel('threshold (tau)'), ylabel('e1') title('error vs. threshold (e1, 1 <= t <= 4)') subplot (313), plot(tau, error); xlabel('threshold (tau)'), ylabel('pr[error]'); title('error vs. threshold (pr[error], 1 <= t <= 4)')
i mean, can use cursor when function graphed close (though not right @ point occurs (threshold = 2.5), there must method print number window. far have tried:
fminbnd('error', 'e0', 'e1')
and many other variants. tried using anonymous , inline function definitions no luck.
can point me in right direction? feel foolish being stuck simple problem... appreciated!
see fminbnd
you should try this:
error =@(tau) 0.5*qfunc(((-tau) + 5) /(sqrt(2.5))) + 0.5*qfunc((tau)/(sqrt(2.5))); x = fminbnd(error,0,10)
the first argument of fminbnd(f,x1,x2) function , other arguments bounds. did f=error, x1=0 , x2=10.
output:
x=2.5000
another way save error function in .m file. see webpage above.
Comments
Post a Comment