Run matlabFunction got error note: Variable names must be valid MATLAB variable names.

It seems like sth wrong in: objfun = matlabFunction(f,'vars',{actions}); i put 'vars' here coz at beginning the array 'actions' is symbolic array, but after [X,FVAL,EXITFLAG,OUTPUT] = fmincon(objfun,[2;2;2],[1,1,1],50,[],[],0,20,[],options), i hv got the real number of actions.
%Discription: This code is a simulation of 3 user Distributed Power Control
%algorithm used in CDMA networks for interference coordination.
%Variables: SIR-Signal to Interference+Noise Ratio
% H-channel gain matrix; Gamm- Gamm-Required SIR at each receiver
% P-power available at each transmitter, N-noise at each
% receiver
% Err-error.Difference between required SIR and actual SIR. Measure
% of convergence of algorithm
%Algorithm: p(t+1,i)=Gamm(i)/SIR(t,i)*p(t,i) where t-is time index and
%i-user index.
%We perfom this algorithm until we conver to required SIR levels
clc, clear all, clf
global N ITERATION_STEP BETA Noise H Gamma
syms a1 a2 a3
N=3;
ITERATION_STEP=3;
%Next we randomly generate channel matrix H.
H=rand(N,N); %H contains channel all channel gains. Channels gains are assumed to be less then 1
Noise=[0.01;0.01;0.01]; % Noise power at each receiver
% discount factor
BETA=0.95;
%prob = [0.662;0.547;0.769];
prob = rand(N,1);
disp('prob');
disp(prob);
states = zeros(N,1);
actions = [a1; a2; a3];
%actions(:,1)=20; initial transmitted power is 20dB
inst_reward = zeros(N,1);
future_reward = zeros(N,1);
% initialize SIR at each player
SIR=[H(1)*actions(1)/(H(3)*actions(3)+H(2)*actions(2)+Noise(1)),H(2)*actions(2)/(H(3)*actions(3)+H(1)*actions(1)+Noise(2)),H(3)*actions(3)/(H(2)*actions(2)+H(1)*actions(1)+Noise(3))];
%target SIR at each receiver
Gamma=[0.1, 0.2, 0.3];
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:ITERATION_STEP
for i = 1:N
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 + future_reward + total;
f = sum(future_reward);
objfun = matlabFunction(f,'vars',{actions});
% 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('Algorithm','interior-point','Display','off');
[X,FVAL,EXITFLAG,OUTPUT] = fmincon(objfun,[2;2;2],[1,1,1],50,[],[],0,20,[],options)
% update transmitted power to the results of optimization
actions(:,1) = X;
disp('actions');
disp(actions);
d = size(actions);
k = size(prob);
disp(d);
disp(k);
% increase the loop
i = i+1;
end
j = j+1;
end
% new SIR
SIR(:,i)=[H(1)*actions(1)/(H(3)*actions(3)+H(2)*actions(2)+Noise(1)),H(2)*actions(2)/(H(3)*actions(3)+H(1)*actions(1)+Noise(2)),H(3)*actions(3)/(H(2)*actions(2)+H(1)*actions(1)+Noise(3))];
disp('SIR');
disp(SIR);
% increase the loop
plot(1:iterations,SIR(:,1),'-.')
plot(1:iterations,SIR(:,2),'-.g')
plot(1:iterations,SIR(:,3),'-.r')
xlabel('Iterations')
ylabel('SIR')
title('SIR vs number of Iterations')
legend(' SIR of user 1',' SIR of user 2',' SIR of user 3')
Error note are: Error using sym/matlabFunction>checkVars (line 153) Variable names must be valid MATLAB variable names.
Error in sym/matlabFunction (line 104) vars = checkVars(funvars,opts);
Error in test1016 (line 72) objfun = matlabFunction(f,'vars',{actions});

2 件のコメント

Vivek Selvam
Vivek Selvam 2013 年 10 月 16 日
Viva, can you upload the InstReward function?
I'm not really sure how the error message could be more clear: The call
matlabFunction(f,'vars',{actions})
is valid if and only if {actions} is a cell array of valid MATLAB variable names (or symbolic variables). Which isn't the case here, since you put doubles into the variable actions. (By the way, since actions holds a symbolic array, those doubles will be converted to exact symbolic numbers. But you cannot use those as variable names either.)
Without seeing all of your code, I can only guess: Perhaps you meant to have
matlabFunction(f,'vars',{a1,a2,a3})

サインインしてコメントする。

回答 (0 件)

カテゴリ

タグ

質問済み:

2013 年 10 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by