How to optimize (minimize) a Vector function

10 次查看(过去 30 天)
I need to minimize a vector function at all points of x f(x) = a+b*x+c*x^2+d*x^3. The values of a,b,c,d has to be optimized for the same. Is their any algorithm in matlab that can do the same? I used gamultiobj algorithm for the same, but it generated a large number of these values for each pareto point. I just need a single set of value for the same.

采纳的回答

Walter Roberson
Walter Roberson 2016-3-30
编辑:Walter Roberson 2016-3-30
fitfun = @(abcd, x, f) sum( (f - (abcd(1) + abcd(2) * x + abcd(3) * x.^2 + abcd(4) .* x.^3)).^2 );
f = ...
x = ...
%must set those before the next
obj = @(abcd) fitfun(abcd, f, x);
Now run a minimizer on obj, with an input that is a vector of length 4.
If you have the CurveFitting Toolbox, there are more direct tools for doing this.
  3 个评论
Walter Roberson
Walter Roberson 2016-3-30
Do you know the x values and the corresponding f(x)? If you do then assign them in the places I show and make the calls I show.
Note: I corrected a typing mistake I had made.
The optimizers will pass in a single vector of length 4. That will be received under the name abcd . abcd(1) corresponds to a, abcd(2) corresponds to b, and so on. So the optimizer is going to be providing candidate a, b, c, d. For any one candidate, the difference between the actual f(x) and the projected f(x) is calculated for each x, and the differences are squared, and the sum of those is taken, giving you a single numeric result for the trial abcd . If there was a perfect fit somehow, then the sum-of-squares would be 0, so finding the best fit consists of minimizing the sum-of-squares . For example, after the setup above,
fminsearch(obj, rand(1,4))
Walter Roberson
Walter Roberson 2016-3-30
There is a completely different approach to this:
Given the x and the known f(x) values:
A = [ones(length(x),1), x(:), x(:).^2, x(:).^3];
b = f(:); %the known values
bestabcd = A \ f;
a = bestabcd(1); b = bestabcd(2); c = bestabcd(3); d = bestabcd(4);
Or even more compactly,
dcba = polyfit( x(:), f(:), 3);
a = dcba(4); b = dcba(3); c = dcba(2); a = dcba(1);
polyfit() is restricted to univariate polynomials. Using \ has more flexibility but is restricted to finding multiplication coefficients. The method I posted first is the most general method that can be used for arbitrary functions; for example it could be used if you needed to find the "a" in a besselj(a,x) call.

请先登录,再进行评论。

更多回答(5 个)

deboshree roy
deboshree roy 2016-3-30
Maybe, I am not able to define my problem clearly. I have certain value of a,b,c,d (known values), that generates f(x). However, the value of a,b,c,d parameters has to be changed, such that I obtain a f(x) value that is minimum at all x. This minimized function is not known to us. Hence, a curve fitting polynomial wont help. I tried fminsearch but that works for a scalar function. I tried using gamultiobj (Multiple objective optimization), but not clear of its working, as it generates a large number of different a,b,c,d values.
  2 个评论
Torsten
Torsten 2016-3-30
Say you have a=b=c=d=1 and x(1)=1 and x(2)=2.
Now what do you mean by
However, the value of a,b,c,d parameters has to be changed, such that I obtain a f(x) value that is minimum at all x.
Best wishes
Torsten.
Walter Roberson
Walter Roberson 2016-3-31
fminsearch is for vector functions not just scalar. The function has to take one parameter but it is expected to be a vector.

请先登录,再进行评论。


deboshree roy
deboshree roy 2016-3-30
I want a to change to a+del,b,c,d, and check for the values of f(x) ( del is 0.0001). Carry on this for all parameters, for multiple times, till a minimum function of f(x) for all x is reached.
  2 个评论
Torsten
Torsten 2016-3-30
I don't understand.
Change a to -Inf, b,c and d to 0. Then a minimum value for all x is reached, namely f(x)=-Infinity.
Best wishes
Torsten.
Walter Roberson
Walter Roberson 2016-3-31
Your function takes a vector x. You want the minimum f(x) for all x. So you are trying to minimize all members of the vector simultaneously. How do you want to account for the fact that the parameters a b c d that give you the minimum f(x(1)) might give you a larger f(x(2))? If you have two possible sets of a b c d, how do you decide which of the two is better over the entire vector?
Did I see you mention Pareto?

请先登录,再进行评论。


deboshree roy
deboshree roy 2016-3-30
I would be glad if you could provide me with a matlab program that would generate the same result. My objective function is different. The parameters abcd are phases for cosine functions.and hence, the function have limitations.
  2 个评论
deboshree roy
deboshree roy 2016-3-30
The f(x) I defined was an example, just to simplify my question.
Torsten
Torsten 2016-3-30
Could you post the objective you are using ?
Best wishes
Torsten.

请先登录,再进行评论。


deboshree roy
deboshree roy 2016-3-30
编辑:Walter Roberson 2016-4-5
the objective function is -
function f = pulse(phi,duration)
t = 0:duration;
T = duration;
f = 0;
for i = 1:10
f = f + cos (((2*i-1).*t/T)+ phi(i));
end
end
Starting point is phi = [0,0,......0] generates a pulse at t=0.
This signal should disperse to minimum value
  3 个评论
Torsten
Torsten 2016-3-30
Then use fminimax from the optimization toolbox.
Best wishes
Torsten.

请先登录,再进行评论。


deboshree roy
deboshree roy 2016-4-4
It worked, thanks

Community Treasure Hunt

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

Start Hunting!

Translated by