PutsandCalls
PutsandCalls

Reputation: 1011

Implementing the following series?

I am trying to implement the following series with a following for-loop and x=1, but am not getting the desired result, could someone please specify where I am going wrong?

I have attached an image of the series as follows:

enter image description here

x = 1;
for k = 1:21
    S(k) = (2./sqrt(2*pi))*(cumsum((x.^(2*(k-1)-1)*(-1.^((k-1)+2)))./((2.^(k-1))*(factorial(k-1))*(2*(k-1)+1))))
end

For some reason, I am getting completely different results as my number is negative, but I have looked over my code over again but Im still not sure where its coming from.

Thanks

Upvotes: 2

Views: 31

Answers (1)

learnvst
learnvst

Reputation: 16195

Your indexing is out. At the opening of the cumsum statement you put

x.^(2*(k-1)-1)

Which should be . .

x.^(2*(k-1)+1)

Upvotes: 1

Related Questions