求助各位高手们:这个循环该怎样写啊?
xt=’xt为一列向量,a为一行向量,
a= ,
y向量中的元素y(1),y(2),y(3),.......y(17)分别为:
y(1)=xt(1)
y(2)=a(1)*y(1)
y(3)=a(1)*y(2)+a(2)*y(1)
y(4)=a(1)*y(3)+a(2)*y(2)+a(3)*y(1)
y(5)=a(1)*y(4)+a(2)*y(3)+a(3)*y(2)+a(4)*y(1)
.......................
y(17)=a(1)*y(16)+a(2)*y(15)+.......+a(16)*y(1)
请高手们指点迷津啊 y(:)=0;
y(1)=xt(1);
for k=2:17
for n=1:k-1
y(k)=y(k)+a(n)*y(k-n);
end
end
试一下吧,就这个思路。
记不清要几个end了。
第一步是将y向量赋零。
[ 本帖最后由 ChaChing 于 2009-4-22 14:07 编辑 ]
谢谢您啊
我按您的思路运行了一下,发现y(1)=xt(1),当k=2,n=1时y(2)=y(2)+a(1)*y(1).MATLAB提示等号右边的y(2)没有事先赋值........还请您再解决一下啊 function xunhuan
clc
xt=';
a=[0.1972,0.0793,-0.0041,0.0990,-0.0250,0.0262,-0.0022,0.0979,0.2454,-0.2224,...
0.3678,-0.1068,0.0990,0.2240,-0.0477,-0.0294];
xt1=xt()';
y=xt(1);
for i=2:length(xt1)
y=;
end
[ 本帖最后由 bainhome 于 2006-8-5 15:00 编辑 ]
感谢您的指点!
我运行后得出y =Columns 1 through 7
162.0000 31.9464 47.3566 45.1597 58.9303 59.2944 60.0264
Columns 8 through 14
57.7281 79.5181116.5706 83.9168138.7380125.7661143.4469
Columns 15 through 16
173.5141177.0229
但手算后发现y1=xt(1)=162, y(2)=a(1)*y(1)=0.1972*162=31.9464,
y(3)=a(1)*y(2)+a(2)*y(1)=0.1972*31.9464+0.0793*162=19.14643,
发现y(3)与运行的结果不相等啊,还请帮忙啊
十分感谢您!
谢谢前辈的指点啊!我以后一定努力动脑! y(2)初值为零啊,y整个向量初值都为零啊。你是不是没有把y向量初始化为零啊?
页:
[1]