# Math Help - fmincon on vectorvalued function?

1. ## fmincon on vectorvalued function?

Hi

In MATLAB, can one use the fmincon function on a vectorvalued function?
I can't get it to work.

thanks!

2. Originally Posted by Twig
Hi

In MATLAB, can one use the fmincon function on a vectorvalued function?
I can't get it to work.

thanks!
What would a minimum of a vector look like?

CB

3. ## Hi

hi CB

good point, I need to rethink this a bit probably.

My problem is, I need to use fmincon to maximize distance between 6 points on a unit sphere in R^3. I need in some way find an expression for calculating the distance from every point to every other point?

I just thought maybe it would be easiest in some way if I were to put the different points in a matrix or something..

Also obv, I need to write a nonlinear constraint function.

I guess it would be something like:

function [c,ceq]=confun(x)

c=[] %No less than constraints
ceq=x(1).^2 + x(2).^2 + x(3).^3 - 1
end

But I need this constraint for 6 points..

thanks!

4. Originally Posted by Twig
hi CB

good point, I need to rethink this a bit probably.

My problem is, I need to use fmincon to maximize distance between 6 points on a unit sphere in R^3. I need in some way find an expression for calculating the distance from every point to every other point?

I just thought maybe it would be easiest in some way if I were to put the different points in a matrix or something..

Also obv, I need to write a nonlinear constraint function.

I guess it would be something like:

function [c,ceq]=confun(x)

c=[] %No less than constraints
ceq=x(1).^2 + x(2).^2 + x(3).^3 - 1
end

But I need this constraint for 6 points..

thanks!
Write a function to calculate the distance between two points lets call it $d(x,y)$ , then the sum of the distances between the points is:

$D=\sum_{i=1}^6 \sum_{j=i+1}^6 d(x_i,x_j)$

If you represent your points in sphereical polars you will not need constraints

CB

5. ## hi

hi

I am having a bit trouble with this. Need a bit more guidance.

function y=sumfunc(x)
for j=1:6
for k=j+1:6
y=-norm([x(k,1)-x(k-1,1) x(k,2)-x(k-1,2) x(k,3)-x(k-1,3)])
end
end

This is supposed to be the function calculating distance.

function testasumfunc()
clc
%A=[1 0 0;-10 0 0]
A=rand(6,3);
[X,fval]=fmincon(@sumfunc,A,[],[],[],[],[],[],@confun);

X
norm(X(1,) %DOES NOT EQUAL ONE, not working
end

%Constraint function
function [c,ceq]=confun(x)
c=[];
ceq=x(1).^2 + x(2).^2 + x(3).^2 -1;
end