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.

  2. jcsd
  3. Sep 8, 2010 #2
    Code (Text):
    n = 10;
    for k=0:n;
    S = S + 2^k;
    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
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook