sum of a series
이전 댓글 표시
Hi,
Can someone please help me to write the following code using a summation
for i = 1:1000
v(i) =y(i) - a0- a1*y(i-1)-a2*y(i-2);
end
Thanks.
채택된 답변
추가 답변 (1개)
Youssef Khmou
2013년 3월 18일
편집: Youssef Khmou
2013년 3월 18일
hi, what is Y[nT]? random variable?
N=1000;
a0=2.36;
a1=4.56;
a2=5.57;
y=randn(N,1);
v=zeros(N,1);
v(1:2)=y(1:2); % Optional, take is as initial condition
% Using Loops
for n=3:N
v(n)=y(n)-a0-(a1*y(n-1))-(a2*y(n-2));
end
figure, plot(y), hold on, plot(v,'r'), hold off
% Vectorization
Y1=zeros(size(y));
Y1(2:end)=y(1:end-1);
Y2=zeros(size(y));
Y2(3:end)=y(1:end-2);
V=y-a0-a1*Y1-a2*Y2;
% Comparaison
figure, plot(v), hold , plot(V,'r'), hold off
댓글 수: 5
dav
2013년 3월 18일
Youssef Khmou
2013년 3월 18일
편집: Youssef Khmou
2013년 3월 18일
sorry, i was completing the code....look at the second part..... it is translation of the loop you posted
dav
2013년 3월 18일
dav
2013년 3월 19일
Youssef Khmou
2013년 3월 19일
ok
카테고리
도움말 센터 및 File Exchange에서 Mathematics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!