How to run optmization on vectors?
Show older comments
Hello,
Please, I would like to ask for some help on a procedure that I'm running.
I have some large vectors that are input for a model that is solved through Least Squares Method. The model is a function of 6 parameters (the vectors v1[], v2[], v3[] and v4) and the 2 vectors to be optmized (x1[] and x2[]). The function dOptTgt is the quadratic sum of the errors of the model.
function dOptT = dOptTgt(x1,v1,v2,x2,v3,v4)
t1=f1(x1,v1,v2,x2,v3,v4) %math only
t2=f2(x1,v1,v2,x2,v3,v4) %math only
a1=(t1-v3)./v3
a2=(t2-v4)./v4
dOptT=(a1.^2+a2.^2)*10000
end
I have tried to use fminsearch() on the vectors,
x1=...
x2=...
fun=@(x) dOptTgt(x(:,1),v1,v2,x(:,2),v3,v4)
x0=[x1,x2]
Y=fun(x0)
x=fminsearch(fun,x0)
but got an error message. As it seems, fminsearch cannot be run on vectors:
Attempt to execute SCRIPT fminsearch as a function
Error in fminsearch (line 22)
x=fminsearch(fun,x0)
Also tried lsqnonlin(), not sure if the problem was correctly setup; the outputs afer fitting do not make the residuals zero, but just a good approximation.
x1=...
x2=...
fun=@(x) dOptTgt(x(:,1),v1,v2,x(:,2),v3,v4)
x0=[x1,x2]
options = optimoptions('lsqnonlin','Display','iter')
[x,resnorm] =lsqnonlin(fun,x0,[],[],options)
The solution I put in place was a loop selecting the elements i of each vector and using fminsearch().
x1=...
x2=...
for i=1:size(...)
fun=@(x) dOptTgt(x(1),v1(i),v2(i),x(2),v3(i),v4(i)))
x0=[x1(i),x2(i)]
a =fminsearch(fun,x0)
end
It works, but takes a lot of time to run, and doesn't seem to be the most efficient way to do that.
Please, is there a way to run this problem more efficiently?
Thank you,
G
Accepted Answer
More Answers (0)
Categories
Find more on Simulink Design Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!