1. PF Contest - Win "Conquering the Physics GRE" book! Click Here to Enter
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MATLAB matrix question

  1. Jan 21, 2010 #1
    1. The problem statement, all variables and given/known data
    OK, so I have defined:

    p=1.01; (but later will make this so it is inputted by user as a function)

    I need to define y1-y100 like:
    y3=1/(1+sum(dxn(1:3))) etc

    is there some way I can make this into some matrix with values up to y100 without having to write out and define each one individually? Maybe I'm being stupid but I can't see an easy way to do this. Any help would be much appreciated.
  2. jcsd
  3. Jan 22, 2010 #2


    Staff: Mentor

    I would use an intermediate array variable with 100 elements, and would store the values 1 + dxn(1), 1 + sum(dxn(1:2)), 1 + sum(dxn(1:3), etc. in it, up to 1 + sum(dxn(1:100). If you know about DO loops, you can do this very easily.

    After you have calculated all 100 values, store their reciprocals in y1, y2, ... , y100.
  4. Jan 22, 2010 #3

    for loop and empty 100 element long array?
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook