Help me figure out what the error is. This is the first time I use matlab. Optimization problem with thirteen variables.

My task is to solve the target function, which is the sum of the total costs of purchasing and using reactive power compensation devices in medium voltage electrical networks. I need to minimize it.
For now, conditionally, there should be a reactive power compensation device(PCD) on each load.
I have formed a target function from three variables (capital costs, costs of energy loss in the network and costs depending on the reliability of the system).
Since the third variable does not depend on the PCD, it can be ignored. I have divided the target function into two to find their minima. I'll shorten the calculations, the final function in the matlab looks like this:
function f=fun1_optim(x)
f(1) = 266.214+0.256*(x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)+x(9)+x(10)+x(11)+x(12)+x(13));
f(2) = 23.37*0.05*((sqrt(100^2+(90-x(1))^2))/(sqrt(3)*10^2)...
+(sqrt(150^2+(130-x(2))^2))/(sqrt(3)*10^2)...
+(sqrt(210^2+(180-x(3))^2))/(sqrt(3)*10^2)...
+(sqrt(300^2+(250-x(4))^2))/(sqrt(3)*10^2)...
+(sqrt(100^2+(90-x(5))^2))/(sqrt(3)*10^2)...
+(sqrt(600^2+(450-x(6))^2))/(sqrt(3)*10^2)...
+(sqrt(400^2+(390-x(7))^2))/(sqrt(3)*10^2)...
+(sqrt(100^2+(90-x(8))^2))/(sqrt(3)*10^2)...
+(sqrt(150^2+(130-x(9))^2))/(sqrt(3)*10^2)...
+(sqrt(180^2+(162-x(10))^2))/(sqrt(3)*10^2)...
+(sqrt(600^2+(450-x(11))^2))/(sqrt(3)*10^2)...
+(sqrt(500^2+(470-x(12))^2))/(sqrt(3)*10^2)...
+(sqrt(100^2+(90-x(13))^2))/(sqrt(3)*10^2));
and here is the error:
I sincerely don't understand what they want from me. Please help me.

Answers (1)

x0 = zeros(13,1);
lb = zeros(13,1);
ub = inf(13,1);
sol = fmincon(@fun1_optim,x0,[],[],[],[],lb,ub)
Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
sol = 13×1
1.0e-07 * 0.8139 0.7857 0.8161 0.8162 0.8139 0.7704 0.7988 0.8060 0.8081 0.8285
fun1_optim(sol)
ans = 30.9608
function F=fun1_optim(x)
f(1) = 0.256*(x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)+x(9)+x(10)+x(11)+x(12)+x(13));
f(2) = 23.37*0.05*((sqrt(100^2+(90-x(1))^2))/(sqrt(3)*10^2)...
+(sqrt(150^2+(130-x(2))^2))/(sqrt(3)*10^2)...
+(sqrt(210^2+(180-x(3))^2))/(sqrt(3)*10^2)...
+(sqrt(300^2+(250-x(4))^2))/(sqrt(3)*10^2)...
+(sqrt(100^2+(90-x(5))^2))/(sqrt(3)*10^2)...
+(sqrt(600^2+(450-x(6))^2))/(sqrt(3)*10^2)...
+(sqrt(400^2+(390-x(7))^2))/(sqrt(3)*10^2)...
+(sqrt(100^2+(90-x(8))^2))/(sqrt(3)*10^2)...
+(sqrt(150^2+(130-x(9))^2))/(sqrt(3)*10^2)...
+(sqrt(180^2+(162-x(10))^2))/(sqrt(3)*10^2)...
+(sqrt(600^2+(450-x(11))^2))/(sqrt(3)*10^2)...
+(sqrt(500^2+(470-x(12))^2))/(sqrt(3)*10^2)...
+(sqrt(100^2+(90-x(13))^2))/(sqrt(3)*10^2));
F = f(1) + f(2);
end

15 Comments

Error: File: fun1_optim.m Line: 18 Column: 1
This statement is not inside any function.
(It follows the END that terminates the definition of the function "fun1_optim".)
Error in fmincon (line 563)
initVals.f = feval(funfcn{3},X,varargin{:});
Caused by:
Failure in initial objective function evaluation. FMINCON cannot continue.
am I entering something wrong or not in the right place?
Remove the 18th line in the function fun1_optim file and run the code again.
Show the result of,
fun1_optim(x0)
Where should I insert this line at what point?
Deleting the 18th line in the fun1_optim function file did not help. The same mistake.
Where should I insert this line at what point?
Run this as standalone code. Run it anywhere where fun1_optim is visible to Matlab, and paste the result for us,
x0 = zeros(13,1);
lb = zeros(13,1);
ub = inf(13,1);
fun1_optim(x0)
The error is occurring in fun1_optim.m but you are showing us fun1_optim.mlx
I wonder if there is a precendence when calling, where there is a function and a live function with the same name.
Thank you for sharing that information, Walter.
However, in that case, when OP uses "fun1_optim" to call, shouldn't the function with .mlx extension be called?
Run this command and see where the file is located.
which fun1_optim.m -all

Sign in to comment.

Categories

Products

Release

R2023b

Asked:

on 27 Jan 2024

Commented:

on 1 Feb 2024

Community Treasure Hunt

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

Start Hunting!