MATLAB: Matrix Operations for Inputs as Function Handles

funtionsmatrix operations

Hi!
I want to minimize this function with respect to h.
f1 = @(h) integral((psitildasq.*((1 - psibar).^2)),(-40),40,'ArrayValued',true);
where,
psitildasq = @(t) (1/n^2)*sum((cos(x.*t))).^2 + (1/n^2)*sum((sin(x.*t))).^2;
psibar = @(t,h) sum(exp((b.*t.*h).^2))./n;
I consider h and t as scalars. x is my (1,n) vector of input variables and b is another (1,n) vector of inputs.
But when I give the command
[h,hval] = fminbnd(f1,0,3);
Matlab gives me the error
"Undefined function 'minus' for input arguments of type 'function_handle'"
I don't quite understand where I am doing the mistake.
I would be grateful to learn about a way to write the function in the correct way.

Best Answer

The problem is caused by this part of f1:
1 - psibar
You're subtracting the function handle psibar from 1, which to matlab does not mean anything. What you want to subtract from 1 is the result of calling psibar with some argument, so you need to pass these arguments to psibar. You'll have a similar error with
psitilidasq.* ...
where you're multiplying a function handle with something. Again you need to pass some arguments to the function.
Possibly, you meant f1 to be:
f1 = @(h, t) integral(psitildasq(t) .* (1 - psibar(t, h).^2), -40, 40, 'ArrayValued', true);