Hello there,
I'am having trouble solving an Exercise regarding a linear programming optimization.
fmincon(@dist, x0, [], [], [], [], lb, ub, @d_constr)
First I want to generate a Random set of numbers of "little" stations and their distribution on a Line:
j = randi([1 1000]);n = randi([2 20]);m = randi([j],n,1);
Then I need to find the location for the "Main" Station,
which needs to bet at the point on the Line where it has the minimum distance to all other Stations.
the function for the sum is this:
function d = dist(x)L = x(1);d = @(m) sum(m - L);end
Now a function for the constrains is needed:
As the only one is L>0 && L<j ; where j is the total lenght of the line.
function [g,h] = d_constr(x)L = x(1);g(1) = L < j;g(2) = L > 0;h = [];end
Well it doesn't work and Iam blank.
This is the Error I am getting all the Time:
Error using fmincon (line 700)FMINCON requires all values returned by functions to be of data type double.Error in distance (line 69) fmincon(@dist, x0, [], [], [], [], x1, x2, @d_constr)
Thank you for your time <3
Best Answer