McBotto.t
McBotto.t

Reputation: 113

Minimize function that takes n vectors as input

I'd like to minimize a function in MATLAB that takes n vectors as input

More precisely: I have n points in 3D-space that describe a closed curve, let's say the circle.

n = 10;
t = linspace(0,1,10);

x = cos(2*pi*t);
y = sin(2*pi*t);
z = zeros(1,length(2*pi*t));

vec = [x;y;z]
scalar = function my_fun(vec)

So the points representing the curve in space are defined by vec(:,1),...,vec(:,n). My function takes the points (vec) and calculates some kind of energy, so the output is a scalar.

My problem is that I don't know how to set the the variable input such that I can use fminsearch. The idea is, if possible, that fminsearch vary the points in space to find the minimum.

Upvotes: 1

Views: 138

Answers (1)

Cris Luengo
Cris Luengo

Reputation: 60799

fminsearch can optimize a function that takes any one array as input. Your function takes one input argument, vec, which is a 2D array. This can be directly optimized:

init = randn(3,n);
answer = fminsearch(my_fun,init);

Do note that, with n=10, you have 30 variables over which to optimize, which is a lot. This is going to be expensive and likely to get stuck in a local minimum.

Upvotes: 2

Related Questions