fmincon with a RBF toolbox
4 views (last 30 days)
Show older comments
I have approximated a function using a RBF toolbox. Now, I woud like to optimize this function using fmincon. However, I do not know how to use the fmincon in this case.
%Create plot of original function:
x=(0:0.001:1)';
y=((6.*x-2).^2).*sin(12.*x-4);
plot(x,y,'k','LineWidth',2)
xlabel('x','FontSize',12,'Color','k','FontWeight','bold');
ylabel('y','FontSize',12,'Color','k','FontWeight','bold');
hold on
%Samples:
Xtr=[0;0.2;0.4;0.6;0.8;1];
Ytr=[3.0272;-0.6397;0.1148;-0.1494;-4.9491;15.8297];
%Build the metamodel:
[model, time] = rbfbuild(Xtr, Ytr,'MQ',1);
%Plot the approximate function:
Xq=(0:0.01:1)';
[Yq] = rbfpredict(model, Xtr, Xq);
plot(Xq,Yq,'--k','LineWidth',2)
legend('Função original','Função aproximada');
plot(Xtr,Ytr,'*k','MarkerSize',10);
hold off
%Verify quality of metamodel:
Xtst=[0.1;0.3;0.7;0.9];%Pontos para teste
Ytst=[-0.6566;-0.0156;-4.6058;5.7120];
[MSE, RMSE, RRMSE, R2] = rbftest(model, Xtr, Xtst, Ytst)
%Optimization:
LB = [0];
UB= [1];
x=[0.5];
A= [];
B= [];
Aeq=[];
Beq=[];
options = optimset('MaxIter',300000000,'MaxFunEvals',100000000);
[x,Yq]=fmincon(rbfpredict(model,Xtr,Xq), x, A,B,Aeq,Beq,LB,UB)
Answers (2)
Walter Roberson
on 16 Oct 2017
You need to pass a function handle to fmincon . That might look something like,
x0 = rand;
[best_x, Yq] = fmincon( @(x) rbfpredict(model, Xtr, Xq, x), x0, A, B, Aeq, Beq, LB, UB, [], options);
rbfpredict does not appear to be a Mathworks function so I do not know what parameters it takes or in what order.
1 Comment
Walter Roberson
on 16 Oct 2017
What are you minimizing? Your Xq appears to be a vector. Are to we understand that you should have written,
x0 = rand;
[best_x, Yq] = fmincon( @(xq) rbfpredict(model, Xtr, Xq), x0, A, B, Aeq, Beq, LB, UB, [], options);
and that you are looking for the scalar Xq that gives the smallest (or most negative) prediction, yq ?
See Also
Categories
Find more on Nonlinear 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!