MATLAB Answers

0

Create a vector x with the elements

Asked by Noorhafizah on 3 Feb 2011
Create a vector x with the elements x = (-1^n + 1/2*n -1 ) Add up the elements of the version of this vector that has 100 elements.
Can someone tell me how to do it?

  2 Comments

Is that (-1)^n ? Does the 1/2 apply to n or to (n-1) ? Is n a constant, or does it represent the index of the element? If it represents the index, should n start at 0 or at 1 ?
the cyclist
on 3 Feb 2011
If this is class homework, please say so and describe what you have tried on your own.

Sign in to comment.

1 Answer

Answer by Davide Ferraro on 3 Feb 2011

You can use vector operations on the vector n with elements from 1 to 100:
x = (-1.^n + 1/2*n -1);
to create the x vector.
If you need to sum every element you can then use the SUM command:
sum(x)

  0 Comments

Sign in to comment.