How can I debug the following Matlab code?

48 views Asked by At

The error

File: parameter_estimation_1.m Line: 8 Column: 10

Unexpected MATLAB expression.

crops up when I run the following MATLAB code:

T = 0:0.25:5; % time vector (row)
T = T'; % time vector (column)
seed = [3;0.5]; % seed for noise generation
randn('state',seed); % using the same seed each time
uu = 0.5 1 0.25*randn(length(T),1); % mean of 0.5 with variance
% of 0.25
U = 2*round(uu)-1; % creates PRBS with -1 and 1 values %
sim('est_vdv'); % runs simulation of linear van de vusse % diagram
figure(1); % plot input-output data
subplot(2,1,1),plot(tp,yp,'k',t,y,'ko');
xlabel('time, min'), ylabel('y')
title('PRBS estimation example')
subplot(2,1,2),plot(tp,up,'k'); xlabel('time, min'),ylabel('u')
axis([0 5 -1.1 1.1])
% % generate phi matrix for estimation
for j = 4:22;
phi(j-3,:) = [y(j-2) y(j-3) u(j-2) u(j-3)];
end
%
theta = inv(phi'*phi)*phi'*y(3:21) % estimate parameters
num = [theta(3) theta(4)]; % numerator of discrete transfer function
den = [1 -theta(1) -theta(2)]; % denominator of discrete transfer function
sysd = tf(num,den,0.25) % create discrete tf object
tzero(sysd) % calculate zeros
pole(sysd) % calculate poles
syszpk = zpk(sysd) % zero-pole-k form

This code is supposed to run in tandem with a SIMULINK model titled "est_vdv" to estimate the parameters of a model. How should I deal with this error?

1

There are 1 answers

0
biswajit On BEST ANSWER

Thanks Friends for your suggestions, I have been able to figure out what went wrong with the 5th line, it should have been

uu=0.5+0.25.*randn(length(T),1)

Sorry, it was wrongly indicated that the error was in the 8th line.