MATLAB: Create a vector u of dimension 10 with elements un = 4(−1)n 2n+1 . Compute the sum of all the elements and comment.

for loopvectorzeros

Create a vector u of dimension 10 with elements u(n) = 4*(−1)n/ (2n+1) .
To create the vector I created R=zeros(1,10). then did:
for n=1:10; R(1,n)=R + (4*(-1)^n)/(2*n+1); end
Result gives R=[0,0,0,0,0,0,0,0,0,0]

Best Answer

n=1:10;
u=4*(-1).^n./(2*n+1);
Best wishes
Torsten.