想用差分方程实现对y=sin(pi*t)的跟踪,文件保存为:zuijin2t ,程序如下:
clear;
clc;
n=100;
pi=3.14;
for t=1:n
T=t/100;
y_d(t)=sin(pi*t/100);
end
t1=0.01;
y1=0.04;
for t=1:n
y(t+1)=y(t)+pi*cos(pi*t/100)*t1;
end
T=t/100;
t=1:n
plot(t,yd(t),'b');hold on;
plot(t,y(t),'r');hold on;
可是,无论怎样改,总提示:
??? Undefined func
tion or method 'y' for input arguments of type 'double'.
Error in ==> zuijin2t at 12
y(t+1)=y(t)+pi*cos(pi*t/100)*t1;