Optimizing 1 equation with 7 variables

4 Ansichten (letzte 30 Tage)
Pelajar UM
Pelajar UM am 20 Sep. 2021
Bearbeitet: Pelajar UM am 20 Sep. 2021
I have the following function:
f= (a^2/x^2)-((a*(2*b))/x^2)+(2*(b^2)/y^2)+((1/x^2)-(2/y^2))*b^2+((2*(2*d)^2)/s^2)+(((y^2)^-1)-(4*x^2)^-1)*((2*z)^2);
Unrecognized function or variable 'a'.
I want to find all possible combinations of a,b,d,s,x,y,z for which f = 1 subject to the following constraints:
y<2*x
0=< a,b,d,s,x,y,z <= 1
I keep getting the "not enough input arguments" error when I try to run fmincon. Is this even a valid problem or it's too broad?

Akzeptierte Antwort

John D'Errico
John D'Errico am 20 Sep. 2021
Bearbeitet: John D'Errico am 20 Sep. 2021
You do understand this is likely impossible to do?
If there are ANY solutions which satisfy the given equality, then there are almost certainly infinitely many solutions. So finding ALL such solutions will take an infinitely long time to perform.
We can probably even show there are infinitely many solutions too. For example...
syms a b d s x y z
f = 1;
eqn = (a^2/x^2)-((a*(2*b))/x^2)+(2*(b^2)/y^2)+((1/x^2)-(2/y^2))*b^2+((2*(2*d)^2)/s^2)+(((y^2)^-1)-(4*x^2)^-1)*((2*z)^2) - f;
Now, we can search for one such solution. Does one exist? For example, suppose we set a=b=s=0.5. Now you want y < 2*x, so I'll pick values for x and t that satisfy that relationship. Say y = 0.5, and x = 0.3. Now look at what we get.
pretty(subs(eqn,[a,b,x,y,s],[.5 .5 .3 .5 .5]))
2 2 44 z 32 d + ----- - 1 9
This represents an ellipse in the plane, with variables d and z. It has center (0,0).
fimplicit(subs(eqn,[a,b,x,y,s],[.5 .5 .3 .5 .5]),[0 1 0 1])
axis equal
grid on
xlabel 'd'
ylabel 'z'
So as long as d is a little smaller than 0.2, then there are infinitely many solutions, all living on that ellipse. We can even solve for z as a function of d.
z_d = solve(subs(eqn,[a,b,x,y,s],[.5 .5 .3 .5 .5]),z)
z_d = 
We will choose only the positive root there, so the second one found. It can be written as:
vpa(z_d(2))
ans = 
And clearly that root will be real (for non-negative values of d) as long as d <= sqrt(1/32).
sqrt(1/32)
ans = 0.1768
So no, you cannot find ALL solutions. There is NO optimization tool that will do so. I could have chosen many sets of the variables, picking random values for them from the domain of interest. How about if we pick
a0 = rand()
a0 = 0.0905
b0 = rand()
b0 = 0.0418
d0 = rand()*.2
d0 = 0.0461
z0 = rand()
z0 = 0.7448
s0 = rand()
s0 = 0.9282
eqnsubs = subs(eqn,[a,b,d,z,s],[a0,b0,d0,z0,s0])
eqnsubs = 
fimplicit(eqnsubs,[0 1 0 1])
hold on
fimplicit(y == 2*x,[0 1 0 1],'r')
Here we see that anything below the red curve has y <= 2*x. So there will be infinitely many solutions, all of which lie along the blue curve for that set of random parameters.
I might also point out that I had to try multiple random values for a,b,d,s and z to find a set that had any solutions at all for x and y. There were many such sets of those parameters that failed to have solutions in the unit square, [0 1]X[0 1].
  1 Kommentar
Pelajar UM
Pelajar UM am 20 Sep. 2021
Bearbeitet: Pelajar UM am 20 Sep. 2021
Thanks. I understand that there are many solutions. Neverthless, there appears to be a pattern. I wonder how this could be further explored ...
syms a b d s x y z
f = 1;
eqn = (a^2/x^2)-((a*(2*b))/x^2)+(2*(b^2)/y^2)+((1/x^2)-(2/y^2))*b^2+((2*(2*d)^2)/s^2)+(((y^2)^-1)-(4*x^2)^-1)*((2*z)^2) - f;
fimplicit3(subs(eqn,[a,b,y,s],[.01837 .02188 .02889 .05333]),[0 0.1 0 0.1 0 0.1])
xlabel 'd'
ylabel 'x'
zlabel 'z'
fimplicit3(subs(eqn,[a,b,x,s],[.01837 .02188 .0234 .05333]),[0 0.1 0 0.1 0 0.1])
xlabel 'd'
ylabel 'y'
zlabel 'z'
fimplicit3(subs(eqn,[a,b,x,y],[.01837 .02188 .0234 .02889]),[0 0.1 0 0.1 0 0.1])
xlabel 'd'
ylabel 's'
zlabel 'z'

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Alan Weiss
Alan Weiss am 20 Sep. 2021
I think that you would have an easier time formulating your problem by using the problem-based approach.
However, if you really want to use the fmincon solver using its default syntax, you have to reformulate your problem so that there is just one optimization variable vector, typically called x, possibly along with other variables representing fixed parameters or data. See Writing Scalar Objective Functions and Passing Extra Parameters.
Alan Weiss
MATLAB mathematical toolbox documentation

Kategorien

Mehr zu Linear Programming and Mixed-Integer Linear Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by