Finding maximum to a symbolic array inside an m-file

2 次查看(过去 30 天)
Hi everyone,
I'm using MATLAB to graphically display a model with three variables, L1, L2 and Psi. I have created the following function:
function d = dafstand(L1,L2)
%do a lot of stuff, with the result being a 1- or 2-dimensional complex vector, called x, containing a symbolic Psi
Now, for this variable x, I want to elementwise maximize x given a Psi between 0 and pi/2 (for example, using fminbnd with -x). When such a Psi is given, the complex part of the vector results to 0, and I would like to drop that using something like real(). Finally, I want to get the maximum element in x, such that the last line of the m-file would be:
d = max(x)
So that I can call from the command window:
ezsurf(@(L1,L2)(dafstand(L1,L2)),[0,1,0,1]
Can someone help me?

回答(1 个)

Walter Roberson
Walter Roberson 2011-12-14
If the symbolic formula are sufficiently complex, then fminbnd would not always be able to find the correct maximum, especially if there are discontinuities.
There is a possibility that you might find it more productive to solve() or fsolve() for the imaginary part being 0, since that is what you care about anyhow.
  1 个评论
Sander Hermanussen
Sander Hermanussen 2011-12-14
Actually, the answer never has a complex result, no matter what the input is. However, due to rounding errors, it always gives a +0.000i or 0.000i part.
Also, the answer is continous at least on the given interval of (0,pi/2).
I want to do something like the following:
x = matlabFunction(x);
[Psi,x]=fminbnd(@(Psi)(real(x(Psi))),0,pi/2);
This gives the following error:
??? Operands to the || and && operators must be convertible to
logical scalar values.
Error in ==> fminbnd at 315
if ( (fu <= fw) || (w == xf) )
Error in ==> dafstand at 27
[Psi,x]=fminbnd(@(Psi)(real(x(Psi))),0,pi/2)

请先登录,再进行评论。

产品

Community Treasure Hunt

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

Start Hunting!

Translated by