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: Need some matlab help adding sequences

  1. Sep 30, 2011 #1
    1. The problem statement, all variables and given/known data
    The problem provides a sequence. Let x(n) ={1,-2,4,6,-5,8,10} where x(-4)=1, x(-3)=-2,etc.
    Generate x1(n) = 3x(n+2)+x(n+4)-2x(n)

    3. The attempt at a solution

    PHP:
    x = [0, 0, 1, -2, 4, 6, -5, 8, 10, 0, 0, 0, 0];
    n = -6:6;

    x1 = x * 3;
    n1 = n-2;

    x2 = x * 2;
    n2 = n;

    x3 = x;
    n3 = n+4;
    subplot(4,1,1), stem(n1,x1)
    grid on
    subplot(4,1,2), stem(n2,x2)
    grid on
    subplot(4,1,3), stem(n3,x3)
    grid on
     
    The above is the code I have so far to try to get each of the terms separately. but the difficult part is how to add these sequences together, since they start at different indices. I've tried some for loops but i can't figure out a way to get it to sweep the indices and compare them correctly. any help?? thanks
     
    Last edited: Sep 30, 2011
  2. jcsd
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted