Hey guys, I am struggling with a rather easy mathematical problem:
I have a 3x2 Matrix, U = A\b gives me a solution with the minimal norm(U). But I want to have the maximum, where U(1,2,3) < 24000. Do you have an idea? Here is my code so far:
alpha = 12.34567;
dU = 1;
beta = [0 120 240];
A = [sind(beta(1)) sind(beta(2)) sind(beta(3)); cosd(beta(1)) cosd(beta(2)) cosd(beta(3))];
b = [tand(alpha) 1]';
% Rang = rank(A)
%
U = A\b

 Akzeptierte Antwort

VK_11
VK_11 am 1 Jun. 2017

0 Stimmen

I found a solution, but it's not giving the right answers...
Startwert = [1,1,1];
[Uopt,UZeiger] = fmincon(@(U) Ufunktion(U),Startwert,[],[],[],[],[],[],@(U) Nebenbed(U,UZeiger,Umax,alpha,beta),optimset('Display','off','Algorithm','active-set'));
UZeiger = -UZeiger;
% Lösung mit Numerischer Methodik
function[UZeiger] = Ufunktion(U)
UZeiger = sum(U);
end
% Analog werden die Nebenbedingungen als Funktion definiert
function[c,ceq] = Nebenbed(U,UZeiger,Umax,alpha,beta)
% die Gleichungsnebenbedingungen
ceq = [sind(beta(1))*U(1) + sind(beta(2))*U(2) + sind(beta(3))*U(3) - tand(alpha);
cosd(beta(1))*U(1) + cosd(beta(2))*U(2) + cosd(beta(3))*U(3) - 1;
];
% die Ungleichungsnebenbedingungen
c = UZeiger - 3*Umax; % U(2) - 24000;U(3) - 24000; % Maximalwerte der Spannung
end

9 Kommentare

Torsten
Torsten am 1 Jun. 2017
1. UZeiger and Umax are predefined values - so the inequality constraint is either satisfied or not. It does not influence the solution.
2. UZeiger= sum(U) is not adequate as objective function. Maybe you mean UZeiger = -sum(U.^2) ?
Best wishes
Torsten.
VK_11
VK_11 am 1 Jun. 2017
The inequality constrait is actually being ignored. How can I fix this? Basically I want the maximal magnitude of the combined vector of Z, but the single vectors of U can't be over 24000. How is UZeiger predefined? I thought, that this is the variable I try to maximize.
This is my code:
alpha = 30;
Umax = 5;
% dU = 1;
beta = [0 120 240];
% XzuY = tand(alpha);
% A = [sind(beta(1)) sind(beta(2)) sind(beta(3)); cosd(beta(1)) cosd(beta(2)) cosd(beta(3))];
%
% b = [tand(alpha) 1]';
% Rang = rank(A)
%
% U = A\b
% Das Maximierungsproblem wird nun durch folgende Eingaben gelöst:
Startwert = [1,-1,1];
[Uopt,UZeiger] = fmincon(@(U) Ufunktion(U,beta),Startwert,[],[],[],[],[],[],@(U) Nebenbed(U,Umax,alpha,beta),optimset('Display','off','Algorithm','active-set'));
UZeiger = -UZeiger;
Uopt
% Lösung mit Numerischer Methodik
function[UZeiger] = Ufunktion(U,beta)
Winkel = beta/180*pi;
Z = U .* exp(1i*Winkel);
Y = Z(1) + Z(2) + Z(3);
UZeiger = -abs(Y);
end
% Analog werden die Nebenbedingungen als Funktion definiert
function[c,ceq] = Nebenbed(U,Umax,alpha,beta)
% die Gleichungsnebenbedingungen
ceq = [sind(beta(1))*U(1) + sind(beta(2))*U(2) + sind(beta(3))*U(3) - tand(alpha);
cosd(beta(1))*U(1) + cosd(beta(2))*U(2) + cosd(beta(3))*U(3) - 1;
];
% die Ungleichungsnebenbedingungen
c = [abs(U(1)) - Umax; abs(U(2)) - Umax; abs(U(3)) - Umax;]; % Maximalwerte der Spannung
end
Torsten
Torsten am 1 Jun. 2017
Is this the problem you are trying to solve in a mathematical notation ?
max: x(1)^2 + x(2)^2 + x(3)^2
s.c.
x(1) <= 24000
x(2) <= 24000
x(3) <= 24000
sin(beta1)*x(1) + sin(beta2)*x(2) + sin(beta3)*x(3) = tan(alpha)
sin(beta1)*x(1) + sin(beta2)*x(2) + sin(beta3)*x(3) = 1
Best wishes
Torsten.
VK_11
VK_11 am 1 Jun. 2017
Basically it is, though x(1,2,3) are 3 komplex vectors.
The vector that x(1,2,3) add up to must be maximized and can't be over 72000.
So I think you could describe the problem as this:
max: magnitude(Y)
Y = x(1) + x(2) + x(3) <= 72000
x(m) = X * exp(i*beta(m))
beta = [0 120 240]
alpha = angle(Y)
alpha = 30
X(1,2,3) (the length of x(1,2,3)) is the parameter that can be modified to get a solution for Y.
Torsten
Torsten am 1 Jun. 2017
What does Y <= 72000 mean for Y being a complex number ?
VK_11
VK_11 am 2 Jun. 2017
Y is a complex number, it's magnitude must be smaller than 72000
Torsten
Torsten am 2 Jun. 2017
x(1)+x(2)+x(3) is not the magnitude of the vector x.
Sorry, but since I don't know the physical background of your problem, it seems that I'm not able to help you here.
Best wishes
Torsten.
VK_11
VK_11 am 2 Jun. 2017
I solved my problem! As always it is the most stupid mistake after all. I didn't transform alpha into radians therefore only getting bad results. Thanks a lot for your help!
Torsten
Torsten am 2 Jun. 2017
I wonder where in your code you needed alpha in radians since you used "tand".
Anyhow ...
Best wishes
Torsten.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Torsten
Torsten am 1 Jun. 2017

0 Stimmen

Use "fmincon".
Best wishes
Torsten.

2 Kommentare

VK_11
VK_11 am 1 Jun. 2017
Actually I already tried to use fmincon. Unfortunatly it can only be used for scalar values as far as I know. But I want three U to be maximized, or at least the length of the total vector.
Torsten
Torsten am 1 Jun. 2017
The length of the total vector is a scalar ...
Best wishes
Torsten.

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 1 Jun. 2017

Kommentiert:

am 2 Jun. 2017

Community Treasure Hunt

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

Start Hunting!

Translated by