minimize the sum of functions. (fmincon)

1 view (last 30 days)
hi, sorry for my bad english
i have to minimize a function g(x,a,b):=(i=1 to N) Σ(f(x,a(i))-b(i)) in the variable x.
where a and b are N-dimensional vector that i have in input.
x must be greater than zero so i would use fmincon.
for a(i) and b(i) i would use anonymous parameter (parameterfun) to pass them to the function.
the problem for me is the sum.
for a fixed index "i" is easy for me to minimize (f(x,a(i))-b(i)). but how can pass to the minimization of the sum ?
thank you so much!

Accepted Answer

Walter Roberson
Walter Roberson on 23 Sep 2011
Construct your function f to be vectorizable in a, and use
sf = @(x) sum(f(x,a)-b);
as the function you fmincon()
Or if it is too hard to make f vectorizable in a, then you can use
sf = @(x) sum(arrayfun(@(K) f(x,a(K))-b(K),1:length(a));

More Answers (0)

Categories

Find more on Operators and Elementary Operations in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!