필터 지우기
필터 지우기

Input arguments to function include colon operator. To input the colon character, use ':' instead

조회 수: 6 (최근 30일)
Hello
I have four problems
The first is that I wrote these codes based on HATL MATLAB to predict the prediction. I do not know whether I wrote the correct functions or not.The second thing I wrote makes this mistake?
#####
I used this for coding
%%%%%%%%%%%%%%%%
Nonlinear system code is discrete:
%%
function x1=exocstrstateFcnCT1(x1,u1,p)
for i=1:p
x1=x1(i,:);
u1(1)=u1(i,1);
u1(2)=u1(i,1);
x1(i+1,:)=[0.9*cos(x1(3)) 0;0.9*sin(x1(3)) 0;0 0.9]*[u1(1);u1(2)]+[x1(1);x1(2);x1(3)];
end
end
%% CostFunction
function J1=myCostFunction1(x1,x1d,u1,x4had,data,x2had)
for i=1:p
u1=u1(i,:);
x1=x1(i,:);
x2had=x2had(2:p+1,:);
x4had=x4had(2:p+1,:);
J1=0.1*norm(x1-x1d,2)+0.2*norm(u1,2)+ 0.1*norm(x4had-x1-x14d,2)+0.1.*norm(x2had-x1-x12d,2);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
nx=3;
ny=3;
nu=2;
nlobj1 = nlmpc(nx,ny,nu);
Ts = 0.1;
nlobj1.Ts = Ts;
p=6;
c=3;
nlobj1.PredictionHorizon = p;
nlobj1.ControlHorizon = c;
x1(1,:) = [0.5;0.6;0.7];
x1had=x1(1,:);
u1(:,1) = 0.2*[1;1];
validateFcns(nlobj1,x1,u1,[],{Ts});
%%%%%
nloptions1 = nlmpcmoveopt;
nloptions1.Parameters = {Ts};
%%
xHistory1 = x1(1,:);
Duration = 20;
lastMV1 = u1';
uHistory1 = lastMV1;
%%
for k = 1:(Duration/Ts)
t = linspace(k*Ts, (k+p-1)*Ts,p);
% Compute the control moves with reference previewing.
x1k = xHistory1(k,:);
[u1k,nloptions1,info] = nlmpcmove(nlobj1,x1k,lastMV1,[],[],nloptions1);
uHistory1(k+1,:) = u1k';
lastMV1 = u1k;
% Update states.
x1k = @(u1k,x1k) exocstrstateFcnCT1(x1k,u1k);
y1 = x1k;
xHistory1(k+1,:) = y1(end,:);
end
%%%%
fprintf(' k | u1(1) u1(2) x1(1) x1(2) x1(3) Time\n');
fprintf('----------------------------------------------------------\n');
%% This is the estimation part
for l=2:p+1
if l<=p-1
x1had(l,:)=xHistory1(l-1,:);
else
x1had(p,:)=xHistory1(p+1,:);
end
end
%%%%
Third, I want several robots to move together, and for the current position of the neighboring robot, the previous mode is used as an estimate for the neighboring robot.
Its code is as follows
Fourth, I want to show this on the plot, for example, they are connected in a rectangular shape, go from one point to another.
The nonlinear system is discrete
%%%%
It makes an error
Input arguments to function include colon operator. To input the colon character, use ':' instead.
Error in mpc1 (line 83)
xHistory1(k+1,:) = y1(end,:);
please guide me

답변 (1개)

Walter Roberson
Walter Roberson 2020년 10월 27일
x1k = @(u1k,x1k) exocstrstateFcnCT1(x1k,u1k);
That is a function handle
y1 = x1k;
That copies the function handle but does not invoke the function
xHistory1(k+1,:) = y1(end,:);
That tries to treat the function handle as an array.
It looks to me as if y1 should be assigned the result of invoking the function handle, but it is not obvious to me what the arguments should be to the invocation.
  댓글 수: 10
Farshid R
Farshid R 2020년 10월 30일
No, no, you do not have to say sorry
You helped me a lot, thank you

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Code Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by