Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab summations

  1. Sep 8, 2010 #1
    Hi, I'm new to matlab.

    I'm trying to sum a function similar to 2n from 0 to n where n is specified as a digit and not a list. I am using the sum() function but I don't really know how to get it to work right for this.

    Thanks
     
  2. jcsd
  3. Sep 8, 2010 #2
    Code (Text):
    S=0;
    n = 10;
    for k=0:n;
    S = S + 2^k;
    end
    Or
    Code (Text):

    ind = 0:1:n;
    S = sum(2.^ind);
     
     
  4. Sep 9, 2010 #3
    Thanks but I got it. I needed a one-line code like this:

    Code (Text):
    n = 25
    sum(2.^(0:n))
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Matlab summations
  1. Matlab - Summation (Replies: 4)

Loading...