Using Symbolic function to execute Optimization in MATLAB
Ältere Kommentare anzeigen
Hello all I ran into a symbolic viarible optimization problem in MATLAB. I tried to define array containing with symbolic element, and then apply a certain function and I would like to optimize this function which contain symbolic variables. Error notes show: "Function 'ge' is not implemented for MuPAD symbolic objects" which i assume meaning MATLAB can not run optimization on symbolic object functions. is there anyone know how to fix it? pls.....
This is the code:
clear all
global N ITERATION_STEP BETA a1 a2 a3
syms a1 a2 a3
N=3;
ITERATION_STEP=3;
% discount factor
BETA=0.95;
prob = [0.662,0.547,0.769]; %prob = rand(1,n);
disp('prob');
disp(prob);
states = zeros(1,N);
actions = [a1, a2, a3];
%actions(1,:)=20; initial transmitted power is 20dB
inst_reward = zeros(1,N);
future_reward = zeros(1,N);
for i = 1:N
imm_reward = InstReward(prob,actions);
end
disp('imm_reward');
disp(imm_reward);
% at every moment, there are two possible rewards, name them reward1 and
% reward 2 which reward1 denotes the reward when no state change happens,
% while reward2 denotes the reward when state changes.
for j = 1:2
for i = 1:2
alter_prob = 1 - prob;
reward1 = InstReward(prob, actions);
reward2 = InstReward(alter_prob, actions);
total = BETA.^(j)*(prob.*reward1 + alter_prob.*reward2);
future_reward = imm_reward + sum(total);
end
end
obj_function = @(actions)(sum(future_reward));
% optimization algorithm to find the value of actions to get the min reward
% [X,FVAL,EXITFLAG,OUTPUT] = fmincon(FUN,X0,A,B,Aeq,Beq,LB,UB,NONLCON,OPTIONS)
%options = optimset('Display','off');
[X,FVAL,EXITFLAG,OUTPUT] = fmincon(obj_function,[0,0],[],[],[],[],0,[]);
But I got error note as: Error using sym>notimplemented (line 2682) Function 'ge' is not implemented for MuPAD symbolic objects.
Error in sym/ge (line 823) notimplemented('ge');
Error in nlconst (line 663) elseif f >=0
Error in fmincon (line 794) [X,FVAL,LAMBDA,EXITFLAG,OUTPUT,GRAD,HESSIAN]=...
Error in main (line 42) [X,FVAL,EXITFLAG,OUTPUT] = fmincon(obj_function,[0,0],[],[],[],[],0,[]);
Akzeptierte Antwort
Weitere Antworten (3)
Walter Roberson
am 8 Okt. 2013
0 Stimmen
You can use matlabFunction() to generate an anonymous function from a symbolic expression, and then optimize that function.
1 Kommentar
viva
am 8 Okt. 2013
Alan Weiss
am 9 Okt. 2013
0 Stimmen
There are examples in the documentation showing how to optimize using matlabFunction. Here is one, and here is another.
Alan Weiss
MATLAB mathematical toolbox documentation
Kategorien
Mehr zu Environments finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!