Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

how to find the sum terms in of binomial expansion

Asked by a

a (view profile)

on 11 Apr 2013

I need to find the sum of few terms in binomial expansion...more precisely i need to find the sum of this expression:

                   ∑ (nCr) * p^r * q^(n - r)

and limits for summation are from r = 2 to 15. and n=15

any help would be most welcome.



a (view profile)


No products are associated with this question.

2 Answers

Answer by Ahmed A. Selman

Ahmed A. Selman (view profile)

on 11 Apr 2013
Edited by Ahmed A. Selman

Ahmed A. Selman (view profile)

on 11 Apr 2013
Accepted answer

The general steps to find such a summation are:

- Start a loop over r,

- Calculate each term as a function of (r),

- In the loop, add the terms one by one to a unique matrix,

- After the loop is finished, sum over the added terms.

The code should be something as :

% ∑ (nCr) * p^r * q^(n - r)
clc; clear all
p =...;
q =...;
n = 15;
i = 0;
   for r = 2:15
        i = i+1;
        nCr = ...;% calculate the coefficients here  
        Terms(i) = nCr * p.^r .* q.^(n-r);
 SumOfTerms = sum(Terms)

The output is in (SumOfTerms), which should be a single value.

I assumed that (nCr) is not a constant, as I expect, it must be a function of (n and r). If it was a constant of (n and r), then define it outside the loop.

I also didn't understand the meaning of ( *| ) at the beginning and end of the formula in your question. If they mean some operation s ( complex conjugate or absolute) then add any of the commands at the very end of the code:

finalSum = conj(SumOfTerms);% for complex conjugate value.


finalSum = real(SumOfTerms);% for real value.

and in this case the output will be in (finalSum).

If you tried it and it didn't work, please let me know in which line it made an error, and the error message.



a (view profile)

on 12 Apr 2013

@ Image Analyst : Thank You Sir.

I am new to Matlab, so i did not inspect the Workspace.My answer is listed there in Workspace.I was only bothering the behavior of Command Window.




a (view profile)

on 12 Apr 2013

@ Ahmed A Selman:

thank You Mr. Ahmed A Selman for helping me out.



a (view profile)

on 14 May 2013

@ Ahmed A. Selman

Sir, the code you provided works well...Can you please explain me how this loop is executing?

Ahmed A. Selman

Ahmed A. Selman (view profile)

Answer by Roger Stafford

Roger Stafford (view profile)

on 11 Apr 2013

With that range of r I would think it would be more efficient to compute



Roger Stafford

Roger Stafford (view profile)

Contact us