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!

Matlab Programming(Need help with the last couple of details)

  1. Nov 21, 2012 #1
    1. The problem statement, all variables and given/known data

    Okay, so I need some help with this Matlab program. I never learned Matlab, so I'm trying to do it as best as I can. The question is: Calculate the 2nd and 3rd degree Taylor polynomials for the function f(x)=ln(1+x) about the point a=0 Plot these polynomials and the function on the interval -1<x<3

    2. Relevant equations

    N/A

    3. The attempt at a solution
    This is what I have so far. I thought it was right, but Matlab said "Not enough input arguments." What does that mean, and I how do I fix it?
    >> figure(1);clf;
    x=[-1:.01:3];
    y=log*(1+x);
    P2= x-(x^2/2)!;
    P3= x-(x^2/2)+(x^3/3)!;
    figure(1);clf;
    plot(x,y,x,P2,'--',x,P3,'-.')
    legend('log*(1+x)','P_2','P_3')
    xlabel('x')
    title('The function and the 2^{nd} and ^{rd} order Taylor Polynomials')
    figure(2);clf
    plot(x,abs(y-P2),x,abs(y-P3),'--')
    legend('log*(1+x)-P_2|','log*(1+x)-P_3|')
    xlabel('x')
    title('Errors in the two Taylor Polynomials')

    Thanks in advance!:)
     
  2. jcsd
  3. Nov 22, 2012 #2

    lewando

    User Avatar
    Gold Member

    Problem is with this line: "y=log*(1+x)". Can you spot it?
     
  4. Nov 22, 2012 #3
    Honestly, no. There was an issue with that line before because I had put ln instead of log so I changed it. Is there supposed to be a . Before/after the x? I noticed that there's a lot of times where that's necessary.
     
  5. Nov 22, 2012 #4

    lewando

    User Avatar
    Gold Member

    log (natural log) is a function so it should be: "y=log(1+x)"
     
  6. Nov 22, 2012 #5
    It's that simple? Wow I was looking for at least an hour, and I couldn't find the issue. Thank you so much!
     
  7. Nov 22, 2012 #6

    lewando

    User Avatar
    Gold Member

    I think you are also going to have a problem with the factorial operator. Missed that one--try the factorial() function. [edit-- you have some significant semantic issues with the factorial operation--does not make much sense]
     
    Last edited: Nov 22, 2012
  8. Nov 22, 2012 #7
    What do you mean?
     
  9. Nov 22, 2012 #8

    lewando

    User Avatar
    Gold Member

    Well for example, the line:
    P2= x-(x^2/2)!;

    You are trying to take the factorial of an array of non-integers (not defined) using "!" (not a MATLAB operator). You might need to step back and detail what you are trying to do.
     
  10. Nov 22, 2012 #9
    Oh so I would have to write out the factorial instead of simply putting !.
     
  11. Nov 22, 2012 #10

    lewando

    User Avatar
    Gold Member

    I don't understand what the factorial symbol is doing in the expressions for P2 and P3. I don't think they belong there at all.
     
  12. Nov 22, 2012 #11
    But doesn't the equation call for a factorial? How else would it be done?
     
  13. Nov 22, 2012 #12

    lewando

    User Avatar
    Gold Member

    Not sure what equation you are using. From page 4 of this link is the general form http://www.math.ufl.edu/~vatter/teaching/m8w10/m8l01.pdf [Broken]

    f = ln(1+x)
    f' = 1/(1+x)
    f'' = -1/(1+x)2
    f''' = 2/(1+x)3

    [edit-- also familiarize yourself with the distinction between the ".^" and the "^" operators]
     
    Last edited by a moderator: May 6, 2017
  14. Nov 22, 2012 #13
    I have to use the Taylor series so it's not just the derivative. And okay, will do.
     
    Last edited by a moderator: May 6, 2017
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Matlab Programming(Need help with the last couple of details)
  1. HELP MATLAB program (Replies: 2)

  2. Matlab help needed (Replies: 3)

  3. Matlab Need Help (Replies: 1)

Loading...