Results 1 to 2 of 2

Math Help - loops in matlab, plotting matrix elements

  1. #1
    Member
    Joined
    Jul 2008
    From
    Sofia, Bulgaria
    Posts
    75

    loops in matlab, plotting matrix elements

    Hi all!

    I want to perform the following summation numerically:

    r(x,t)=\sum_{p=-N}^N\cos(pt)\cos(px)e^{-p^2}

    where t and x are parameters with respect to which I will subsequently plot the results

    x is between -C and C, and t is between -K and K for some positive constants C, K

    I would like to get a matrix r, whose columns are the summation values for fixed t and whose rows the summation values for fixed x.

    Here's my attempt for K = C = 10 and N = 5, but it fails - I only get a single number r.

    for t = -10:0.1:10;
    for x = -10:0.1:10;
    for p = -5:1:5;
    A = 2.*cos(p*t).*cos(p*x).*exp(-p.^2);
    r = sum(A);
    end;
    end;
    end;
    The plots I want are for r(t), r(x) the other variable being fixed, respectively, and a polar plot for r(x,t). Does anyone know how to read off and plot a column/row from a matrix?

    Thanks a lot!
    marin
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Member
    Joined
    Jul 2008
    From
    Sofia, Bulgaria
    Posts
    75
    here's an improvement to the above code:

    %set initial values for the parameter j%
    i=1;
    j=1;
    for t = 0:.1:10; %set time interval t%
    j = 1;

    for x = -10:.1:10; %set line interval x%

    p = 0:1:100; %define a summation prameter p%
    A = 2.*cos(p*t).*cos(p*x).*exp(-p.^2); %define the sumamtions vector A%
    s(i,j) = sum(A); %perform summation for fixed x and t and define the (i,j)-component of matrix s%

    j=j+1; %increase j by 1%

    end;
    i=i+1; %increase i by 1%
    end;
    pcolor(s)
    I'm still unsure about it though... Can anyone tell me if it's ok?
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Need help with Matlab (Loops)
    Posted in the Math Software Forum
    Replies: 1
    Last Post: February 8th 2011, 01:50 AM
  2. matlab plotting graph need help
    Posted in the Math Software Forum
    Replies: 1
    Last Post: August 7th 2010, 12:27 AM
  3. matlab for loops?
    Posted in the Math Software Forum
    Replies: 5
    Last Post: February 28th 2010, 10:49 PM
  4. [SOLVED] Matlab plotting help:peicewise with loops
    Posted in the Math Software Forum
    Replies: 4
    Last Post: October 20th 2009, 10:19 PM
  5. MATLAB: Plotting MATRIX?
    Posted in the Math Software Forum
    Replies: 3
    Last Post: January 25th 2009, 01:21 PM

Search Tags


/mathhelpforum @mathhelpforum