Filter löschen
Filter löschen

Finding maximum to a symbolic array inside an m-file

2 Ansichten (letzte 30 Tage)
Sander Hermanussen
Sander Hermanussen am 14 Dez. 2011
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?

Antworten (1)

Walter Roberson
Walter Roberson am 14 Dez. 2011
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 Kommentar
Sander Hermanussen
Sander Hermanussen am 14 Dez. 2011
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)

Melden Sie sich an, um zu kommentieren.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by