From: bonthu on
hi all,
im building a model reference controller for a plant in matlab editor using narxsp network. i just started using matlab. i request u all to help me. im getting only one error. i mentioned below abt it. the proram is of 3 parts
1st: identification of plant
2nd: controller design- the error is in this part
3rd: checking the plant output

and also give me ur valuable suggestions on the complete code

The code is given below for a discrete plant.
clc; clear all; close all;
k=1:100;
r=sin(2*pi*k/25);
ym(1)=0;ym(2)=0;
for k=2:99
ym(k + 1) = 0.6*ym(k) + 0.2*ym(k - 1) + r(k);
end
figure(1)
plot(ym);
y=ones(1,100);
for k=2:99
u(k)=((-1)*(y(k)*y(k-1)*(y(k)+5)/(1+(y(k)*y(k))+(y(k-1)*y(k-1)))))+ym(k+1);
end
figure(2)
plot(u);
e=ym-y;
figure(3)
subplot(3,1,1)
plot(ym)
subplot(3,1,2)
plot(y)
subplot(3,1,3)
plot(e)
for k=2:99
y(k+1)=(y(k)*y(k-1)*(y(k)+5)/(1+(y(k)*y(k))+(y(k-1)*y(k-1))))+u(k);
end
figure(4)
plot(y)
r=con2seq(r);
ym=con2seq(ym);
u=con2seq(u);
y=con2seq(y);
%plant identification
%plant identification starts
p=y;
t=y;
d1=[1 2];
narx_net=newnarxsp(p,t,d1,[1:2],[20 10]);
narx_net.trainfcn='trainbr';
narx_net.trainparam.show=10;
narx_net.trainparam.epochs=500;
narx_net.trainparam.lr=0.25;
%narx_net.trainparam.goal=0.00001;
narx_net=train(narx_net,[p;t],t);
yp=sim(narx_net,[p;t]);
e = cell2mat(yp)-cell2mat(t);
figure(5)
plot(e);
figure(6)
plot([cell2mat(yp)' cell2mat(t)']);
% plant identification ends
%p1=[r;y];
%t1=u;
%neural model reference controller

%neural model reference controller starts
narx_net1=newnarxsp({[r;y],u},d1,[1 2],[20 10]);
p=[r;y;u];
P=mat2cell(p,[size(p,1)-1 1],ones(size(p,2),1));
T=mat2cell(u,1,ones(size(c,2),1));
%narx_net1.inputconnect(1,3)=1;
%narx_net1.numInputs=2;
narx_net1.trainfcn='trainbr';
narx_net1.trainparam.show=10;
narx_net1.trainparam.epochs=100;
narx_net1.trainparam.lr=0.25;
%narx_net.trainparam.goal=0.00001;
narx_net1=train(narx_net1,P,T);
u1=sim(narx_net1,P);
%end end controller
%end end controller

u1=seq2con(u1);
y=seq2con(y);
for k=2:99
y(k+1)=(y(k)*y(k-1)*(y(k)+5)/(1+(y(k)*y(k))+(y(k-1)*y(k-1))))+u1(k);
end
ym=seq2con(ym);
efinal=ym-y;
figure(7)
subplot(4,1,1)
plot(u1)
subplot(4,1,2)
plot(y)
subplot(4,1,3)
plot(ym)
subplot(4,1,4)
plot(efinal)

BUT im getting the following error

??? Error using ==> cell2mat at 55
Cannot support cell arrays containing cell arrays or objects.

Error in ==> newnarxsp>new_5p1 at 134
if isa(p,'cell'), p = cell2mat(p); end

Error in ==> newnarxsp at 110
net = new_5p1(varargin{:});

Error in ==> sai0identification7 at 51
narx_net1=newnarxsp({[r;y],u},d1,[1 2],[20 10]);

please help me.