Results 1 to 5 of 5

Math Help - Legendre Polynomial question - matlab

  1. #1
    Junior Member
    Joined
    Aug 2008
    Posts
    26
    Awards
    1

    Legendre Polynomial question - matlab

    Hi am trying to prove using the recursive formula that the legendre polynomial P3(x)=(1/2)*(5x^3 - 3x) .......(1)

    This is the recursive formula

    Pk+1=(1/k+1)*((2*k+1)*x*P2-k*P1)
    where P2=(1/2)(3x^2 - 1) and P1=x

    we have chosen k=2 so it gives Pk+1 = P3.

    Everytime I try to evaluate this by hand, I dont get equation (1), which is what I need, can someone help me on this.

    I even tried matlab which gave an ans = 45/4*x^3-27/4*x, which is still not (1).

    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by shadow85 View Post
    Hi am trying to prove using the recursive formula that the legendre polynomial P3(x)=(1/2)*(5x^3 - 3x) .......(1)

    This is the recursive formula

    Pk+1=(1/k+1)*((2*k+1)*x*P2-k*P1)
    where P2=(1/2)(3x^2 - 1) and P1=x

    we have chosen k=2 so it gives Pk+1 = P3.

    Everytime I try to evaluate this by hand, I dont get equation (1), which is what I need, can someone help me on this.

    I even tried matlab which gave an ans = 45/4*x^3-27/4*x, which is still not (1).

    The recurrence is:

    (n+1)P_{n+1}(x)=(2n+1)x P_n(x) - nP_{n-1}(x)

    Put n=2:

    3P_3(x)=5xP_2(x)-2P_1(x)

    So:

    6P_3(x)=5x(3x^2-1)-4x=15x^3-5x-4x=15x^3-9x

    hence:

    P_3(x)=\frac{5x^3-3x}{2}

    RonL
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Junior Member
    Joined
    Aug 2008
    Posts
    26
    Awards
    1
    Hi, I am having trouble getting this legendre function to work in Matlab now. I am suppose to create a for-loop containing the recursion equation to create a vector called P, containing simplified symbolic formulae for the legendre polynomials from degree 1 up to degree 10. firstly I included the first two degree

    here is my matlab code of I tried to do:

    syms x k
    x=linspace(-1,1,5);
    P(1)=x;
    P(2)=0.5*(3*x^2-1);
    for k=1:9
    P(k+1)=(1/k+1)*((2*k+1)*x*P(k)-k*P(k-1));
    end

    I keep getting this error from Matlab:
    ??? In an assignment A(I) = B, the number of elements in B and
    I must be the same.

    Error in ==> legendrepoly at 4
    P(1)=x;
    Follow Math Help Forum on Facebook and Google+

  4. #4
    MHF Contributor
    Opalg's Avatar
    Joined
    Aug 2007
    From
    Leeds, UK
    Posts
    4,041
    Thanks
    7
    Quote Originally Posted by shadow85 View Post
    Hi, I am having trouble getting this legendre function to work in Matlab now. I am suppose to create a for-loop containing the recursion equation to create a vector called P, containing simplified symbolic formulae for the legendre polynomials from degree 1 up to degree 10. firstly I included the first two degree

    here is my matlab code of I tried to do:

    syms x k
    x=linspace(-1,1,5);
    P(1)=x;
    P(2)=0.5*(3*x^2-1);
    for k=1:9
    P(k+1)=(1/k+1)*((2*k+1)*x*P(k)-k*P(k-1));
    end

    I keep getting this error from Matlab:
    ??? In an assignment A(I) = B, the number of elements in B and
    I must be the same.

    Error in ==> legendrepoly at 4
    P(1)=x;
    I don't know anything about Matlab, but it looks to me as though the loop should go from k=2 to 9, not 1 to 9. If you put k=1 then the program will look for P(k-1) and not find it.
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by shadow85 View Post
    Hi, I am having trouble getting this legendre function to work in Matlab now. I am suppose to create a for-loop containing the recursion equation to create a vector called P, containing simplified symbolic formulae for the legendre polynomials from degree 1 up to degree 10. firstly I included the first two degree

    here is my matlab code of I tried to do:

    syms x k
    x=linspace(-1,1,5);
    P(1)=x;
    P(2)=0.5*(3*x^2-1);
    for k=1:9
    P(k+1)=(1/k+1)*((2*k+1)*x*P(k)-k*P(k-1));
    end

    I keep getting this error from Matlab:
    ??? In an assignment A(I) = B, the number of elements in B and
    I must be the same.

    Error in ==> legendrepoly at 4
    P(1)=x;
    Well I don't have the symbolic tool boxed, so I don't know much about symbolic operations in Matlab.

    But: you want x to be a symbolic variable, but you have assigned it to a numeric array (which may be arbitrary precision or floating point; I don't know) which I'm pretty sure is nonsense.

    (and note opalg's comment about loop indices)

    RonL
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. legendre's polynomial...
    Posted in the Differential Equations Forum
    Replies: 1
    Last Post: April 11th 2011, 11:05 PM
  2. Shifted Legendre Polynomial
    Posted in the Advanced Math Topics Forum
    Replies: 3
    Last Post: October 24th 2010, 07:32 AM
  3. [SOLVED] Legendre Polynomial
    Posted in the Differential Equations Forum
    Replies: 0
    Last Post: September 26th 2010, 08:27 AM
  4. Legendre polynomial in MatLab
    Posted in the Math Software Forum
    Replies: 6
    Last Post: April 5th 2009, 07:09 PM
  5. Legendre polynomial property
    Posted in the Advanced Applied Math Forum
    Replies: 0
    Last Post: May 5th 2007, 07:53 AM

Search Tags


/mathhelpforum @mathhelpforum