Help me figure out what the error is. This is the first time I use matlab. Optimization problem with thirteen variables.
Show older comments
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.
1 Comment
Torsten
on 27 Jan 2024
f must be one single value, not an array of two values (f(1) and f(2)).
Answers (1)
x0 = zeros(13,1);
lb = zeros(13,1);
ub = inf(13,1);
sol = fmincon(@fun1_optim,x0,[],[],[],[],lb,ub)
fun1_optim(sol)
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
Matt J
on 28 Jan 2024
Show the result of,
fun1_optim(x0)
Dyuman Joshi
on 28 Jan 2024
Remove the 18th line in the function fun1_optim file and run the code again.
Ivan
on 29 Jan 2024
Matt J
on 29 Jan 2024
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)
Walter Roberson
on 29 Jan 2024
The error is occurring in fun1_optim.m but you are showing us fun1_optim.mlx
Dyuman Joshi
on 30 Jan 2024
I wonder if there is a precendence when calling, where there is a function and a live function with the same name.
Walter Roberson
on 30 Jan 2024
mlx has precedence 6
p has precedence 7
m has precedence 8
Dyuman Joshi
on 30 Jan 2024
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?
Ivan
on 31 Jan 2024
Walter Roberson
on 31 Jan 2024
edit fun1_optim.m
Ivan
on 31 Jan 2024
Dyuman Joshi
on 31 Jan 2024
Run this command and see where the file is located.
which fun1_optim.m -all
Ivan
on 1 Feb 2024
Dyuman Joshi
on 1 Feb 2024
There's a missing word, "which", from the command.
Categories
Find more on Optimization Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


