Question

I'm simply trying to find the exact minimum of a simple function in MATLAB. I've been experimenting with the use of built-in functions such as "fminbnd" and inline function definition, but I don't think I quite know what I'm doing.

My code is below. I want to find the x and y of Error's minimum.

clear all

A = 5;
tau = linspace(1,4,500); %Array of many tau values between 1 and 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, I can use the cursor when the function is graphed to get close (though not right at the point where it occurs (Threshold = 2.5), but there must be a method just to print the number to the window. So far I have tried:

fminbnd('Error', 'E0', 'E1')

And many other variants. Also tried using anonymous and inline function definitions with no luck.

Can anyone point me in the right direction? Feel foolish for being stuck with this simple problem... Any help greatly appreciated!

Was it helpful?

Solution

See fminbnd

You should try something like 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) is the function and the other arguments are the bounds. I did f=Error, x1=0 and x2=10.

Output:

x=2.5000

Another way is to save your error function in .m file. See the webpage above.

OTHER TIPS

I don't understand why you're using E0 and E1 as the limits of the range where the minimum should be found. Or am I misunderstanding something in your code?

Maybe if you have your function as a discrete collection of samples (as seems implied from your way of constructing it, error is going to be a matrix, I think), you could use the "min" command: http://www.mathworks.es/es/help/matlab/ref/min.html

Hope this helped!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top