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 help with e^x

  1. Sep 20, 2010 #1
    1. The problem statement, all variables and given/known data

    Plot e^x for -10 to 10 using a Taylor series about 0
    find the error between the nth term and the actual value of e^-10 and e^10

    plot sin(4*theta) using a 2 term expansion, a 4 term expansion and a 10 term expansion and constrast it with the plot of sin(4*theta)

    3. The attempt at a solution

    This is the first time I have ever opened MatLab and tried to do any sort of math programming. I suppose I need help in the logic of it or trying to trace what I am doing.

    So far I have:

    Code (Text):

    %This will compute the Taylor Series expansion of e^x for a user defined
    %x value for the number of terms required by the user.  It will do this about the point
    %a=0.  The result of the
    %nth term will be compared to the computer generated value of e^x

    x = input ('Enter a value for x:'); % user input of which value to use for x
    i = input ('Enter the non-zero number of terms for this Taylor Series expansion:'); %user input of number of terms to use

    % g_n: the nth term in Taylor Series

    k=1;    % initialize k

    g_n=x^(k-1)/factorial(k-1);   % begin with the first term


    while  i>k; % let index increase until number of desired terms reached
        k=k+1;  % increase index by 1
        g=g+g_n; %add the next term in the series  

    I changed my code to what is listed above and it seemed to help entirely.
    Last edited: Sep 20, 2010
  2. jcsd
  3. Sep 20, 2010 #2
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Threads - MatLab help Date
Need help with matlab matrices Nov 27, 2015
Building a truss with matlab -- Need help Nov 22, 2015
Matlab help please... Nov 14, 2015
Matlab error, can you help? Jan 30, 2015
MATLAB help Nov 11, 2014