How to optimize (minimize) a Vector function
10 views (last 30 days)
Show older comments
deboshree roy
on 30 Mar 2016
Edited: Walter Roberson
on 5 Apr 2016
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.
0 Comments
Accepted Answer
Walter Roberson
on 30 Mar 2016
Edited: Walter Roberson
on 30 Mar 2016
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 Comments
Walter Roberson
on 30 Mar 2016
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
on 30 Mar 2016
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.
More Answers (5)
deboshree roy
on 30 Mar 2016
2 Comments
Torsten
on 30 Mar 2016
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
on 31 Mar 2016
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
on 30 Mar 2016
2 Comments
Torsten
on 30 Mar 2016
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
on 31 Mar 2016
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?
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!