MatLab e^x Homework: Plot and Error Calc

  • Thread starter sandbanana
  • Start date
  • Tags
    E^x Matlab
In summary, we use a Taylor series expansion to plot e^x for -10 to 10 about the point a=0. We also calculate the error between the nth term and the actual value of e^-10 and e^10. Additionally, we use a 2 term, 4 term, and 10 term expansion to plot sin(4*theta) and compare it to the plot of sin(4*theta). The code uses user input for the value of x and the number of terms to use in the expansion. The while loop continues to add terms until the desired number of terms is reached.
  • #1
sandbanana
8
0

Homework Statement



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)

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:
%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^xx = 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

g=g_n;

while  i>k; % let index increase until number of desired terms reached
 
    k=k+1;  % increase index by 1
    g_n=x^(k-1)/factorial(k-1);
    g=g+g_n; %add the next term in the series   
end
    
disp(g)

I changed my code to what is listed above and it seemed to help entirely.
 
Last edited:
Physics news on Phys.org
  • #2
http://www.mathworks.com/help/toolbox/symbolic/taylor.html
 

1. What is MatLab e^x Homework?

MatLab e^x Homework is a common assignment in many math and science courses that requires students to use the MatLab software to plot and calculate the error of the exponential function e^x.

2. How do I plot e^x in MatLab?

To plot e^x in MatLab, you first need to define a range of x values using the "linspace" function. Then, use the "plot" function to graph the exponential function using the defined x values. Finally, use the "xlabel" and "ylabel" functions to label the x and y axes.

3. What is the error calculation in MatLab e^x Homework?

The error calculation in MatLab e^x Homework involves comparing the values of the actual exponential function e^x to the values calculated using a numerical approximation method such as the Taylor series or Euler's method. The difference between these values is used to calculate the error.

4. Can I use any numerical approximation method for the error calculation?

Yes, you can use any numerical approximation method that you are familiar with for the error calculation in MatLab e^x Homework. However, it is recommended to use methods that provide a more accurate approximation, such as the Taylor series or Euler's method.

5. How can I check my work for MatLab e^x Homework?

You can check your work for MatLab e^x Homework by comparing your plotted graph and error calculation to the expected results. You can also ask your instructor or a classmate to review your work and provide feedback.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
6
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
941
  • Engineering and Comp Sci Homework Help
Replies
1
Views
953
  • Engineering and Comp Sci Homework Help
Replies
12
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
32
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
876
  • Engineering and Comp Sci Homework Help
Replies
3
Views
805
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
Back
Top