1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    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!

Homework Help: Problem in matlab

  1. Aug 26, 2014 #1


    User Avatar

    1. The problem statement, all variables and given/known data
    hi, i am having some problem with a code in matlab. my code is:

    t = 30;
    H= 30;
    h= 3;
    n = H/h;
    qqq= 10;
    a= 3;
    b = .2;
    k= 0.04;
    Lo= 100;
    g= 9.81;

    for i = 1:t
    q(i) = 0;

    for j = 1:n
    nl = qqq + (j*h)/(a + b*(j*h));
    nlt = nl*(0.0172*log(i) + 1);
    q(i) = q(i) + 2*k*(Lo/100)*(nlt/3)*g*exp(-k*(i));


    plot((1:t), q);


    2. Relevant equations
    this is the code and i keep getting this error- "Attempted to access q(2); index out of bounds because numel(q)=1."

    help would be greatly appreciated.

    3. The attempt at a solution
  2. jcsd
  3. Aug 26, 2014 #2


    Staff: Mentor

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted