How does the fcn2optimexpr() really work, for non-linear expressions. Confused.

3 views (last 30 days)
Hi,
I am have an non linear equation problem, in which I am using the problem based approuch. I have gotten solutions, but some of the solutions where just awkward. I have found where the error can be be. It lies in the calls to to fcn2optimexpr().
So little of my code.
This function below creates the non-linear equations.
function [Pkj_expr,Qkj_expr] = PowerFlow_func(U,Theta,G,B,Nodes)
%power flows in the system
for m = 1:length(Nodes)
for n = 1:length(Nodes)
Pkj_expr(m,n) = U(m)*U(n)*(G(m,n)*cos(Theta(m)-Theta(n))+B(m,n)*sin(Theta(m)-Theta(n)));
Qkj_expr(m,n) = U(m)*U(n)*(G(m,n)*sin(Theta(m)-Theta(n))-B(m,n)*cos(Theta(m)-Theta(n)));
end
end
end
Then in my main code I use the func2optimexpr() to form the non-linear constrain. Then I sum rows of Pkj and Qkj. See code below.
[Pkj_expr, Qkj_expr] = fcn2optimexpr(@PowerFlow_func,U,Theta,G,B,Nodes);
Flow_P_eq = Pkj == Pkj_expr;
Flow_Q_eq = Qkj == Qkj_expr;
for tt = 1:length(Nodes)
P_Injected_eq(tt) = Pk(tt) == sum(Pkj(tt,:));
Q_Injected_eq(tt) = Qk(tt) == sum(Qkj(tt,:));
end
When I solve the problem. I get follwowing
% Equation problem has bound constraints. Reformulating as a least squares problem.
%
% Solving problem using lsqnonlin.
%
% Equation solved, inaccuracy possible.
%
% lsqnonlin stopped because the vector of function values is near zero, as measured by the value
% of the function tolerance. However, the last step was ineffective.
%
% <stopping criteria details>
So the problem is solved. With inaccuracy. When I investigate the soltuion, it seem resonable, until I inspect the sol.Pkj and sol.Qkj variables. These are unrealistic. So the question, is how to obtain correct expression from the func2optimexpr().
Cheers!

Answers (0)

Categories

Find more on Get Started with Optimization Toolbox in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!