1

I want to compute the sum of 1/((1^2)(3^2))+ 1/((3^2)(5^2))+1/((5^2)(7^2))+ ...

The following code is my attempt at computing that sum with no looping:

n = 1000;
t0 = clock;    %vectorizing we get 
x1 = (1./(1:2:n)).^2;
y1 = (1/(3:2:n)).^2y1.*x1;
t = sum(y1.*x1)etime(clock,t0)

But MATLAB gives an error that the vector sizes do not agree.

How can I fix this to get the correct answer?

2
  • I see that someone already provided the answer for the specific case, but given the error message I would have suggested you to check the size of all vectors and see which one is not what you expected. Commented Oct 8, 2016 at 15:10
  • @DennisJaheruddin Thanks ;) Commented Oct 8, 2016 at 15:14

1 Answer 1

5
y1=(1/(3:2:n)).^2y1.*x1;

should be:

y1=(1/(3:2:n+2)).^2;
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks a lot I am new here :), let me check ;)
no problem, if it works out then select my answer so other people can benefit from it!
anytime, this is what the website is for!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.