Minimizing a function of two variables

21 visualizzazioni (ultimi 30 giorni)
Bashayer AlKandari
Bashayer AlKandari il 22 Dic 2020
Hello there,
I appreciate your assistance in minimizing the following function with respect to t and w
{(tw(k-1)(t-1)-(k-1) t^2+(w-1) t^3-w)/(tw(t-1)^2 (w-1) )+(w(t-1)-t)/(tw(t-1)^2 (w-1) )+(k-1)[w(w-1) (t-1)^2+1]/(w^2 (t-1)^4 (w-1)^2 (tw-t-w) )}^k
Also I would like to find the values of t and w that minimize the function when k=2,3,4,...,10
the variables t and w are between 0 and 1
k if a fixed integer

Risposte (1)

John D'Errico
John D'Errico il 22 Dic 2020
Modificato: John D'Errico il 22 Dic 2020
First, LEARN TO USE MATLAB SYNTAX. That is, when you write an exprtession, learn to use MATLAB syntax when you write an expression. That makes it that much easier to write your own code. It also makes it that much easier for someone to help you! Why do you want to make it more difficult to solve a problem?
That is, learn to use * between variables to indicate multiplication. If things will be vectorized, then learn to use .* as the multiplication operator.
Next, learn to use parens. NOT {} in expressions. {} indicates you are creating a cell array! It also makes your code impossible to execute. Also [] is another construct where () is better to use, even though [] MAY succeed in your code.
LEARN MATLAB SYNTAX.
k = 2;
z = @(t,w) ((t.*w.*(k-1).*(t-1)-(k-1).*t.^2+(w-1).*t.^3-w)./(t.*w.*(t-1).^2.*(w-1))+(w.*(t-1)-t)./(t.*w.*(t-1).^2.*(w-1))+(k-1).*(w.*(w-1).*(t-1).^2+1)./(w.^2.*(t-1).^4.*(w-1).^2.*(t.*w-t-w))).^k;
fsurf(z,[0 1 0 1])
xlabel t
ylabel w
Next, plot EVERYTHING. Think about what you see.
So it looks like a singularity at t == 1.
fsurf(z,[0 .9 0 1])
xlabel t
ylabel w
As well as singularities at w=0 and w=1.
And all that for only k == 2. Sigh.
Easy enough to minimize with any minimizer that handles bound constraints. I'll use my own fminsearchbnd, found on the file exchange for free download.
fun = @(tw) z(tw(1),tw(2));
[twmin,fval] = fminsearchbnd(fun,[.5 .5],[0 0],[1 1])
twmin =
0.191401225235301 0.738702112421878
fval =
4.06564906554573e-15
fmincon would work as well, of course. The flatness of the objective would suggest it is better to take the log of your function, and to minimize that.
logz = @(t,w) log(z(t,w));
fsurf(logz,[0 1 0 1])
xlabel t
ylabel w
And that should teach you something highly important! It seems like there is a crease in the function, probably where it is zero along since path through the (t,w) plane. This suggests there is no unique minimum, but that z may be zero along some smooth path, giving you the same value at any such point along that path. Closer examination of the function itself would probably teach you the same thing.
So, first, learn MATLAB. Next, PLOT EVERYTHING. THINK ABOUT WHAT YOU SEE.

Community Treasure Hunt

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

Start Hunting!

Translated by