MATLAB Answers

index error is appearing for last line

1 view (last 30 days)
U=zeros(1,2,'sym');
B=zeros(10,'sym');
U(1)=1;
U(2)=a;
for k=1:10
B(1)=0;
for i=1:k
B(1)=B(1)+U(i)*U(k-i+1)
end
end
It is displaying the error for B(1)=B(1)+U(i)*U(k-i+1)
  6 Comments

Sign in to comment.

Accepted Answer

Girijashankar Sahoo
Girijashankar Sahoo on 1 Jun 2021
B(1)=B(1)+U(i)*U(k-i+1)
% Here you defined length(U)=2 while U(i)*U(k-i+1) is over indexed value
% So my suggestion denfine U=zeros(1,10,'sym')

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!